1
0
mirror of https://github.com/moparisthebest/xeps synced 2024-11-22 01:02:17 -05:00

tooling: print metadata extraction errors to stderr

This commit is contained in:
Jonas Wielicki 2017-08-23 16:33:28 +02:00
parent a455020d3a
commit 0ff93d4fa0

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import pathlib import pathlib
import sys
import xml.dom.minidom import xml.dom.minidom
import xml.etree.ElementTree as etree import xml.etree.ElementTree as etree
@ -160,6 +161,8 @@ def main():
tree = etree.Element("xep-infos") tree = etree.Element("xep-infos")
has_error = False
for xepfile in args.xepdir.glob("xep-*.xml"): for xepfile in args.xepdir.glob("xep-*.xml"):
number = xepfile.name.split("-", 1)[1].split(".", 1)[0] number = xepfile.name.split("-", 1)[1].split(".", 1)[0]
try: try:
@ -167,6 +170,7 @@ def main():
except ValueError: except ValueError:
continue continue
try:
with xepfile.open("rb") as f: with xepfile.open("rb") as f:
parsed = open_xml(f) parsed = open_xml(f)
@ -175,10 +179,14 @@ def main():
extract_xep_metadata(parsed), extract_xep_metadata(parsed),
True, True,
)) ))
except Exception as exc:
has_error = True
print("{}: {}".format(xepfile, exc), file=sys.stderr)
for xepfile in (args.xepdir / "inbox").glob("*.xml"): for xepfile in (args.xepdir / "inbox").glob("*.xml"):
protoname = xepfile.name.rsplit(".", 1)[0] protoname = xepfile.name.rsplit(".", 1)[0]
try:
with xepfile.open("rb") as f: with xepfile.open("rb") as f:
parsed = open_xml(f) parsed = open_xml(f)
@ -188,6 +196,12 @@ def main():
False, False,
protoname=protoname protoname=protoname
)) ))
except Exception as exc:
has_error = True
print("{}: {}".format(xepfile, exc), file=sys.stderr)
if has_error:
sys.exit(2)
sys.stdout.buffer.raw.write(etree.tostring(tree)) sys.stdout.buffer.raw.write(etree.tostring(tree))