diff options
| author | Paweł Jastrzębski <[email protected]> | 2017-03-17 11:11:00 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-03-17 11:11:00 +0100 |
| commit | c01ff83fce6e91a7ee417c113377996400770572 (patch) | |
| tree | c76b5d0398d5085a7a57e63a688856f28c3cab1b /kindlecomicconverter/cbxarchive.py | |
| parent | Merge pull request #224 from ciromattia/dev (diff) | |
| parent | Update README.md (diff) | |
| download | kcc-c01ff83fce6e91a7ee417c113377996400770572.tar.gz kcc-c01ff83fce6e91a7ee417c113377996400770572.tar.bz2 kcc-c01ff83fce6e91a7ee417c113377996400770572.zip | |
Merge pull request #231 from ciromattia/dev
5.3.1
Diffstat (limited to 'kindlecomicconverter/cbxarchive.py')
| -rw-r--r-- | kindlecomicconverter/cbxarchive.py | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/kindlecomicconverter/cbxarchive.py b/kindlecomicconverter/cbxarchive.py index 726432b..7bd833f 100644 --- a/kindlecomicconverter/cbxarchive.py +++ b/kindlecomicconverter/cbxarchive.py @@ -22,12 +22,8 @@ from zipfile import is_zipfile, ZipFile from subprocess import STDOUT, PIPE from psutil import Popen from shutil import move, copy -try: - from scandir import walk -except ImportError: - walk = os.walk from . import rarfile -from .shared import check7ZFile as is_7zfile, saferReplace, saferRemove +from .shared import check7ZFile as is_7zfile class CBxArchive: @@ -50,12 +46,12 @@ class CBxArchive: filelist = [] for f in cbzFile.namelist(): if f.startswith('__MACOSX') or f.endswith('.DS_Store') or f.endswith('humbs.db'): - pass # skip MacOS special files + pass elif f.endswith('/'): try: os.makedirs(os.path.join(targetdir, f)) except Exception: - pass # the dir exists so we are going to extract the images only. + pass else: filelist.append(f) cbzFile.extractall(targetdir, filelist) @@ -63,24 +59,18 @@ class CBxArchive: def extractCBR(self, targetdir): cbrFile = rarfile.RarFile(self.origFileName) cbrFile.extractall(targetdir) - for root, dirnames, filenames in walk(targetdir): + for root, _, filenames in os.walk(targetdir): for filename in filenames: if filename.startswith('__MACOSX') or filename.endswith('.DS_Store') or filename.endswith('humbs.db'): - saferRemove(os.path.join(root, filename)) + os.remove(os.path.join(root, filename)) def extractCB7(self, targetdir): - # Workaround for some wide UTF-8 + Popen abnormalities - if sys.platform.startswith('darwin'): - copy(self.origFileName, os.path.join(os.path.dirname(self.origFileName), 'TMP_KCC_TMP')) - self.origFileName = os.path.join(os.path.dirname(self.origFileName), 'TMP_KCC_TMP') output = Popen('7za x "' + self.origFileName + '" -xr!__MACOSX -xr!.DS_Store -xr!thumbs.db -xr!Thumbs.db -o"' + targetdir + '"', stdout=PIPE, stderr=STDOUT, stdin=PIPE, shell=True) extracted = False for line in output.stdout: if b"Everything is Ok" in line: extracted = True - if sys.platform.startswith('darwin'): - saferRemove(self.origFileName) if not extracted: raise OSError @@ -96,10 +86,6 @@ class CBxArchive: adir.remove('ComicInfo.xml') if len(adir) == 1 and os.path.isdir(os.path.join(targetdir, adir[0])): for f in os.listdir(os.path.join(targetdir, adir[0])): - # If directory names contain UTF-8 chars shutil.move can't clean up the mess alone - if os.path.isdir(os.path.join(targetdir, f)): - saferReplace(os.path.join(targetdir, adir[0], f), os.path.join(targetdir, adir[0], f + '-A')) - f += '-A' move(os.path.join(targetdir, adir[0], f), targetdir) os.rmdir(os.path.join(targetdir, adir[0])) return targetdir |