Skip to content

Commit

Permalink
Use PREMIS dateCreatedByApplication in create_dip
Browse files Browse the repository at this point in the history
Set the modified date for files based on the PREMIS element
dateCreatedByApplication rather than the FITS element fslastmodified.
  • Loading branch information
ehanson8 authored Aug 6, 2024
1 parent 4f73fa3 commit 4ca4c22
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions aips/create_dip.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import subprocess
import sys
import uuid
from datetime import datetime

import amclient
import metsrw
Expand Down Expand Up @@ -259,9 +260,9 @@ def create_dip(aip_dir, aip_uuid, output_dir, mets_type, dip_type):

if dip_type != "avalon-manifest":
try:
set_fslastmodified(premis, namespaces, dip_file_path)
set_datecreatedbyapplication(premis, namespaces, dip_file_path)
except Exception:
LOGGER.warning("fits/fileinfo/fslastmodified not found")
LOGGER.warning("creatingApplication/dateCreatedByApplication not found")

# Modify or copy METS file for DIP based on mets_type argument
dip_mets_file = os.path.join(dip_dir, f"METS.{aip_uuid}.xml")
Expand Down Expand Up @@ -359,18 +360,19 @@ def move_sub_doc(aip_dir, to_zip_dir):
LOGGER.warning("submissionDocumentation folder not found")


def set_fslastmodified(premis, namespaces, dip_file_path):
"""Obtain and set the fslastmodified date to the moved files"""

fslastmodified = premis.findtext(
"premis:objectCharacteristics/premis:objectCharacteristicsExtension/fits:fits/fits:fileinfo/fits:fslastmodified",
def set_datecreatedbyapplication(premis, namespaces, dip_file_path):
"""Obtain and set the datecreatedbyapplication date to the moved files"""
datecreatedbyapplication = premis.findtext(
"premis:objectCharacteristics/premis:creatingApplication/premis:dateCreatedByApplication",
namespaces=namespaces,
)
if not fslastmodified:
LOGGER.warning("fits/fileinfo/fslastmodified not found")
if not datecreatedbyapplication:
LOGGER.warning("creatingApplication/dateCreatedByApplication not found")
return

# Convert from miliseconds to seconds
timestamp = int(fslastmodified) // 1000
timestamp = datetime.strptime(
datecreatedbyapplication, "%Y-%m-%dT%H:%M:%SZ"
).timestamp()
os.utime(dip_file_path, (timestamp, timestamp))


Expand Down

0 comments on commit 4ca4c22

Please sign in to comment.