From 0ccc3f72523aff28f1c330665126a2e927090ffc Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Tue, 21 Jul 2020 20:14:08 +0200 Subject: [PATCH] Fixes for windows (moving files not allowed -> Close pdf after metadata extracting, add os.path.normcase to path while renaming folders, as thi caused also trouble Added hint for missing ghostcript on cover extraction --- cps/helper.py | 13 +++++++------ cps/uploader.py | 5 +++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cps/helper.py b/cps/helper.py index 20f3d4ad..681719a9 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -340,13 +340,13 @@ def update_dir_structure_file(book_id, calibrepath, first_author): new_title_path = os.path.join(os.path.dirname(path), new_titledir) try: if not os.path.exists(new_title_path): - os.renames(path, new_title_path) + os.renames(os.path.normcase(path), os.path.normcase(new_title_path)) else: log.info("Copying title: %s into existing: %s", path, new_title_path) for dir_name, __, file_list in os.walk(path): for file in file_list: - os.renames(os.path.join(dir_name, file), - os.path.join(new_title_path + dir_name[len(path):], file)) + os.renames(os.path.normcase(os.path.join(dir_name, file)), + os.path.normcase(os.path.join(new_title_path + dir_name[len(path):], file))) path = new_title_path localbook.path = localbook.path.split('/')[0] + '/' + new_titledir except OSError as ex: @@ -357,7 +357,7 @@ def update_dir_structure_file(book_id, calibrepath, first_author): if authordir != new_authordir: new_author_path = os.path.join(calibrepath, new_authordir, os.path.basename(path)) try: - os.renames(path, new_author_path) + os.renames(os.path.normcase(path), os.path.normcase(new_author_path)) localbook.path = new_authordir + '/' + localbook.path.split('/')[1] except OSError as ex: log.error("Rename author from: %s to %s: %s", path, new_author_path, ex) @@ -370,8 +370,9 @@ def update_dir_structure_file(book_id, calibrepath, first_author): new_name = get_valid_filename(localbook.title) + ' - ' + get_valid_filename(new_authordir) path_name = os.path.join(calibrepath, new_authordir, os.path.basename(path)) for file_format in localbook.data: - os.renames(os.path.join(path_name, file_format.name + '.' + file_format.format.lower()), - os.path.join(path_name, new_name + '.' + file_format.format.lower())) + os.renames(os.path.normcase( + os.path.join(path_name, file_format.name + '.' + file_format.format.lower())), + os.path.normcase(os.path.join(path_name, new_name + '.' + file_format.format.lower()))) file_format.name = new_name except OSError as ex: log.error("Rename file in path %s to %s: %s", path, new_name, ex) diff --git a/cps/uploader.py b/cps/uploader.py index 1323e3d0..74c94d83 100644 --- a/cps/uploader.py +++ b/cps/uploader.py @@ -116,8 +116,8 @@ def default_meta(tmp_file_path, original_file_name, original_file_extension): def pdf_meta(tmp_file_path, original_file_name, original_file_extension): doc_info = None if use_pdf_meta: - doc_info = PdfFileReader(open(tmp_file_path, 'rb')).getDocumentInfo() - + with open(tmp_file_path, 'rb') as f: + doc_info = PdfFileReader(f).getDocumentInfo() if doc_info: author = doc_info.author if doc_info.author else u'Unknown' title = doc_info.title if doc_info.title else original_file_name @@ -156,6 +156,7 @@ def pdf_preview(tmp_file_path, tmp_dir): return None except Exception as ex: log.warning('Cannot extract cover image, using default: %s', ex) + log.warning('On Windows this error could be caused by missing ghostscript') return None