1
0
mirror of https://github.com/ciromattia/kcc synced 2026-07-23 05:03:13 +00:00

Mainly adhere to PEP 8 code style (http://www.python.org/dev/peps/pep-0008/)

Add some commented code for working on Panel view enhancement and natural sorting.
This commit is contained in:
Ciro Mattia Gonano
2013-03-01 16:22:11 +01:00
parent 1edbe389ba
commit 32a0038c49
3 changed files with 142 additions and 132 deletions
+15 -14
View File
@@ -14,22 +14,23 @@
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#
__license__ = 'ISC'
__license__ = 'ISC'
__copyright__ = '2012-2013, Ciro Mattia Gonano <ciromattia@gmail.com>'
__docformat__ = 'restructuredtext en'
import os
class CBxArchive:
def __init__(self, origFileName):
self.cbxexts = ['.zip','.cbz','.rar','.cbr']
self.cbxexts = ['.zip', '.cbz', '.rar', '.cbr']
self.origFileName = origFileName
self.filename = os.path.splitext(origFileName)
def isCbxFile(self):
return self.filename[1].lower() in self.cbxexts
def extractCBZ(self,targetdir):
def extractCBZ(self, targetdir):
try:
from zipfile import ZipFile
except ImportError:
@@ -40,13 +41,13 @@ class CBxArchive:
pass # skip MacOS special files
elif f.endswith('/'):
try:
os.makedirs(os.path.join(targetdir,f))
os.makedirs(os.path.join(targetdir, f))
except:
pass #the dir exists so we are going to extract the images only.
pass # the dir exists so we are going to extract the images only.
else:
cbzFile.extract(f, targetdir)
def extractCBR(self,targetdir):
def extractCBR(self, targetdir):
try:
import rarfile
except ImportError:
@@ -55,24 +56,24 @@ class CBxArchive:
cbrFile = rarfile.RarFile(self.origFileName)
for f in cbrFile.namelist():
if f.startswith('__MACOSX') or f.endswith('.DS_Store'):
pass # skip MacOS special files
pass # skip MacOS special files
elif f.endswith('/'):
try:
os.makedirs(os.path.join(targetdir,f))
except:
pass #the dir exists so we are going to extract the images only.
pass # the dir exists so we are going to extract the images only.
else:
cbrFile.extract(f, targetdir)
def extract(self,targetdir):
def extract(self, targetdir):
if '.cbr' == self.filename[1].lower() or '.rar' == self.filename[1].lower():
self.extractCBR(targetdir)
elif '.cbz' == self.filename[1].lower() or '.zip' == self.filename[1].lower():
self.extractCBZ(targetdir)
dir = os.listdir(targetdir)
if len(dir) == 1 and os.path.isdir(os.path.join(targetdir,dir[0])):
adir = os.listdir(targetdir)
if len(adir) == 1 and os.path.isdir(os.path.join(targetdir, adir[0])):
import shutil
for f in os.listdir(os.path.join(targetdir,dir[0])):
shutil.move(os.path.join(targetdir,dir[0],f),targetdir)
os.rmdir(os.path.join(targetdir,dir[0]))
for f in os.listdir(os.path.join(targetdir, adir[0])):
shutil.move(os.path.join(targetdir, adir[0], f), targetdir)
os.rmdir(os.path.join(targetdir, adir[0]))
return targetdir