From d0f96b6511815eb20a2609f6d9cb5be485de2fb8 Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Sat, 19 Mar 2022 18:17:38 -0700 Subject: [PATCH 1/4] Ensure XML is UTF-8 encoded --- comicapi/comicinfoxml.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/comicapi/comicinfoxml.py b/comicapi/comicinfoxml.py index d6a307b..1d80c78 100644 --- a/comicapi/comicinfoxml.py +++ b/comicapi/comicinfoxml.py @@ -51,12 +51,9 @@ class ComicInfoXml: return self.convertXMLToMetadata(tree) def stringFromMetadata(self, metadata, xml=None): - - header = '\n' - tree = self.convertMetadataToXML(self, metadata, xml) - tree_str = ET.tostring(tree.getroot()).decode() - return header + tree_str + tree_str = ET.tostring(tree.getroot(), encoding="utf-8", xml_declaration=True).decode() + return tree_str def indent(self, elem, level=0): # for making the XML output readable @@ -278,7 +275,7 @@ class ComicInfoXml: tree = self.convertMetadataToXML(self, metadata, xml) # ET.dump(tree) - tree.write(filename, encoding='utf-8') + tree.write(filename, encoding="utf-8", xml_declaration=True) def readFromExternalFile(self, filename): From 7d2702c3b6a7e400e3c9ee56eb4efb64fe98c7a4 Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Sun, 20 Mar 2022 02:09:47 -0700 Subject: [PATCH 2/4] Update pyinstaller --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 6d4e0a3..59613db 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,4 +1,4 @@ -pyinstaller==4.3 +pyinstaller>=4.10 setuptools>=42 setuptools_scm[toml]>=3.4 wheel From 95d167561ddf9c7dfd4f8c4a8b5e272368f0877b Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Sun, 20 Mar 2022 02:10:11 -0700 Subject: [PATCH 3/4] Fix locale for macOS --- comictagger.py | 1 + localefix.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 localefix.py diff --git a/comictagger.py b/comictagger.py index e85ab3f..0c738b1 100755 --- a/comictagger.py +++ b/comictagger.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import localefix from comictaggerlib.main import ctmain if __name__ == '__main__': diff --git a/localefix.py b/localefix.py new file mode 100644 index 0000000..74d339e --- /dev/null +++ b/localefix.py @@ -0,0 +1,44 @@ +import locale +import os +import subprocess +import sys + +def _lang_code_mac(): + """ + stolen from https://github.com/mu-editor/mu + Returns the user's language preference as defined in the Language & Region + preference pane in macOS's System Preferences. + """ + + # Uses the shell command `defaults read -g AppleLocale` that prints out a + # language code to standard output. Assumptions about the command: + # - It exists and is in the shell's PATH. + # - It accepts those arguments. + # - It returns a usable language code. + # + # Reference documentation: + # - The man page for the `defaults` command on macOS. + # - The macOS underlying API: + # https://developer.apple.com/documentation/foundation/nsuserdefaults. + + LANG_DETECT_COMMAND = 'defaults read -g AppleLocale' + + status, output = subprocess.getstatusoutput(LANG_DETECT_COMMAND) + if status == 0: + # Command was successful. + lang_code = output + else: + _logger.warning('Language detection command failed: %r', output) + lang_code = '' + + return lang_code + +if sys.platform == "darwin" and "LANG" not in os.environ: + code = _lang_code_mac() + if code != "": + os.environ["LANG"] = f"{code}.utf-8" + +locale.setlocale(locale.LC_ALL, '') +sys.stdout.reconfigure(encoding=sys.getdefaultencoding()) +sys.stderr.reconfigure(encoding=sys.getdefaultencoding()) +sys.stdin.reconfigure(encoding=sys.getdefaultencoding()) From 5de2ce65a4645deba976c509690b8037a128bebd Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Sun, 20 Mar 2022 10:39:53 -0700 Subject: [PATCH 4/4] Remove print statements Fixes #223 --- comicapi/comicinfoxml.py | 1 - comictaggerlib/comicvinetalker.py | 1 - 2 files changed, 2 deletions(-) diff --git a/comicapi/comicinfoxml.py b/comicapi/comicinfoxml.py index 1d80c78..d9b724a 100644 --- a/comicapi/comicinfoxml.py +++ b/comicapi/comicinfoxml.py @@ -87,7 +87,6 @@ class ComicInfoXml: def assign(cix_entry, md_entry): if md_entry is not None: - print(cix_entry, md_entry) et_entry = root.find(cix_entry) if et_entry is not None: et_entry.text = "{0}".format(md_entry) diff --git a/comictaggerlib/comicvinetalker.py b/comictaggerlib/comicvinetalker.py index d2b7736..9eef33a 100644 --- a/comictaggerlib/comicvinetalker.py +++ b/comictaggerlib/comicvinetalker.py @@ -630,7 +630,6 @@ class ComicVineTalker(QObject): for w in col_widths: fmtstr += " {{:{}}}|".format(w + 1) width = sum(col_widths) + len(col_widths) * 2 - print("width=", width) table_text = "" counter = 0 for row in rows: