Merge branch 'MichaelFitzurka-feature/247-empty-tags' into develop

This commit is contained in:
Timmy Welch 2022-04-04 14:16:29 -07:00
commit 62baa79d23
2 changed files with 16 additions and 16 deletions

View File

@ -65,13 +65,13 @@ class SevenZipArchiver:
self.path = path self.path = path
# @todo: Implement Comment? # @todo: Implement Comment?
def getArchiveComment(self): def get_comment(self):
return "" return ""
def setArchiveComment(self, comment): def set_comment(self, comment):
return False return False
def readArchiveFile(self, archive_file): def read_file(self, archive_file):
data = "" data = ""
try: try:
with py7zr.SevenZipFile(self.path, "r") as zf: with py7zr.SevenZipFile(self.path, "r") as zf:
@ -85,22 +85,22 @@ class SevenZipArchiver:
return data return data
def removeArchiveFile(self, archive_file): def remove_file(self, archive_file):
try: try:
self.rebuildSevenZipFile([archive_file]) self.rebuild_zip_file([archive_file])
except: except:
return False return False
else: else:
return True return True
def writeArchiveFile(self, archive_file, data): def write_file(self, archive_file, data):
# At the moment, no other option but to rebuild the whole # At the moment, no other option but to rebuild the whole
# zip archive w/o the indicated file. Very sucky, but maybe # zip archive w/o the indicated file. Very sucky, but maybe
# another solution can be found # another solution can be found
try: try:
files = self.getArchiveFilenameList() files = self.get_filename_list()
if archive_file in files: if archive_file in files:
self.rebuildSevenZipFile([archive_file]) self.rebuild_zip_file([archive_file])
# now just add the archive file as a new one # now just add the archive file as a new one
with py7zr.SevenZipFile(self.path, "a") as zf: with py7zr.SevenZipFile(self.path, "a") as zf:
@ -109,7 +109,7 @@ class SevenZipArchiver:
except: except:
return False return False
def getArchiveFilenameList(self): def get_filename_list(self):
try: try:
with py7zr.SevenZipFile(self.path, "r") as zf: with py7zr.SevenZipFile(self.path, "r") as zf:
namelist = zf.getnames() namelist = zf.getnames()
@ -119,7 +119,7 @@ class SevenZipArchiver:
logger.warning("Unable to get 7zip file list [%s]: %s", e, self.path) logger.warning("Unable to get 7zip file list [%s]: %s", e, self.path)
return [] return []
def rebuildSevenZipFile(self, exclude_list): def rebuild_zip_file(self, exclude_list):
"""Zip helper func """Zip helper func
This recompresses the zip archive, without the files in the exclude_list This recompresses the zip archive, without the files in the exclude_list
@ -142,12 +142,12 @@ class SevenZipArchiver:
os.remove(self.path) os.remove(self.path)
os.rename(tmp_name, self.path) os.rename(tmp_name, self.path)
def copyFromArchive(self, otherArchive): def copy_from_archive(self, otherArchive):
"""Replace the current zip with one copied from another archive""" """Replace the current zip with one copied from another archive"""
try: try:
with py7zr.SevenZipFile(self.path, "w") as zout: with py7zr.SevenZipFile(self.path, "w") as zout:
for fname in otherArchive.getArchiveFilenameList(): for fname in otherArchive.get_filename_list():
data = otherArchive.readArchiveFile(fname) data = otherArchive.read_file(fname)
if data is not None: if data is not None:
zout.writestr(data, fname) zout.writestr(data, fname)
except Exception as e: except Exception as e:

View File

@ -67,7 +67,7 @@ class ComicInfoXml:
# helper func # helper func
def assign(cix_entry, md_entry): def assign(cix_entry, md_entry):
if md_entry is not None: if md_entry is not None and md_entry:
et_entry = root.find(cix_entry) et_entry = root.find(cix_entry)
if et_entry is not None: if et_entry is not None:
et_entry.text = str(md_entry) et_entry.text = str(md_entry)
@ -152,7 +152,7 @@ class ComicInfoXml:
assign("LanguageISO", md.language) assign("LanguageISO", md.language)
assign("Format", md.format) assign("Format", md.format)
assign("AgeRating", md.maturity_rating) assign("AgeRating", md.maturity_rating)
assign("BlackAndWhite", "Yes" if md.blackAndWhite else None) assign("BlackAndWhite", "Yes" if md.black_and_white else None)
assign("Manga", md.manga) assign("Manga", md.manga)
assign("Characters", md.characters) assign("Characters", md.characters)
assign("Teams", md.teams) assign("Teams", md.teams)
@ -168,7 +168,7 @@ class ComicInfoXml:
for page_dict in md.pages: for page_dict in md.pages:
page_node = ET.SubElement(pages_node, "Page") page_node = ET.SubElement(pages_node, "Page")
page_node.attrib = page_dict page_node.attrib = dict(sorted(page_dict.items()))
utils.indent(root) utils.indent(root)