Skip to content

Commit

Permalink
Ensure FILEID is updated in all places
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ross-spencer committed Jun 25, 2019
1 parent 9ab6410 commit ed7293b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion metsrw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

LOGGER = logging.getLogger(__name__)
LOGGER.addHandler(logging.NullHandler())
__version__ = "0.3.9"
__version__ = "0.3.10"

__all__ = [
"Agent",
Expand Down
3 changes: 2 additions & 1 deletion metsrw/fsentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
)

Expand Down
6 changes: 4 additions & 2 deletions metsrw/mets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)


Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions tests/test_mets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ed7293b

Please sign in to comment.