1
0
mirror of https://github.com/ciromattia/kcc synced 2026-01-30 17:07:41 +00:00

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

View File

@@ -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.")

View File

@@ -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: