about summary refs log tree commit diff
path: root/kindlecomicconverter/comic2ebook.py
diff options
context:
space:
mode:
authorPaweł Jastrzębski <pawelj@iosphe.re>2017-03-12 17:42:08 +0100
committerPaweł Jastrzębski <pawelj@iosphe.re>2017-03-15 18:30:32 +0100
commit2e9b3389e4ff746d339c74cead92cc072b9dd6a9 (patch)
tree5910e7b94f2b8bfb38fd2a4586df0e70ef9866a2 /kindlecomicconverter/comic2ebook.py
parentUpdated build environment (diff)
downloadkcc-2e9b3389e4ff746d339c74cead92cc072b9dd6a9.tar.gz
kcc-2e9b3389e4ff746d339c74cead92cc072b9dd6a9.tar.bz2
kcc-2e9b3389e4ff746d339c74cead92cc072b9dd6a9.zip
Code cleanup
Diffstat (limited to 'kindlecomicconverter/comic2ebook.py')
-rwxr-xr-xkindlecomicconverter/comic2ebook.py48
1 files changed, 24 insertions, 24 deletions
diff --git a/kindlecomicconverter/comic2ebook.py b/kindlecomicconverter/comic2ebook.py
index 4ab9248..a1ad174 100755
--- a/kindlecomicconverter/comic2ebook.py
+++ b/kindlecomicconverter/comic2ebook.py
@@ -42,7 +42,7 @@ try:
     from PyQt5 import QtCore
 except ImportError:
     QtCore = None
-from .shared import md5Checksum, getImageFileName, walkSort, walkLevel, saferReplace, saferRemove, sanitizeTrace
+from .shared import md5Checksum, getImageFileName, walkSort, walkLevel, sanitizeTrace
 from . import comic2panel
 from . import image
 from . import cbxarchive
@@ -81,11 +81,11 @@ def buildHTML(path, imgfile, imgfilepath):
     imgfilepath = md5Checksum(imgfilepath)
     filename = getImageFileName(imgfile)
     deviceres = options.profileData[1]
-    if "Rotated" in options.imgIndex[imgfilepath]:
+    if "Rotated" in options.imgMetadata[imgfilepath]:
         rotatedPage = True
     else:
         rotatedPage = False
-    if "BlackFill" in options.imgIndex[imgfilepath]:
+    if "BlackBackground" in options.imgMetadata[imgfilepath]:
         additionalStyle = 'background-color:#000000;'
     else:
         additionalStyle = 'background-color:#FFFFFF;'
@@ -420,7 +420,7 @@ def buildEPUB(path, chapterNames, tomeNumber):
                   "display: none;\n",
                   "}\n"])
     f.close()
-    for (dirpath, dirnames, filenames) in os.walk(os.path.join(path, 'OEBPS', 'Images')):
+    for dirpath, dirnames, filenames in os.walk(os.path.join(path, 'OEBPS', 'Images')):
         chapter = False
         dirnames, filenames = walkSort(dirnames, filenames)
         for afile in filenames:
@@ -457,11 +457,11 @@ def imgDirectoryProcessing(path):
     global workerPool, workerOutput
     workerPool = Pool()
     workerOutput = []
-    options.imgIndex = {}
-    options.imgPurgeIndex = []
+    options.imgMetadata = {}
+    options.imgOld = []
     work = []
     pagenumber = 0
-    for (dirpath, dirnames, filenames) in os.walk(path):
+    for dirpath, _, filenames in os.walk(path):
         for afile in filenames:
             pagenumber += 1
             work.append([afile, dirpath, options])
@@ -478,9 +478,9 @@ def imgDirectoryProcessing(path):
         if len(workerOutput) > 0:
             rmtree(os.path.join(path, '..', '..'), True)
             raise RuntimeError("One of workers crashed. Cause: " + workerOutput[0][0], workerOutput[0][1])
-        for file in options.imgPurgeIndex:
+        for file in options.imgOld:
             if os.path.isfile(file):
-                saferRemove(file)
+                os.remove(file)
     else:
         rmtree(os.path.join(path, '..', '..'), True)
         raise UserWarning("Source directory is empty.")
@@ -493,8 +493,8 @@ def imgFileProcessingTick(output):
     else:
         for page in output:
             if page is not None:
-                options.imgIndex[page[0]] = page[1]
-                options.imgPurgeIndex.append(page[2])
+                options.imgMetadata[page[0]] = page[1]
+                options.imgOld.append(page[2])
     if GUI:
         GUI.progressBarTick.emit('tick')
         if not GUI.conversionAlive:
@@ -509,7 +509,7 @@ def imgFileProcessing(work):
         output = []
         workImg = image.ComicPageParser((dirpath, afile), opt)
         for i in workImg.payload:
-            img = image.ComicPage(i[0], i[1], i[2], i[3], i[4], opt)
+            img = image.ComicPage(opt, *i)
             if opt.cropping == 2 and not opt.webtoon:
                 img.cropPageNumber(opt.croppingp)
             if opt.cropping > 0 and not opt.webtoon:
@@ -615,7 +615,7 @@ def getComicInfo(path, originalPath):
         try:
             xml = metadata.MetadataParser(xmlPath)
         except Exception:
-            saferRemove(xmlPath)
+            os.remove(xmlPath)
             return
         options.authors = []
         if defaultTitle:
@@ -640,7 +640,7 @@ def getComicInfo(path, originalPath):
             options.chapters = xml.data['Bookmarks']
         if xml.data['Summary']:
             options.summary = escape(xml.data['Summary'])
-        saferRemove(xmlPath)
+        os.remove(xmlPath)
 
 
 def getCoversFromMCB(mangaID):
@@ -659,7 +659,7 @@ def getCoversFromMCB(mangaID):
 
 def getDirectorySize(start_path='.'):
     total_size = 0
-    for dirpath, dirnames, filenames in os.walk(start_path):
+    for dirpath, _, filenames in os.walk(start_path):
         for f in filenames:
             fp = os.path.join(dirpath, f)
             total_size += os.path.getsize(fp)
@@ -694,7 +694,7 @@ def sanitizeTree(filetree):
             newKey = os.path.join(root, slugified + splitname[1])
             key = os.path.join(root, name)
             if key != newKey:
-                saferReplace(key, newKey)
+                os.replace(key, newKey)
         for name in dirs:
             tmpName = name
             slugified = slugify(name)
@@ -704,7 +704,7 @@ def sanitizeTree(filetree):
             newKey = os.path.join(root, slugified)
             key = os.path.join(root, name)
             if key != newKey:
-                saferReplace(key, newKey)
+                os.replace(key, newKey)
     return chapterNames
 
 
@@ -722,7 +722,7 @@ def sanitizeTreeKobo(filetree):
             newKey = os.path.join(root, slugified + splitname[1])
             key = os.path.join(root, name)
             if key != newKey:
-                saferReplace(key, newKey)
+                os.replace(key, newKey)
 
 
 def sanitizePermissions(filetree):
@@ -781,7 +781,7 @@ def splitProcess(path, mode):
                     move(os.path.join(root, name), os.path.join(currentTarget, name))
     else:
         firstTome = True
-        for root, dirs, files in walkLevel(path, 0):
+        for root, dirs, _ in walkLevel(path, 0):
             for name in dirs:
                 if not firstTome:
                     currentTarget, pathRoot = createNewTome()
@@ -795,7 +795,7 @@ def splitProcess(path, mode):
 def detectCorruption(tmpPath, orgPath):
     imageNumber = 0
     imageSmaller = 0
-    for root, dirs, files in os.walk(tmpPath, False):
+    for root, _, files in os.walk(tmpPath, False):
         for name in files:
             if getImageFileName(name) is not None:
                 path = os.path.join(root, name)
@@ -818,7 +818,7 @@ def detectCorruption(tmpPath, orgPath):
                     else:
                         raise RuntimeError('Image file %s is corrupted.' % pathOrg)
             else:
-                saferRemove(os.path.join(root, name))
+                os.remove(os.path.join(root, name))
     if imageSmaller > imageNumber * 0.25 and not options.upscale and not options.stretch:
         print("WARNING: More than 25% of images are smaller than target device resolution. "
               "Consider enabling stretching or upscaling to improve readability.")
@@ -846,7 +846,7 @@ def makeZIP(zipFilename, baseDir, isEPUB=False):
     zipOutput = ZipFile(zipFilename, 'w', ZIP_DEFLATED)
     if isEPUB:
         zipOutput.writestr('mimetype', 'application/epub+zip', ZIP_STORED)
-    for dirpath, dirnames, filenames in os.walk(baseDir):
+    for dirpath, _, filenames in os.walk(baseDir):
         for name in filenames:
             path = os.path.normpath(os.path.join(dirpath, name))
             aPath = os.path.normpath(os.path.join(dirpath.replace(baseDir, ''), name))
@@ -1103,14 +1103,14 @@ def makeBook(source, qtGUI=None):
                 print('Error: Failed to tweak KindleGen output!')
                 return filepath
             else:
-                saferRemove(i.replace('.epub', '.mobi') + '_toclean')
+                os.remove(i.replace('.epub', '.mobi') + '_toclean')
             if k.path and k.coverSupport:
                 options.covers[filepath.index(i)][0].saveToKindle(k, options.covers[filepath.index(i)][1])
     return filepath
 
 
 def makeMOBIFix(item, uuid):
-    saferRemove(item)
+    os.remove(item)
     mobiPath = item.replace('.epub', '.mobi')
     move(mobiPath, mobiPath + '_toclean')
     try: