Fix #242
Fix file encoding inconsistencies, windows defaults to cp1252, which is not Unicode compatible. Add logging for all exceptions in the comicapi package Ensure that all exceptions are logged and shown to the user
This commit is contained in:
parent
96b44d4cba
commit
826b3ce898
@ -92,6 +92,7 @@ class SevenZipArchiver:
|
|||||||
try:
|
try:
|
||||||
self.rebuild_zip_file([archive_file])
|
self.rebuild_zip_file([archive_file])
|
||||||
except:
|
except:
|
||||||
|
logger.exception("Failed to remove %s from 7zip archive", archive_file)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
@ -110,6 +111,7 @@ class SevenZipArchiver:
|
|||||||
zf.writestr(data, archive_file)
|
zf.writestr(data, archive_file)
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
|
logger.exception("Writing zip file failed")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_filename_list(self):
|
def get_filename_list(self):
|
||||||
@ -194,6 +196,7 @@ class ZipArchiver:
|
|||||||
try:
|
try:
|
||||||
self.rebuild_zip_file([archive_file])
|
self.rebuild_zip_file([archive_file])
|
||||||
except:
|
except:
|
||||||
|
logger.exception("Failed to remove %s from zip archive", archive_file)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
@ -306,7 +309,7 @@ class ZipArchiver:
|
|||||||
else:
|
else:
|
||||||
raise Exception("Failed to write comment to zip file!")
|
raise Exception("Failed to write comment to zip file!")
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception()
|
logger.exception("Writing comment to %s failed", filename)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
@ -342,7 +345,7 @@ class RarArchiver:
|
|||||||
self.rar_exe_path = rar_exe_path
|
self.rar_exe_path = rar_exe_path
|
||||||
|
|
||||||
if RarArchiver.devnull is None:
|
if RarArchiver.devnull is None:
|
||||||
RarArchiver.devnull = open(os.devnull, "w")
|
RarArchiver.devnull = open(os.devnull, "bw")
|
||||||
|
|
||||||
# windows only, keeps the cmd.exe from popping up
|
# windows only, keeps the cmd.exe from popping up
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
@ -360,9 +363,8 @@ class RarArchiver:
|
|||||||
try:
|
try:
|
||||||
# write comment to temp file
|
# write comment to temp file
|
||||||
tmp_fd, tmp_name = tempfile.mkstemp()
|
tmp_fd, tmp_name = tempfile.mkstemp()
|
||||||
f = os.fdopen(tmp_fd, "w+")
|
with os.fdopen(tmp_fd, "wb") as f:
|
||||||
f.write(comment)
|
f.write(comment.encode("utf-8"))
|
||||||
f.close()
|
|
||||||
|
|
||||||
working_dir = os.path.dirname(os.path.abspath(self.path))
|
working_dir = os.path.dirname(os.path.abspath(self.path))
|
||||||
|
|
||||||
@ -441,7 +443,7 @@ class RarArchiver:
|
|||||||
|
|
||||||
# TODO: will this break if 'archive_file' is in a subfolder. i.e. "foo/bar.txt"
|
# TODO: will this break if 'archive_file' is in a subfolder. i.e. "foo/bar.txt"
|
||||||
# will need to create the subfolder above, I guess...
|
# will need to create the subfolder above, I guess...
|
||||||
with open(tmp_file, "w") as f:
|
with open(tmp_file, "wb") as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
|
||||||
# use external program to write file to Rar archive
|
# use external program to write file to Rar archive
|
||||||
@ -457,7 +459,9 @@ class RarArchiver:
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
os.remove(tmp_file)
|
os.remove(tmp_file)
|
||||||
os.rmdir(tmp_folder)
|
os.rmdir(tmp_folder)
|
||||||
except:
|
except Exception as e:
|
||||||
|
logger.info(str(e))
|
||||||
|
logger.exception("Failed write %s to rar archive", archive_file)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
@ -479,6 +483,7 @@ class RarArchiver:
|
|||||||
if platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
except:
|
except:
|
||||||
|
logger.exception("Failed to remove %s from rar archive", archive_file)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
@ -543,7 +548,6 @@ class FolderArchiver:
|
|||||||
try:
|
try:
|
||||||
with open(fname, "rb") as f:
|
with open(fname, "rb") as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
f.close()
|
|
||||||
except IOError:
|
except IOError:
|
||||||
logger.exception("Failed to read: %s", fname)
|
logger.exception("Failed to read: %s", fname)
|
||||||
|
|
||||||
@ -553,11 +557,10 @@ class FolderArchiver:
|
|||||||
|
|
||||||
fname = os.path.join(self.path, archive_file)
|
fname = os.path.join(self.path, archive_file)
|
||||||
try:
|
try:
|
||||||
with open(fname, "w+") as f:
|
with open(fname, "wb") as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
f.close()
|
|
||||||
except:
|
except:
|
||||||
logger.exception("Failed to read: %s", fname)
|
logger.exception("Failed to write: %s", fname)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
@ -568,7 +571,7 @@ class FolderArchiver:
|
|||||||
try:
|
try:
|
||||||
os.remove(fname)
|
os.remove(fname)
|
||||||
except:
|
except:
|
||||||
logger.exception("Failed to read: %s", fname)
|
logger.exception("Failed to remove: %s", fname)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
@ -976,7 +979,7 @@ class ComicArchive:
|
|||||||
if raw_cix == "":
|
if raw_cix == "":
|
||||||
raw_cix = None
|
raw_cix = None
|
||||||
cix_string = ComicInfoXml().string_from_metadata(metadata, xml=raw_cix)
|
cix_string = ComicInfoXml().string_from_metadata(metadata, xml=raw_cix)
|
||||||
write_success = self.archiver.write_file(self.ci_xml_filename, cix_string)
|
write_success = self.archiver.write_file(self.ci_xml_filename, cix_string.encode("utf-8"))
|
||||||
if write_success:
|
if write_success:
|
||||||
self.has__cix = True
|
self.has__cix = True
|
||||||
self.cix_md = metadata
|
self.cix_md = metadata
|
||||||
@ -1088,8 +1091,7 @@ class ComicArchive:
|
|||||||
data = self.archiver.read_file(n)
|
data = self.archiver.read_file(n)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
data = ""
|
data = ""
|
||||||
err_msg = f"Error reading in Comet XML for validation!: {e}"
|
logger.warning("Error reading in Comet XML for validation!: %s", e)
|
||||||
logger.warning(err_msg)
|
|
||||||
if CoMet().validate_string(data):
|
if CoMet().validate_string(data):
|
||||||
# since we found it, save it!
|
# since we found it, save it!
|
||||||
self.comet_filename = n
|
self.comet_filename = n
|
||||||
|
@ -119,5 +119,5 @@ class ComicBookInfo:
|
|||||||
|
|
||||||
cbi_container = self.create_json_dictionary(metadata)
|
cbi_container = self.create_json_dictionary(metadata)
|
||||||
|
|
||||||
with open(filename, "w") as f:
|
with open(filename, "w", encoding="utf-8") as f:
|
||||||
f.write(json.dumps(cbi_container, indent=4))
|
f.write(json.dumps(cbi_container, indent=4))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user