def archive_sip(sip_uuid): """Send the SIP for archiving. Retries every 4 hours, six times, which should work for up to 24 hours archiving system downtime. :param sip_uuid: UUID of the SIP for archiving. :type sip_uuid: str """ try: sip = SIPApi(SIP.query.get(sip_uuid)) archiver = BagItArchiver(sip) bagmeta = archiver.get_bagit_metadata(sip) if bagmeta is None: raise ArchivingError( 'Bagit metadata does not exist for SIP: {0}.'.format(sip.id)) if sip.archived: raise ArchivingError( 'SIP was already archived {0}.'.format(sip.id)) archiver.write_all_files() sip.archived = True db.session.commit() except Exception as exc: # On ArchivingError (see above), do not retry, but re-raise if not isinstance(exc, ArchivingError): archive_sip.retry(exc=exc) raise
def test_save_bagit_metadata(sips): """Test saving of bagit metadata.""" sip = sips[0] assert not BagItArchiver.get_bagit_metadata(sip) archiver = BagItArchiver(sip) archiver.save_bagit_metadata() bmeta = BagItArchiver.get_bagit_metadata(sip, as_dict=True) file_m = next(f for f in bmeta['files'] if 'sipfilepath' in f) assert file_m['sipfilepath'] == 'foobar.txt' assert file_m['filepath'] == 'data/files/foobar.txt' sip.model.sip_files[0].filepath = 'changed.txt' with pytest.raises(Exception) as excinfo: archiver.save_bagit_metadata() assert 'Attempting to save' in str(excinfo.value) archiver.save_bagit_metadata(overwrite=True) bmeta = BagItArchiver.get_bagit_metadata(sip, as_dict=True) file_m = next(f for f in bmeta['files'] if 'sipfilepath' in f) assert file_m['sipfilepath'] == 'changed.txt' assert file_m['filepath'] == 'data/files/changed.txt'