Windows: Miscellenaus tweaks

This commit is contained in:
Paweł Jastrzębski
2015-09-30 16:51:54 +02:00
parent 0f8daaf9f3
commit 1a7b6baaf3
2 changed files with 16 additions and 4 deletions
+3 -3
View File
@@ -46,7 +46,7 @@ try:
from scandir import walk from scandir import walk
except ImportError: except ImportError:
walk = os.walk 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 comic2panel
from . import image from . import image
from . import cbxarchive from . import cbxarchive
@@ -584,7 +584,7 @@ def imgDirectoryProcessing(path):
raise RuntimeError("One of workers crashed. Cause: " + workerOutput[0]) raise RuntimeError("One of workers crashed. Cause: " + workerOutput[0])
for file in options.imgPurgeIndex: for file in options.imgPurgeIndex:
if os.path.isfile(file): if os.path.isfile(file):
os.remove(file) saferRemove(file)
else: else:
rmtree(os.path.join(path, '..', '..'), True) rmtree(os.path.join(path, '..', '..'), True)
raise UserWarning("Source directory is empty.") raise UserWarning("Source directory is empty.")
@@ -990,7 +990,7 @@ def detectCorruption(tmpPath, orgPath):
else: else:
raise RuntimeError('Image file %s is corrupted.' % pathOrg) raise RuntimeError('Image file %s is corrupted.' % pathOrg)
else: 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: 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. " print("\nMore than half of images are smaller than target device resolution. "
"Consider enabling stretching or upscaling to improve readability.") "Consider enabling stretching or upscaling to improve readability.")
+13 -1
View File
@@ -22,7 +22,7 @@ from hashlib import md5
from html.parser import HTMLParser from html.parser import HTMLParser
from distutils.version import StrictVersion from distutils.version import StrictVersion
from time import sleep from time import sleep
from shutil import rmtree, move, copy from shutil import rmtree, copy
from tempfile import mkdtemp from tempfile import mkdtemp
from zipfile import ZipFile, ZIP_DEFLATED from zipfile import ZipFile, ZIP_DEFLATED
from re import split from re import split
@@ -108,6 +108,18 @@ def saferReplace(old, new):
raise PermissionError 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): def removeFromZIP(zipfname, *filenames):
tempdir = mkdtemp('', 'KCC-') tempdir = mkdtemp('', 'KCC-')
try: try: