Skip to content

comicrack: fix generated xml - #7

Merged
lbesnard merged 3 commits into
lbesnard:mainfrom
jpmenil:fix/xml
Nov 20, 2022
Merged

comicrack: fix generated xml#7
lbesnard merged 3 commits into
lbesnard:mainfrom
jpmenil:fix/xml

Conversation

@jpmenil

@jpmenil jpmenil commented Nov 16, 2022

Copy link
Copy Markdown
Collaborator

The current generated xml file is in fact, an xml schema.
xmlschema is used to generate the ComicInfo.xml against the xsd schema.
I needed to update the schema from xs:sequence to xs:all (anansi-project/comicinfo#29) in order to make it work.
In the mean time, fix Letterer.

Signed-off-by: Jean-Philippe Menil jpmenil@gmail.com

Signed-off-by: Jean-Philippe Menil <jpmenil@gmail.com>
Signed-off-by: Jean-Philippe Menil <jpmenil@gmail.com>
Comment thread bdnex/lib/comicrack.py
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)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schema is not defined, I think you meant to have something such as

with open(COMICINFO_TEMPLATE, 'r') as xsd_template:
     schema = xsd_template.read()

     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)

However, even with this, this code change is not working unfortunately. Currently, all the values stored in self.comic_info (coming from the json file) are set as strings and converted into str or integer in the deleted code above, note that L34 should have been int(self.comic_info[metadata_key]) instead of str(self.comic_info[metadata_key]).

So now with this code change, the data coming from the json file is expected to be of the right type but it now breaks against the xsd schema validation, see for example with the number of pages "120":

xmlschema.validators.exceptions.XMLSchemaEncodeError: failed validating '120' with XsdAtomicBuiltin(name='xs:int'):

Reason: '120' is not an instance of <class 'int'>

So maybe some refactoring could be done in https://github.com/lbesnard/bdnex/blob/main/bdnex/conf/bdgest_mapping.json to add the type of each key

such as:

{
    "Couleurs": {"value": "Colorist",
                        "type": "str"},
    "Couverture":  {"value": "CoverArtist",
                        "type": "str"},
    "Planches":  {"value": "PageCount",
                         "type": "int"}
}

and modify the code accordingly in https://github.com/lbesnard/bdnex/blob/main/bdnex/lib/bdgest.py#L428

thoughts?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pushed a fix regarding the schema i've forgot... thx for catching it!!
Doesn't the pagecount integer problem haven't been fixed here:
#5 ?

Signed-off-by: Jean-Philippe Menil <jpmenil@gmail.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Base: 60.95% // Head: 61.53% // Increases project coverage by +0.58% 🎉

Coverage data is based on head (31c0661) compared to base (da95f85).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##             main       #7      +/-   ##
==========================================
+ Coverage   60.95%   61.53%   +0.58%     
==========================================
  Files           5        5              
  Lines         461      468       +7     
==========================================
+ Hits          281      288       +7     
  Misses        180      180              
Impacted Files Coverage Δ
bdnex/lib/bdgest.py 63.14% <0.00%> (+0.84%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@lbesnard
lbesnard merged commit 24aef14 into lbesnard:main Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants