Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update create_dip.py to use PREMIS date #155

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 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,18 @@ 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")

# 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
Loading