about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rwxr-xr-xkcc/comic2ebook.py17
-rw-r--r--kcc/comic2panel.py5
-rw-r--r--kcc/shared.py9
4 files changed, 22 insertions, 12 deletions
diff --git a/README.md b/README.md
index 84dfcda..fc9eb1e 100644
--- a/README.md
+++ b/README.md
@@ -48,11 +48,12 @@ You can find the latest released binary at the following links:
 - [Pillow](http://pypi.python.org/pypi/Pillow/) 2.7.0+
 - [psutil](https://pypi.python.org/pypi/psutil) 2.0+
 - [python-slugify](http://pypi.python.org/pypi/python-slugify) 0.1.0+
+- [scandir](https://pypi.python.org/pypi/scandir) 0.9+
 
 On Debian based distributions these two commands should install all dependencies:
 ```
 sudo apt-get install python3 python3-dev python3-pip python3-pyqt5 libpng-dev libjpeg-dev p7zip-full unrar
-sudo pip3 install pillow python-slugify psutil
+sudo pip3 install pillow python-slugify psutil scandir
 ```
 
 ### For freezing code:
diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py
index 8d76a31..9c31aa3 100755
--- a/kcc/comic2ebook.py
+++ b/kcc/comic2ebook.py
@@ -37,6 +37,7 @@ from slugify import slugify as slugifyExt
 from PIL import Image
 from subprocess import STDOUT, PIPE
 from psutil import Popen, virtual_memory
+from scandir import walk
 try:
     from PyQt5 import QtCore
 except ImportError:
@@ -412,7 +413,7 @@ def buildEPUB(path, chapterNames, tomeNumber):
                   "}",
                   ])
     f.close()
-    for (dirpath, dirnames, filenames) in os.walk(os.path.join(path, 'OEBPS', 'Images')):
+    for (dirpath, dirnames, filenames) in walk(os.path.join(path, 'OEBPS', 'Images')):
         chapter = False
         for afile in filenames:
             filename = getImageFileName(afile)
@@ -463,7 +464,7 @@ def imgDirectoryProcessing(path):
     options.imgPurgeIndex = []
     work = []
     pagenumber = 0
-    for (dirpath, dirnames, filenames) in os.walk(path):
+    for (dirpath, dirnames, filenames) in walk(path):
         for afile in filenames:
             pagenumber += 1
             work.append([afile, dirpath, options])
@@ -698,7 +699,7 @@ def getCoversFromMCB(mangaID):
 
 def getDirectorySize(start_path='.'):
     total_size = 0
-    for dirpath, dirnames, filenames in os.walk(start_path):
+    for dirpath, dirnames, filenames in walk(start_path):
         for f in filenames:
             fp = os.path.join(dirpath, f)
             total_size += os.path.getsize(fp)
@@ -707,7 +708,7 @@ def getDirectorySize(start_path='.'):
 
 def sanitizeTree(filetree):
     chapterNames = {}
-    for root, dirs, files in os.walk(filetree, False):
+    for root, dirs, files in walk(filetree, False):
         for name in files:
             splitname = os.path.splitext(name)
             slugified = slugify(splitname[0])
@@ -733,7 +734,7 @@ def sanitizeTree(filetree):
 
 def sanitizeTreeKobo(filetree):
     pageNumber = 0
-    for root, dirs, files in os.walk(filetree):
+    for root, dirs, files in walk(filetree):
         files.sort()
         dirs.sort()
         for name in files:
@@ -750,7 +751,7 @@ def sanitizeTreeKobo(filetree):
 
 
 def sanitizePermissions(filetree):
-    for root, dirs, files in os.walk(filetree, False):
+    for root, dirs, files in walk(filetree, False):
         for name in files:
             os.chmod(os.path.join(root, name), S_IWRITE | S_IREAD)
         for name in dirs:
@@ -882,7 +883,7 @@ def splitProcess(path, mode):
 
 
 def detectCorruption(tmpPath, orgPath):
-    for root, dirs, files in os.walk(tmpPath, False):
+    for root, dirs, files in walk(tmpPath, False):
         for name in files:
             if getImageFileName(name) is not None:
                 path = os.path.join(root, name)
@@ -949,7 +950,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, dirnames, filenames in 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))
diff --git a/kcc/comic2panel.py b/kcc/comic2panel.py
index 1a766ac..81296aa 100644
--- a/kcc/comic2panel.py
+++ b/kcc/comic2panel.py
@@ -24,6 +24,7 @@ from shutil import rmtree, copytree, move
 from optparse import OptionParser, OptionGroup
 from multiprocessing import Pool
 from PIL import Image, ImageStat, ImageOps
+from scandir import walk
 from .shared import getImageFileName, walkLevel
 try:
     from PyQt5 import QtCore
@@ -246,7 +247,7 @@ def main(argv=None, qtGUI=None):
                 mergeWorkerOutput = []
                 mergeWorkerPool = Pool()
                 mergeWork.append([options.targetDir])
-                for root, dirs, files in os.walk(options.targetDir, False):
+                for root, dirs, files in walk(options.targetDir, False):
                     for directory in dirs:
                         directoryNumer += 1
                         mergeWork.append([os.path.join(root, directory)])
@@ -264,7 +265,7 @@ def main(argv=None, qtGUI=None):
                     rmtree(options.targetDir, True)
                     raise RuntimeError("One of workers crashed. Cause: " + mergeWorkerOutput[0])
             print("\nSplitting images...")
-            for root, dirs, files in os.walk(options.targetDir, False):
+            for root, dirs, files in walk(options.targetDir, False):
                 for name in files:
                     if getImageFileName(name) is not None:
                         pagenumber += 1
diff --git a/kcc/shared.py b/kcc/shared.py
index e9555e5..e2f6650 100644
--- a/kcc/shared.py
+++ b/kcc/shared.py
@@ -20,6 +20,7 @@ import os
 from hashlib import md5
 from html.parser import HTMLParser
 from distutils.version import StrictVersion
+from scandir import walk
 
 
 class HTMLStripper(HTMLParser):
@@ -49,7 +50,7 @@ def walkLevel(some_dir, level=1):
     some_dir = some_dir.rstrip(os.path.sep)
     assert os.path.isdir(some_dir)
     num_sep = some_dir.count(os.path.sep)
-    for root, dirs, files in os.walk(some_dir):
+    for root, dirs, files in walk(some_dir):
         yield root, dirs, files
         num_sep_this = root.count(os.path.sep)
         if num_sep + level <= num_sep_this:
@@ -102,6 +103,12 @@ def dependencyCheck(level):
             missing.append('Pillow 2.7.0+')
     except ImportError:
         missing.append('Pillow 2.7.0+')
+    try:
+        from scandir import __version__ as scandirVersion
+        if StrictVersion('0.9') > StrictVersion(scandirVersion):
+            missing.append('scandir 0.9+')
+    except ImportError:
+        missing.append('scandir 0.9+')
     if len(missing) > 0:
         print('ERROR: ' + ', '.join(missing) + ' is not installed!')
         exit(1)
\ No newline at end of file