Skip to content

Commit

Permalink
[app][fix] mets:agent handling
Browse files Browse the repository at this point in the history
  • Loading branch information
M3ssman committed Jun 13, 2024
1 parent 5836d97 commit 65ef194
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 52 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "digiflow"
version = "3.11.0"
version = "3.11.1"
description = "Father's Little Digitization Workflow Helper"
readme = "README.md"
requires-python = ">=3.8"
Expand Down
33 changes: 22 additions & 11 deletions src/digiflow/digiflow_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,30 @@ def write(self, ext='.xml', out_dir=None, suffix=None) -> str:
class MetsProcessor(XMLProcessor):
"""Basic METS/MODS-Handling"""

def enrich_agent(self, note_msg):
"""Enrich agent information"""

mets_hdr = self.tree.find('.//mets:metsHdr', dfc.XMLNS)
agent_smith = ET.SubElement(mets_hdr,
'{http://www.loc.gov/METS/}agent',
{'TYPE': 'OTHER',
'ROLE': 'OTHER',
'OTHERTYPE': 'SOFTWARE'})
def enrich_agent(self, agent_name, agent_note=None, **kwargs):
"""Enrich agent information by name
at the proper Header position
optional set note/remark (per default current date)
and additional mets:agent attributes as kwargs =>
be sure to know how to do, since the schema is
rigorous concerning *both* attributes and values!
"""

mets_hdr: ET._Element = self.tree.find('.//mets:metsHdr', dfc.XMLNS)
next_agent_id = 0
for i, sub_el in enumerate(mets_hdr.getchildren(), 1):
if ET.QName(sub_el.tag).localname == 'agent':
next_agent_id = i
if kwargs is None or len(kwargs) == 0:
kwargs = {'TYPE': 'OTHER', 'ROLE': 'OTHER', 'OTHERTYPE': 'SOFTWARE'}
agent_smith = ET.Element('{http://www.loc.gov/METS/}agent', kwargs)
the_name = ET.SubElement(agent_smith, '{http://www.loc.gov/METS/}name')
the_name.text = note_msg
the_name.text = agent_name
the_note = ET.SubElement(agent_smith, '{http://www.loc.gov/METS/}note')
the_note.text = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
if agent_note is None:
agent_note = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
the_note.text = agent_note
mets_hdr.insert(next_agent_id, agent_smith)

def clear_agents(self, filter_by_attr, black_list):
"""
Expand Down
Loading

0 comments on commit 65ef194

Please sign in to comment.