From 3bedc3b928b525c7009b62d7a2bcc373abf74422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Tue, 13 Oct 2015 18:45:25 +0200 Subject: [PATCH] Windows: Miscellaneous tweaks --- kcc/comic2ebook.py | 6 +++--- kcc/shared.py | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index 20ba55f..27b6753 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -991,11 +991,11 @@ def detectCorruption(tmpPath, orgPath): raise RuntimeError('Image file %s is corrupted.' % pathOrg) else: 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. " + if imageSmaller > imageNumber * 0.25 and not options.upscale and not options.stretch: + print("\nMore than 25% of images are smaller than target device resolution. " "Consider enabling stretching or upscaling to improve readability.") if GUI: - GUI.addMessage.emit('More than half of images are smaller than target device resolution.', 'warning', False) + GUI.addMessage.emit('More than 25% of images are smaller than target device resolution.', 'warning', False) GUI.addMessage.emit('Consider enabling stretching or upscaling to improve readability.', 'warning', False) GUI.addMessage.emit('', '', False) diff --git a/kcc/shared.py b/kcc/shared.py index c6de633..b363998 100644 --- a/kcc/shared.py +++ b/kcc/shared.py @@ -97,11 +97,11 @@ def check7ZFile(filePath): def saferReplace(old, new): - for x in range(5): + for x in range(50): try: os.replace(old, new) except PermissionError: - sleep(5) + sleep(0.1) else: break else: @@ -109,11 +109,11 @@ def saferReplace(old, new): def saferRemove(target): - for x in range(5): + for x in range(50): try: os.remove(target) except PermissionError: - sleep(5) + sleep(0.1) else: break else: @@ -129,7 +129,15 @@ def removeFromZIP(zipfname, *filenames): for item in zipread.infolist(): if item.filename not in filenames: zipwrite.writestr(item, zipread.read(item.filename)) - copy(tempname, zipfname) + for x in range(50): + try: + copy(tempname, zipfname) + except PermissionError: + sleep(0.1) + else: + break + else: + raise PermissionError finally: rmtree(tempdir, True)