Skip to content

Commit

Permalink
fix(ingest-xmlupload): apply mapping.csv even if extension has wrong …
Browse files Browse the repository at this point in the history
…casing (DEV-3197) (#749)
  • Loading branch information
jnussbaum committed Jan 19, 2024
1 parent bd915ef commit bac7c79
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
24 changes: 16 additions & 8 deletions src/dsp_tools/commands/ingest_xmlupload/apply_ingest_id.py
Expand Up @@ -56,13 +56,21 @@ def replace_filepath_with_sipi_id(
used_media_file_paths = []
new_tree = deepcopy(xml_tree)
for elem in new_tree.iter():
if etree.QName(elem).localname.endswith("bitstream") and elem.text:
img_path = Path(elem.text)
img_path_str = str(img_path.relative_to(Path.cwd())) if img_path.is_absolute() else str(img_path)
if img_path_str in orig_path_2_id_filename:
elem.text = orig_path_2_id_filename[img_path_str]
used_media_file_paths.append(img_path_str)
else:
no_id_found.append((cast("etree._Element", elem.getparent()).attrib["id"], str(elem.text)))
if not etree.QName(elem).localname.endswith("bitstream") or not elem.text:
continue
img_path = Path(elem.text)
img_path = img_path.relative_to(Path.cwd()) if img_path.is_absolute() else img_path
img_path_str = str(img_path)
if img_path_str not in orig_path_2_id_filename:
img_path_str = str(img_path.with_suffix(img_path.suffix.lower()))
if img_path_str not in orig_path_2_id_filename:
img_path_str = str(img_path.with_suffix(img_path.suffix.upper()))

if img_path_str in orig_path_2_id_filename:
elem.text = orig_path_2_id_filename[img_path_str]
used_media_file_paths.append(img_path_str)
else:
no_id_found.append((cast("etree._Element", elem.getparent()).attrib["id"], str(elem.text)))

unused_media_paths = [x for x in orig_path_2_id_filename if x not in used_media_file_paths]
return new_tree, IngestInformation(unused_mediafiles=unused_media_paths, mediafiles_no_id=no_id_found)
Expand Up @@ -33,7 +33,7 @@ def ok_msg(self) -> str | None:
if not self.unused_mediafiles and not self.mediafiles_no_id:
return (
"All multimedia files referenced in the XML file were uploaded through dsp-ingest.\n"
"No multimedia files were uploaded through dsp-ingest that were not referenced in the XML file."
"All multimedia files uploaded through dsp-ingest were referenced in the XML file."
)
return None

Expand Down
Expand Up @@ -10,7 +10,7 @@ class TestIngestInformation:
def test_no_problems(self) -> None:
expected = (
"All multimedia files referenced in the XML file were uploaded through dsp-ingest.\n"
"No multimedia files were uploaded through dsp-ingest that were not referenced in the XML file."
"All multimedia files uploaded through dsp-ingest were referenced in the XML file."
)
assert IngestInformation([], []).ok_msg() == expected

Expand Down

0 comments on commit bac7c79

Please sign in to comment.