about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaweł Jastrzębski <[email protected]>2015-09-30 16:51:54 +0200
committerPaweł Jastrzębski <[email protected]>2015-09-30 16:51:54 +0200
commit1a7b6baaf36b2fe90a556ab5ceafd75000c306a1 (patch)
tree731b66d39477e11849f895bd4fbcdaea534d42a5
parentOS X: GUI tweak for Retina display (close #158) (diff)
downloadkcc-1a7b6baaf36b2fe90a556ab5ceafd75000c306a1.tar.gz
kcc-1a7b6baaf36b2fe90a556ab5ceafd75000c306a1.tar.bz2
kcc-1a7b6baaf36b2fe90a556ab5ceafd75000c306a1.zip
Windows: Miscellenaus tweaks
-rwxr-xr-xkcc/comic2ebook.py6
-rw-r--r--kcc/shared.py14
2 files changed, 16 insertions, 4 deletions
diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py
index bad1865..20ba55f 100755
--- a/kcc/comic2ebook.py
+++ b/kcc/comic2ebook.py
@@ -46,7 +46,7 @@ try:
     from scandir import walk
 except ImportError:
     walk = os.walk
-from .shared import md5Checksum, getImageFileName, walkSort, walkLevel, saferReplace
+from .shared import md5Checksum, getImageFileName, walkSort, walkLevel, saferReplace, saferRemove
 from . import comic2panel
 from . import image
 from . import cbxarchive
@@ -584,7 +584,7 @@ def imgDirectoryProcessing(path):
             raise RuntimeError("One of workers crashed. Cause: " + workerOutput[0])
         for file in options.imgPurgeIndex:
             if os.path.isfile(file):
-                os.remove(file)
+                saferRemove(file)
     else:
         rmtree(os.path.join(path, '..', '..'), True)
         raise UserWarning("Source directory is empty.")
@@ -990,7 +990,7 @@ def detectCorruption(tmpPath, orgPath):
                     else:
                         raise RuntimeError('Image file %s is corrupted.' % pathOrg)
             else:
-                os.remove(os.path.join(root, name))
+                saferRemove(os.path.join(root, name))
     if imageSmaller > imageNumber * 0.5 and not options.upscale and not options.stretch:
         print("\nMore than half of images are smaller than target device resolution. "
               "Consider enabling stretching or upscaling to improve readability.")
diff --git a/kcc/shared.py b/kcc/shared.py
index 6393c32..cd44ee4 100644
--- a/kcc/shared.py
+++ b/kcc/shared.py
@@ -22,7 +22,7 @@ from hashlib import md5
 from html.parser import HTMLParser
 from distutils.version import StrictVersion
 from time import sleep
-from shutil import rmtree, move, copy
+from shutil import rmtree, copy
 from tempfile import mkdtemp
 from zipfile import ZipFile, ZIP_DEFLATED
 from re import split
@@ -108,6 +108,18 @@ def saferReplace(old, new):
         raise PermissionError
 
 
+def saferRemove(target):
+    for x in range(5):
+        try:
+            os.remove(target)
+        except PermissionError:
+            sleep(5)
+        else:
+            break
+    else:
+        raise PermissionError
+
+
 def removeFromZIP(zipfname, *filenames):
     tempdir = mkdtemp('', 'KCC-')
     try: