From ed7293b9e617529b20a1af14e04053a1a34d6cdc Mon Sep 17 00:00:00 2001 From: Ross Spencer Date: Fri, 21 Jun 2019 20:49:12 +0200 Subject: [PATCH] Ensure FILEID is updated in all places Custom file ids must be updated across the code. When a METS file is being updated, as an example, the existing FILEID should be read and passed back into the FSEntry constructor as required. The FSEntry __repr__ method has been updated to provide more comprehensive class debugging information when called. --- metsrw/__init__.py | 2 +- metsrw/fsentry.py | 3 ++- metsrw/mets.py | 6 ++++-- tests/test_mets.py | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/metsrw/__init__.py b/metsrw/__init__.py index 35ba950..10e03dc 100644 --- a/metsrw/__init__.py +++ b/metsrw/__init__.py @@ -43,7 +43,7 @@ LOGGER = logging.getLogger(__name__) LOGGER.addHandler(logging.NullHandler()) -__version__ = "0.3.9" +__version__ = "0.3.10" __all__ = [ "Agent", diff --git a/metsrw/fsentry.py b/metsrw/fsentry.py index 4ea82ba..6761a73 100644 --- a/metsrw/fsentry.py +++ b/metsrw/fsentry.py @@ -183,6 +183,7 @@ def dir(cls, label, children): def from_fptr(cls, label, type_, fptr): """Return ``FSEntry`` object.""" return FSEntry( + fileid=fptr.fileid, label=label, type=type_, path=fptr.path, @@ -197,7 +198,7 @@ def __str__(self): return "{s.type}: {s.path}".format(s=self) def __repr__(self): - return "FSEntry(type={s.type!r}, path={s.path!r}, use={s.use!r}, label={s.label!r}, file_uuid={s.file_uuid!r}, checksum={s.checksum!r}, checksumtype={s.checksumtype!r})".format( + return "FSEntry(type={s.type!r}, path={s.path!r}, use={s.use!r}, label={s.label!r}, file_uuid={s.file_uuid!r}, checksum={s.checksum!r}, checksumtype={s.checksumtype!r}, fileid={s._fileid!r})".format( s=self ) diff --git a/metsrw/mets.py b/metsrw/mets.py index 55236a6..48b6747 100755 --- a/metsrw/mets.py +++ b/metsrw/mets.py @@ -22,7 +22,7 @@ AIP_ENTRY_TYPE = "archival information package" FPtr = namedtuple( - "FPtr", "file_uuid derived_from use path amdids checksum checksumtype" + "FPtr", "file_uuid derived_from use path amdids checksum checksumtype fileid" ) @@ -455,7 +455,9 @@ def _analyze_fptr(fptr_elem, tree, entry_type): group_uuid = file_elem.get("GROUPID", "").replace(utils.GROUP_ID_PREFIX, "", 1) if group_uuid != file_uuid: derived_from = group_uuid # Use group_uuid as placeholder - return FPtr(file_uuid, derived_from, use, path, amdids, checksum, checksumtype) + return FPtr( + file_uuid, derived_from, use, path, amdids, checksum, checksumtype, file_id + ) @staticmethod def _add_dmdsecs_to_fs_entry(elem, fs_entry, tree): diff --git a/tests/test_mets.py b/tests/test_mets.py index 593f13d..a25e00d 100644 --- a/tests/test_mets.py +++ b/tests/test_mets.py @@ -323,6 +323,7 @@ def test_analyze_fptr(self): # Test the integrity of the ``FPtr`` object returned. fptr = mw._analyze_fptr(fptr_elem, tree, "directory") assert fptr == metsrw.mets.FPtr( + fileid="AM68.csv-fc0e52ca-a688-41c0-a10b-c1d36e21e804", file_uuid="fc0e52ca-a688-41c0-a10b-c1d36e21e804", derived_from=None, use="original",