Skip to content

Commit

Permalink
Standardise global state in create_mets_v2
Browse files Browse the repository at this point in the history
The `create_mets_v2` client script uses a bunch of global state for
things like counters and file IDs.  The original implementation could
rely on these globals being reset between runs (by virtue of running
the script in a new subprocess each time) but, after the batching
changes, this is no longer the case.

To make things more manageable, we pull all of this global stuff into
a single top-level object which gets replaced at the beginning of each
job run.  Where other modules call the functions of create_mets_v2,
they reset the global state as appropriate as well.

A secondary piece of shared state is the
`sharedVariablesAcrossModules` module, used by `create_mets_v2` and a
handful of other scripts.  Handling for this needed to be updated for
the batching changes in a small number of places.

Fixes archivematica/Issues#43 and archivematica/Issues#42
  • Loading branch information
marktriggs committed Jul 27, 2018
1 parent 1bd13b0 commit 2613575
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,14 @@ def add_new_files(job, mets, sip_uuid, sip_dir):
return mets

# Set global counters so getAMDSec will work
createmets2.globalAmdSecCounter = int(
mets.tree.xpath('count(mets:amdSec)', namespaces=ns.NSMAP))
createmets2.globalTechMDCounter = int(
mets.tree.xpath('count(mets:amdSec/mets:techMD)', namespaces=ns.NSMAP))
createmets2.globalDigiprovMDCounter = int(
mets.tree.xpath('count(mets:amdSec/mets:digiprovMD)',
namespaces=ns.NSMAP))
createmets2.initGlobalState(
globalAmdSecCounter=int(mets.tree.xpath('count(mets:amdSec)',
namespaces=ns.NSMAP)),
globalTechMDCounter=int(mets.tree.xpath('count(mets:amdSec/mets:techMD)',
namespaces=ns.NSMAP)),
globalDigiprovMDCounter=int(mets.tree.xpath('count(mets:amdSec/mets:digiprovMD)',
namespaces=ns.NSMAP))
)

objects_fsentry = mets.get_file(label='objects', type='Directory')

Expand Down
1 change: 1 addition & 0 deletions src/MCPClient/lib/clientScripts/create_aic_mets.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,6 @@ def call(jobs):
with transaction.atomic():
for job in jobs:
with job.JobContext():
create_mets_v2.initGlobalState()
args = parser.parse_args(job.qrgs[1:])
create_aic_mets(args.aic_uuid, args.aic_dir, job)
Loading

0 comments on commit 2613575

Please sign in to comment.