Skip to content

Commit

Permalink
MCPClient: verify_aip: refactor for Pythonicity
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwdunham committed Mar 26, 2018
1 parent 9d42b3a commit 9451abf
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
import shutil
import sys

import django
django.setup()
from django.conf import settings as mcpclient_settings

# archivematicaCommon
from archivematicaFunctions import get_setting
from custom_handlers import get_script_logger
Expand Down Expand Up @@ -169,15 +165,14 @@ def verify_checksums(bag, sip_uuid):
verification_count += 1
except VerifyChecksumsError as err:
print(err)
return 1
raise
event_outcome_detail_note = (
'All {verification_count} checksums generated at start of transfer'
' match those generated by BagIt (bag).'.format(
verification_count=verification_count))
write_premis_event(sip_uuid, checksum_type, 'Pass',
event_outcome_detail_note)
print(event_outcome_detail_note)
return 0


def verify_aip():
Expand Down Expand Up @@ -227,18 +222,30 @@ def verify_aip():
return_code = 1

if return_code == 0:
return_code = verify_checksums(bag, sip_uuid)
try:
verify_checksums(bag, sip_uuid)
except VerifyChecksumsError:
return_code = 1
else:
print('Not verifying checksums because other tests have already'
' failed.')

# cleanup
if not is_uncompressed_aip:
shutil.rmtree(extract_dir)
try:
shutil.rmtree(extract_dir)
except OSError as err:
print('Failed to remove temporary directory at {extract_dir} which'
' contains the AIP extracted for verification.'
' Error:\n{err}'.format(extract_dir=extract_dir, err=err),
file=sys.stderr)

return return_code


if __name__ == '__main__':
import django
django.setup()
from django.conf import settings as mcpclient_settings
logger = get_script_logger("archivematica.mcp.client.verifyAIP")

sys.exit(verify_aip())

0 comments on commit 9451abf

Please sign in to comment.