Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Checking for existing references can be disabled
  • Loading branch information
kthoden committed Jul 18, 2019
1 parent f0f2805 commit c0f3e4c
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions tei2imxml.py
Expand Up @@ -850,7 +850,7 @@ def assign_ids(xml_tree, data):
return xml_tree, data
# def assign_ids ends here

def update_ids(xml_tree):
def update_ids(xml_tree, ignore_ref_errors):
"""Update the references in EOAref to the id value assigned in assign_ids"""

xmlReferences = xml_tree.findall(".//EOAref")
Expand All @@ -870,16 +870,22 @@ def update_ids(xml_tree):
logging.debug("The corresponding id element is %s", corresponding_eoa_id_element)
# if corresponding_eoa_id_element is None:
if len(corresponding_eoa_id_element) == 0:
logging.error("There seems to be no corresponding xml:id for %s. Exiting." % label_text)
sys.exit(1)
if ignore_ref_errors:
logging.warning(f"Found no corresponding xml:id for {label_text}. Ignoring it for now.")
eoa_reference.set("target", "??")
else:
logging.error("There seems to be no corresponding xml:id for %s. Exiting." % label_text)
sys.exit(1)
elif len(corresponding_eoa_id_element) > 1:
logging.error("The xml:id %s has been assigned more than once. This is not allowed. Exiting." % corresponding_eoa_id_element)
sys.exit(1)
if ignore_ref_errors:
pass
else:
logging.error("The xml:id %s has been assigned more than once. This is not allowed. Exiting." % corresponding_eoa_id_element)
sys.exit(1)
else:
eoa_id_element = corresponding_eoa_id_element[0]

eoa_id = eoa_id_element.get("id")
eoa_reference.set("target", eoa_id)
eoa_id = eoa_id_element.get("id")
eoa_reference.set("target", eoa_id)

return xml_tree
# def update_ids ends here
Expand Down Expand Up @@ -962,7 +968,7 @@ def convert_bibliography_to_dict(bib_data):
bibliography_dict = btb.entries_dict

return bibliography_dict
# deef convert_bibliography_to_dict ends here
# def convert_bibliography_to_dict ends here


def make_bibliography_pandoc(used_citekeys, bib_data, citations_json, output_file_root, CSL_FILE):
Expand Down Expand Up @@ -1145,14 +1151,18 @@ def main():
default = "./output/imxml",
help="where to dump all output files"
)
parser.add_argument(
"-i", "--ignore-ref-errors",
action="store_true",
help="Ignore warnings of missing or duplicate ids."
)

parser.add_argument("-d", "--pickleddata", default="./output/imxml/tmp_files/data.pickle", help="Pickled data file to be used.")
parser.add_argument("-him", "--hyperimage", action="store_true")
args = parser.parse_args()
config_file = args.CONFIG_FILE
print("The config file is ", config_file)


INPUT_DIR = Path( args.filename ).resolve().parent
INPUT_PATH = Path( args.filename )
OUTPUT_DIR = Path( args.output_dir )
Expand Down Expand Up @@ -1254,7 +1264,7 @@ def main():

assigned_ids, data_to_pickle = assign_ids(xml_add_bib, data)

updated_xml_tree = update_ids(assigned_ids)
updated_xml_tree = update_ids(assigned_ids, args.ignore_ref_errors)
# libeoaconvert.debug_xml_here(updated_xml_tree, "updated_tree")
# nearly_final_tree = etree.ElementTree(updated_xml_tree)
# xml_root = nearly_final_tree.getroot()
Expand Down

0 comments on commit c0f3e4c

Please sign in to comment.