From 3a287504ae85bd4b4c2028a4202fa29b9507af0c Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Thu, 15 Jun 2023 20:25:19 -0700 Subject: [PATCH] Fix setting issue and alternate_number on GenericMetadata IssueString.as_string always returns a string this is a problem for GenericMetadata. When the overlay function is used it checks specifically for the value None this allows the -m option to unset attributes however the issue attribute would get set to the empty string when loading ComicRack tags regardless of if there was a value stored in the file. Fixes #465 and #480 --- comicapi/comicinfoxml.py | 5 ++--- comicapi/utils.py | 4 +++- comictaggerlib/filerenamer.py | 6 +----- comictaggerlib/taggerwindow.py | 38 +++++++++++++++++----------------- comictalker/talker_utils.py | 2 +- testing/comicdata.py | 8 +++++++ 6 files changed, 34 insertions(+), 29 deletions(-) diff --git a/comicapi/comicinfoxml.py b/comicapi/comicinfoxml.py index 124b6dc..a4a4873 100644 --- a/comicapi/comicinfoxml.py +++ b/comicapi/comicinfoxml.py @@ -22,7 +22,6 @@ from xml.etree.ElementTree import ElementTree from comicapi import utils from comicapi.genericmetadata import GenericMetadata, ImageMetadata -from comicapi.issuestring import IssueString logger = logging.getLogger(__name__) @@ -189,11 +188,11 @@ class ComicInfoXml: md.series = utils.xlate(get("Series")) md.title = utils.xlate(get("Title")) - md.issue = IssueString(utils.xlate(get("Number"))).as_string() + md.issue = utils.xlate(get("Number")) md.issue_count = utils.xlate_int(get("Count")) md.volume = utils.xlate_int(get("Volume")) md.alternate_series = utils.xlate(get("AlternateSeries")) - md.alternate_number = IssueString(utils.xlate(get("AlternateNumber"))).as_string() + md.alternate_number = utils.xlate(get("AlternateNumber")) md.alternate_count = utils.xlate_int(get("AlternateCount")) md.comments = utils.xlate(get("Summary")) md.notes = utils.xlate(get("Notes")) diff --git a/comicapi/utils.py b/comicapi/utils.py index 090c59b..99bcad9 100644 --- a/comicapi/utils.py +++ b/comicapi/utils.py @@ -115,6 +115,8 @@ def xlate_int(data: Any) -> int | None: def xlate_float(data: Any) -> float | None: + if isinstance(data, str): + data = data.strip() if data is None or data == "": return None i: str | int | float @@ -131,7 +133,7 @@ def xlate_float(data: Any) -> float | None: def xlate(data: Any) -> str | None: - if data is None or data == "": + if data is None or isinstance(data, str) and data.strip() == "": return None return str(data) diff --git a/comictaggerlib/filerenamer.py b/comictaggerlib/filerenamer.py index 8aca69e..da84978 100644 --- a/comictaggerlib/filerenamer.py +++ b/comictaggerlib/filerenamer.py @@ -209,15 +209,13 @@ class FileRenamer: md = self.metadata - # padding for issue - md.issue = IssueString(md.issue).as_string(pad=self.issue_zero_padding) - template = self.template new_name = "" fmt = MetadataFormatter(self.smart_cleanup, platform=self.platform, replacements=self.replacements) md_dict = vars(md) + md_dict["issue"] = IssueString(md.issue).as_string(pad=self.issue_zero_padding) for role in ["writer", "penciller", "inker", "colorist", "letterer", "cover artist", "editor"]: md_dict[role] = md.get_primary_credit(role) @@ -238,8 +236,6 @@ class FileRenamer: new_name += ext new_basename += ext - # remove padding - md.issue = IssueString(md.issue).as_string() if self.move: return new_name.strip() return new_basename.strip() diff --git a/comictaggerlib/taggerwindow.py b/comictaggerlib/taggerwindow.py index 0550386..3e3b701 100644 --- a/comictaggerlib/taggerwindow.py +++ b/comictaggerlib/taggerwindow.py @@ -897,8 +897,8 @@ class TaggerWindow(QtWidgets.QMainWindow): # copy the data from the form into the metadata md = GenericMetadata() md.is_empty = False - md.alternate_number = IssueString(self.leAltIssueNum.text()).as_string() - md.issue = IssueString(self.leIssueNum.text()).as_string() + md.alternate_number = utils.xlate(IssueString(self.leAltIssueNum.text()).as_string()) + md.issue = utils.xlate(IssueString(self.leIssueNum.text()).as_string()) md.issue_count = utils.xlate_int(self.leIssueCount.text()) md.volume = utils.xlate_int(self.leVolumeNum.text()) md.volume_count = utils.xlate_int(self.leVolumeCount.text()) @@ -907,30 +907,30 @@ class TaggerWindow(QtWidgets.QMainWindow): md.day = utils.xlate_int(self.lePubDay.text()) md.alternate_count = utils.xlate_int(self.leAltIssueCount.text()) - md.series = self.leSeries.text() - md.title = self.leTitle.text() - md.publisher = self.lePublisher.text() - md.genre = self.leGenre.text() - md.imprint = self.leImprint.text() - md.comments = self.teComments.toPlainText() - md.notes = self.teNotes.toPlainText() + md.series = utils.xlate(self.leSeries.text()) + md.title = utils.xlate(self.leTitle.text()) + md.publisher = utils.xlate(self.lePublisher.text()) + md.genre = utils.xlate(self.leGenre.text()) + md.imprint = utils.xlate(self.leImprint.text()) + md.comments = utils.xlate(self.teComments.toPlainText()) + md.notes = utils.xlate(self.teNotes.toPlainText()) md.maturity_rating = self.cbMaturityRating.currentText() md.critical_rating = utils.xlate_float(self.dsbCriticalRating.cleanText()) if md.critical_rating == 0.0: md.critical_rating = None - md.story_arc = self.leStoryArc.text() - md.scan_info = self.leScanInfo.text() - md.series_group = self.leSeriesGroup.text() - md.alternate_series = self.leAltSeries.text() - md.web_link = self.leWebLink.text() - md.characters = self.teCharacters.toPlainText() - md.teams = self.teTeams.toPlainText() - md.locations = self.teLocations.toPlainText() + md.story_arc = utils.xlate(self.leStoryArc.text()) + md.scan_info = utils.xlate(self.leScanInfo.text()) + md.series_group = utils.xlate(self.leSeriesGroup.text()) + md.alternate_series = utils.xlate(self.leAltSeries.text()) + md.web_link = utils.xlate(self.leWebLink.text()) + md.characters = utils.xlate(self.teCharacters.toPlainText()) + md.teams = utils.xlate(self.teTeams.toPlainText()) + md.locations = utils.xlate(self.teLocations.toPlainText()) - md.format = self.cbFormat.currentText() - md.country = self.cbCountry.currentText() + md.format = utils.xlate(self.cbFormat.currentText()) + md.country = utils.xlate(self.cbCountry.currentText()) md.language = utils.xlate(self.cbLanguage.itemData(self.cbLanguage.currentIndex())) diff --git a/comictalker/talker_utils.py b/comictalker/talker_utils.py index 92b32d6..299c2ef 100644 --- a/comictalker/talker_utils.py +++ b/comictalker/talker_utils.py @@ -43,7 +43,7 @@ def map_comic_issue_to_metadata( metadata.is_empty = False metadata.series = utils.xlate(issue_results.series.name) - metadata.issue = IssueString(issue_results.issue_number).as_string() + metadata.issue = utils.xlate(IssueString(issue_results.issue_number).as_string()) # Rely on comic talker to validate this number metadata.issue_count = utils.xlate_int(issue_results.series.volume) diff --git a/testing/comicdata.py b/testing/comicdata.py index 4baf139..0de6540 100644 --- a/testing/comicdata.py +++ b/testing/comicdata.py @@ -67,6 +67,14 @@ metadata = [ comicapi.genericmetadata.GenericMetadata(series="", issue="2", title="never"), comicapi.genericmetadata.md_test.replace(series=None, issue="2", title="never"), ), + ( + comicapi.genericmetadata.GenericMetadata(series="", issue="", title="never"), + comicapi.genericmetadata.md_test.replace(series=None, issue=None, title="never"), + ), + ( + comicapi.genericmetadata.GenericMetadata(series="", issue=None, title="never"), + comicapi.genericmetadata.md_test.replace(series=None, issue="1", title="never"), + ), ( comicapi.genericmetadata.GenericMetadata(), comicapi.genericmetadata.md_test.copy(),