Skip to content

Commit

Permalink
OcrdMets.set_physical_page_for_file: fix cached case
Browse files Browse the repository at this point in the history
  • Loading branch information
bertsky authored and kba committed Apr 8, 2024
1 parent 76293a9 commit 0041ada
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/ocrd_models/ocrd_mets.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,19 +734,19 @@ def set_physical_page_for_file(self, pageId : str, ocrd_file : OcrdFile,
orderlabel (string): ``@ORDERLABEL`` to use
"""

# delete any page mapping for this file.ID
candidates = []
# delete any existing page mapping for this file.ID
fptrs = []
if self._cache_flag:
for page_id in self._fptr_cache.keys():
if ocrd_file.ID in self._fptr_cache[page_id].keys():
if self._fptr_cache[page_id][ocrd_file.ID] is not None:
candidates.append(self._fptr_cache[page_id][ocrd_file.ID])
fptrs.append(self._fptr_cache[page_id][ocrd_file.ID])
else:
candidates = self._tree.getroot().findall(
fptrs = self._tree.getroot().findall(
'mets:structMap[@TYPE="PHYSICAL"]/mets:div[@TYPE="physSequence"]/mets:div[@TYPE="page"]/mets:fptr[@FILEID="%s"]' %
ocrd_file.ID, namespaces=NS)

for el_fptr in candidates:
for el_fptr in fptrs:
if self._cache_flag:
del self._fptr_cache[el_fptr.getparent().get('ID')][ocrd_file.ID]
el_fptr.getparent().remove(el_fptr)
Expand Down Expand Up @@ -781,7 +781,7 @@ def set_physical_page_for_file(self, pageId : str, ocrd_file : OcrdFile,
self._page_cache[METS_PAGE_DIV_ATTRIBUTE.ID][pageId] = el_pagediv
# Create a new entry in the fptr cache and
# assign an empty dictionary to hold the fileids
self._fptr_cache[pageId] = {}
self._fptr_cache.setdefault(pageId, {})

el_fptr = ET.SubElement(el_pagediv, TAG_METS_FPTR)
el_fptr.set('FILEID', ocrd_file.ID)
Expand Down

0 comments on commit 0041ada

Please sign in to comment.