"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/calibre/gui2/viewer/convert_book.py" between
calibre-4.0.0.tar.xz and calibre-4.1.0.tar.xz

About: calibre is an e-book library management application (syncing, converting, viewing,\PKG_DESCR_TTnbsp;...).

convert_book.py  (calibre-4.0.0.tar.xz):convert_book.py  (calibre-4.1.0.tar.xz)
skipping to change at line 56 skipping to change at line 56
def robust_rmtree(x): def robust_rmtree(x):
retries = 2 if iswindows else 1 # retry on windows to get around the idioti c mandatory file locking retries = 2 if iswindows else 1 # retry on windows to get around the idioti c mandatory file locking
for i in range(retries): for i in range(retries):
try: try:
shutil.rmtree(x) shutil.rmtree(x)
return True return True
except EnvironmentError: except EnvironmentError:
time.sleep(0.1) time.sleep(0.1)
return False return False
def robust_rename(a, b):
retries = 20 if iswindows else 1 # retry on windows to get around the idiot
ic mandatory file locking
for i in range(retries):
os.rename(a, b)
return True
except EnvironmentError:
return False
def clear_temp(temp_path): def clear_temp(temp_path):
now = time.time() now = time.time()
for x in os.listdir(temp_path): for x in os.listdir(temp_path):
x = os.path.join(temp_path, x) x = os.path.join(temp_path, x)
mtime = os.path.getmtime(x) mtime = os.path.getmtime(x)
if now - mtime > DAY: if now - mtime > DAY:
robust_rmtree(x) robust_rmtree(x)
def expire_cache(path, instances, max_age): def expire_cache(path, instances, max_age):
now = time.time() now = time.time()
skipping to change at line 150 skipping to change at line 160
with cache_lock() as f: with cache_lock() as f:
ans = tempfile.mkdtemp(dir=finished_path) ans = tempfile.mkdtemp(dir=finished_path)
instance['path'] = os.path.basename(ans) instance['path'] = os.path.basename(ans)
try: try:
metadata = json.loads(f.read()) metadata = json.loads(f.read())
except ValueError: except ValueError:
metadata = {'entries': {}, 'last_clear_at': 0} metadata = {'entries': {}, 'last_clear_at': 0}
entries = metadata['entries'] entries = metadata['entries']
instances = entries.setdefault(key, []) instances = entries.setdefault(key, [])
os.rmdir(ans) os.rmdir(ans)
os.rename(src_path, ans) if not robust_rename(src_path, ans):
raise Exception((
'Failed to rename: "{}" to "{}" probably some software such as a
n antivirus or file sync program'
' running on your computer has locked the files'
).format(src_path, ans))
instance['status'] = 'finished' instance['status'] = 'finished'
for q in instances: for q in instances:
if q['id'] == instance['id']: if q['id'] == instance['id']:
q.update(instance) q.update(instance)
break break
expire_cache_and_temp(temp_path, finished_path, metadata, max_age) expire_cache_and_temp(temp_path, finished_path, metadata, max_age)
save_metadata(metadata, f) save_metadata(metadata, f)
return ans return ans
def update_book(path, old_stat, name_data_map=None): def update_book(path, old_stat, name_data_map=None):
 End of changes. 2 change blocks. 
1 lines changed or deleted 18 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)