From 24f59552fbedb559451bb6eebc5b18a6bf228d80 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Menil Date: Wed, 16 Nov 2022 16:31:34 +0100 Subject: [PATCH 1/3] comicrack: fix generated xml Signed-off-by: Jean-Philippe Menil --- bdnex/conf/ComicInfo.xsd | 4 ++-- bdnex/conf/bdgest_mapping.json | 3 ++- bdnex/lib/comicrack.py | 18 ++++++------------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/bdnex/conf/ComicInfo.xsd b/bdnex/conf/ComicInfo.xsd index 244a989..0fa3a10 100755 --- a/bdnex/conf/ComicInfo.xsd +++ b/bdnex/conf/ComicInfo.xsd @@ -2,7 +2,7 @@ - + @@ -41,7 +41,7 @@ - + diff --git a/bdnex/conf/bdgest_mapping.json b/bdnex/conf/bdgest_mapping.json index fa23991..a12695b 100644 --- a/bdnex/conf/bdgest_mapping.json +++ b/bdnex/conf/bdgest_mapping.json @@ -5,7 +5,8 @@ "Editeur": "Publisher", "Format": "Format", "Language": "LanguageISO", - "Scénario": "Letterer", + "Lettrage": "Letterer", + "Scénario": "Writer", "Titre": "Title", "Tome": "Volume", "author": "Writer", diff --git a/bdnex/lib/comicrack.py b/bdnex/lib/comicrack.py index fd99595..31971a9 100644 --- a/bdnex/lib/comicrack.py +++ b/bdnex/lib/comicrack.py @@ -5,6 +5,8 @@ import rarfile import zipfile import logging +import json +import xmlschema from pkg_resources import resource_filename @@ -22,20 +24,12 @@ def __init__(self, input_filename=None, comic_info=None): def comicInfo_xml_create(self): self.logger.info("Create ComicInfo.xml") - mytree = ET.parse(COMICINFO_TEMPLATE) - myroot = mytree.getroot() - - for element in myroot[1][0]: - metadata_key = element.attrib['name'] - if metadata_key in self.comic_info.keys(): - if element.attrib["type"] == "xs:string": - element.attrib['default'] = str(self.comic_info[metadata_key]) - elif element.attrib["type"] == "xs:int": - element.attrib['default'] = str(self.comic_info[metadata_key]) - tmpdir = tempfile.mkdtemp() comic_info_fp = os.path.join(tmpdir, 'ComicInfo.xml') - mytree.write(comic_info_fp, encoding='UTF-8', xml_declaration=True) + + data = json.dumps(self.comic_info) + tmp_xml = xmlschema.from_json(data, preserve_root=True, schema=schema) + ET.ElementTree(tmp_xml).write(comic_info_fp, encoding='UTF-8', xml_declaration=True) return comic_info_fp From 7fa9ba3cacf049cf578dbf6a0d94b1f9925dae5f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Menil Date: Wed, 16 Nov 2022 16:35:29 +0100 Subject: [PATCH 2/3] fixup! comicrack: fix generated xml Signed-off-by: Jean-Philippe Menil --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index bce7ea5..c12b049 100755 --- a/setup.py +++ b/setup.py @@ -56,6 +56,7 @@ def _read(fn): 'tenacity', 'opencv-contrib-python-headless', 'pandas', + 'xmlschema', ], extras_require={ From 31c0661b7b6120c885b21b82805fbb1b9d9da501 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Menil Date: Thu, 17 Nov 2022 08:48:10 +0100 Subject: [PATCH 3/3] fix schema not defined Signed-off-by: Jean-Philippe Menil --- bdnex/lib/comicrack.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bdnex/lib/comicrack.py b/bdnex/lib/comicrack.py index 31971a9..2f1a9f4 100644 --- a/bdnex/lib/comicrack.py +++ b/bdnex/lib/comicrack.py @@ -27,6 +27,7 @@ def comicInfo_xml_create(self): tmpdir = tempfile.mkdtemp() comic_info_fp = os.path.join(tmpdir, 'ComicInfo.xml') + schema = xmlschema.XMLSchema(COMICINFO_TEMPLATE) data = json.dumps(self.comic_info) tmp_xml = xmlschema.from_json(data, preserve_root=True, schema=schema) ET.ElementTree(tmp_xml).write(comic_info_fp, encoding='UTF-8', xml_declaration=True)