artefactual-labs / mets-reader-writer

Library to parse and create METS files, especially for Archivematica.
https://mets-reader-writer.readthedocs.io
GNU Affero General Public License v3.0
20 stars 13 forks source link

Problem: Cannot generate EVENTS through member variables #43

Open ross-spencer opened 6 years ago

ross-spencer commented 6 years ago

Hi Joel,

Looking for clarification on how to write PREMIS events using this. If I try the following:

ev = premisrw.PREMISEvent()
ev.event_type = "AM CAMP DEMO"
ev.event_outcome_detail = "SUCCESS"
ev.event_outcome_detail_note = "dag iedereen!"
ev.linking_agent_identifier_type = "python script"
ev.linking_agent_identifier_value = "1.0"
print ev.generate_data

Then the default values for the object are output and no more:

<bound method PREMISEvent.generate_data of ('event', 
    {'xsi:schema_location': 'info:lc/xmlns/premis-v2 http://www.loc.gov/standards/premis/v2/premis-v2-2.xsd', 'version': '2.2'}, 
    ('event_identifier', ('event_identifier_type', 'UUID'), 
    ('event_identifier_value', 'aa4f20ef-678e-4b07-9bb6-0f875930ddaa')), 
    ('event_date_time', '2020-09-03T14:44:33'))>

I am currently only able to create an event object and output it to XML by creating a tuple using the technique outlined here.

I guess, am I missing something?

jrwdunham commented 6 years ago

Hey @ross-spencer,

Yeah, we haven't implemented PREMIS element creation via attribute setting yet. I guess that would mean implementing __setattr__. It would probably be a good idea to implement what you suggest, we just haven't done it yet.

For now, when creating a new PREMISElement (or subclass), you have to either supply the values on initialization or supply a single tuple to the data kwarg:

>>> ev = premisrw.PREMISEvent(
...     identifier_value='1665f868-dff5-4e66-8a32-f38ad7582309',
...     ...)
>>> ev = PREMISEvent(data=('event', {...}, (...)))

See