From 035a9521f13eb7bc40917ea4602c81212e9e274a Mon Sep 17 00:00:00 2001 From: Klaus Thoden Date: Mon, 5 Mar 2018 17:00:41 +0100 Subject: [PATCH] Report fleshed out --- prepare_tei.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/prepare_tei.py b/prepare_tei.py index e5a424a..de51297 100644 --- a/prepare_tei.py +++ b/prepare_tei.py @@ -304,10 +304,42 @@ def fix_tei_header(xml_tree, bibfile_string): return xml_tree # def fix_tei_header ends here +def plural(num, noun): + """Return singular or plural form of noun, depending on num. + + Works only when a noun's plural is formed with 's'. """ + + if num == 1: + return noun + else: + return noun + "s" +# def plural ends here + def evaluate_report(report): """Print collection of not found items""" - print(report) + print("="*60) + print(' '*4, "Conversion report") + print("-"*60) + if len(report["bad_figures"]) > 0: + print("{} {} could not be linked to a file in the image directory:".format(len(report["bad_figures"]), plural(len(report["bad_figures"]), "figure"))) + for item in report["bad_figures"]: + print(' '*4, item) + else: + print("All figures were linked.") + if len(report["not_cited"]) > 0: + print("{} {} could not be found in the bibliography database:".format(len(report["not_cited"]), plural(len(report["not_cited"]), "citation"))) + for item in report["not_cited"]: + print(' '*4, item) + else: + print("All citekeys were found in the bibliography database.") + if len(report["bad_pageref"]) > 0: + print("{} page {} could not be parsed into start and end value:".format(len(report["bad_pageref"]), plural(len(report["bad_pageref"]), "reference"))) + for item in report["bad_pageref"]: + print(' '*4, item) + else: + print("All page references could be parsed into discrete values.") + print("="*60) # def evaluate_report ends here def main():