From d2adfc197df546c899be634e05e4e93f5ac56782 Mon Sep 17 00:00:00 2001 From: helrond Date: Thu, 15 Sep 2016 11:45:45 -0400 Subject: [PATCH] general cleanup --- archivesspace/README.md | 44 +++++++++++++++++++----- archivesspace/advancedNoteEdit.py | 10 +++--- archivesspace/asExport-associatedMets.py | 14 +++----- archivesspace/asExport-ead.py | 16 +++------ archivesspace/asExport-mets.py | 14 +++----- archivesspace/asNotes.py | 10 +++--- 6 files changed, 58 insertions(+), 50 deletions(-) diff --git a/archivesspace/README.md b/archivesspace/README.md index 199f7f8..aeeb676 100644 --- a/archivesspace/README.md +++ b/archivesspace/README.md @@ -41,6 +41,14 @@ Some of these scripts require a local configurations file, which should be creat # a list of resource IDs to publish publishIDs = ["FA001", "FA002","FA003"] + [Destinations] + # export destinations + dataDestination = /path/to/location + EADdestination = /path/to/location + METSdestination = /path/to/location + MODSdestination = /path/to/location + PDFdestination = /path/to/location + You can use the `config_settings.py` file found [here] (https://github.com/RockefellerArchiveCenter/templates/blob/master/config_setup.py) to automatically create a `local_settings.cfg` file. ##Usage @@ -48,17 +56,37 @@ In the console or terminal, navigate to the directory containing the script you * On Windows this will be something like `python asExport-ead.py` * On Mac or Linux systems you can simply type `./asExport-ead.py` -##asExport-ead.py +## asCSV-accessions.py + +Exports accessions data in a comma-separated file format. (Python) + +## asExport-associatedMets.py + +Exports METS files from digital object records associated with a given resource. (Python) + +## asExport-ead.py + Creates EAD files from resource records. Export can be scoped to specific records by using an optional argument to match against the resource ID. (Python) -##asExport-mets.py -Exports METS files from digital object records. (Python) +## asExport-mets.py -##asPublish.py -Compares resource record IDs against a list, then publishes those which are present and unpublishes those which are not. (Python) +Exports METS files from all digital object records. (Python) -##asCSV-accessions.py -Exports accessions data in a comma-separated file format. (Python) +## asNotes.py -##asNotes.py Matches accessrestrict notes to user-input text, checks every archival object in your ArchivesSpace database, deletes any accessrestrict notes with content exactly matching the user input content, and then posts the archival object back without the note. + +## asPublish.py + +Compares resource record IDs against a list, then publishes those which are present and unpublishes those which are not. (Python) + +## asReplaceContainers.py + +Loops over archival objects that are children of a given resource record and replaces container URIs for duplicate top containers. Relies on a comma-separated values (CSV) file named `containers.csv` with pairs of top container URIs, the second of which is a URI to replace, and the first of which is the URI with which the second should be replaced: + + /repositories/2/top_containers/15456,/repositories/2/top_containers/15457 + /repositories/2/top_containers/15461,/repositories/2/top_containers/15463 + /repositories/2/top_containers/15462,/repositories/2/top_containers/15451 + /repositories/2/top_containers/15454,/repositories/2/top_containers/15464 + /repositories/2/top_containers/15469,/repositories/2/top_containers/15477 + /repositories/2/top_containers/15478,/repositories/2/top_containers/15479 diff --git a/archivesspace/advancedNoteEdit.py b/archivesspace/advancedNoteEdit.py index 28d681f..1d938f5 100644 --- a/archivesspace/advancedNoteEdit.py +++ b/archivesspace/advancedNoteEdit.py @@ -3,7 +3,7 @@ import os, requests, json, sys, logging, ConfigParser, urllib2 config = ConfigParser.ConfigParser() -config.read('publish_local_settings.cfg') +config.read('local_settings.cfg') # Logging configuration logging.basicConfig(filename=config.get('Logging', 'filename'),format=config.get('Logging', 'format', 1), datefmt=config.get('Logging', 'datefmt', 1), level=config.get('Logging', 'level', 0)) @@ -68,7 +68,7 @@ def findBoxFolder(headers): boxfolder = u' '.join((ctypeone, cindicatorone)).encode('utf-8').strip() elif (ctypeone != 0 and cindicatorone != 0 and ctypetwo != 0 and cindicatortwo != 0): boxfolder = u' '.join((ctypeone, cindicatorone, ctypetwo, cindicatortwo)).encode('utf-8').strip() - + def deleteNotes(headers): # Deletes AccessRestrict notes that match input notecontent notes = ao["notes"] @@ -78,7 +78,7 @@ def deleteNotes(headers): for subnote in n["subnotes"]: if notecontent == subnote["content"] and boxfolder != []: del notes[index] - updated = requests.post(repositoryBaseURL + '/archival_objects/' + str(aoId), headers=headers, data=json.dumps(ao)) + updated = requests.post(repositoryBaseURL + '/archival_objects/' + str(aoId), headers=headers, data=json.dumps(ao)) logging.info('Deleted access restrict note with ' + str(notecontent) + ' content from archival object ' + str(aoId) + ' in resource ' + str(resourceID) + ' from ' + str(boxfolder)) elif notecontent == subnote["content"] and boxfolder == []: del notes[index] @@ -86,7 +86,7 @@ def deleteNotes(headers): logging.info('Deleted access restrict note with ' + str(notecontent) + ' content from archival object ' + str(aoId) + ' in resource ' + str(resourceID) + ' with no instances') except: pass - + def replaceNotes(headers): # Deletes AccessRestrict notes that match input notecontent notes = ao["notes"] @@ -96,7 +96,7 @@ def replaceNotes(headers): for subnote in n["subnotes"]: if notecontent == subnote["content"] and boxfolder != []: subnote["content"] = replacecontent - updated = requests.post(repositoryBaseURL + '/archival_objects/' + str(aoId), headers=headers, data=json.dumps(ao)) + updated = requests.post(repositoryBaseURL + '/archival_objects/' + str(aoId), headers=headers, data=json.dumps(ao)) logging.info('Replacing note with ' + str(notecontent) + ' content with ' + str(replacecontent) + ' content in archival object ' + str(aoId) + ' in resource ' + str(resourceID) + ' from ' + str(boxfolder)) elif notecontent == subnote["content"] and boxfolder == []: subnote["content"] = replacecontent diff --git a/archivesspace/asExport-associatedMets.py b/archivesspace/asExport-associatedMets.py index d412fce..8d08f00 100644 --- a/archivesspace/asExport-associatedMets.py +++ b/archivesspace/asExport-associatedMets.py @@ -4,16 +4,10 @@ import requests import json -# the base URL of your ArchivesSpace installation -baseURL = 'http://localhost:8089' -# the id of your repository -repository = 'repository' -# the username to authenticate with -user = 'username' -# the password for the username above -password = 'password' -# export destination -destination = '/path/to/location/' +config = ConfigParser.ConfigParser() +config.read('local_settings.cfg') +dictionary = {'baseURL': config.get('ArchivesSpace', 'baseURL'), 'repository':config.get('ArchivesSpace', 'repository'), 'user': config.get('ArchivesSpace', 'user'), 'password': config.get('ArchivesSpace', 'password'), 'destination': config.get('Destinations', 'METSdestination')} + #list of identifiers for resources whose digital objects you want to export resource_list = ["test123"] diff --git a/archivesspace/asExport-ead.py b/archivesspace/asExport-ead.py index c8eba98..73f648c 100755 --- a/archivesspace/asExport-ead.py +++ b/archivesspace/asExport-ead.py @@ -1,19 +1,13 @@ #!/usr/bin/env python -import os, requests, json, sys, logging +import os, requests, json, sys, logging, ConfigParser + +config = ConfigParser.ConfigParser() +config.read('local_settings.cfg') +dictionary = {'baseURL': config.get('ArchivesSpace', 'baseURL'), 'repository':config.get('ArchivesSpace', 'repository'), 'user': config.get('ArchivesSpace', 'user'), 'password': config.get('ArchivesSpace', 'password'), 'destination': config.get('Destinations', 'EADdestination')} -# the base URL of your ArchivesSpace installation -baseURL = 'http://localhost:8089' -# the id of your repository -repository = '2' -# the username to authenticate with -user = 'admin' -# the password for the username above -password = 'admin' # parses arguments, if any. This allows you to pass in an string to match against resource IDs exportIds = sys.argv[1] -# export destination -destination = '/home/harnold/test/' logging.basicConfig(filename='simple-log.txt',format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.DEBUG) # authenticates the session diff --git a/archivesspace/asExport-mets.py b/archivesspace/asExport-mets.py index d0708a9..4e8fe47 100755 --- a/archivesspace/asExport-mets.py +++ b/archivesspace/asExport-mets.py @@ -3,17 +3,11 @@ import os import requests import json +import ConfigParser -# the base URL of your ArchivesSpace installation -baseURL = 'http://localhost:8089' -# the id of your repository -repository = '2' -# the username to authenticate with -user = 'admin' -# the password for the username above -password = 'admin' -# export destination -destination = '/path/to/export/location/' +config = ConfigParser.ConfigParser() +config.read('local_settings.cfg') +dictionary = {'baseURL': config.get('ArchivesSpace', 'baseURL'), 'repository':config.get('ArchivesSpace', 'repository'), 'user': config.get('ArchivesSpace', 'user'), 'password': config.get('ArchivesSpace', 'password'), 'destination': config.get('Destinations', 'METSdestination')} # authenticates the session auth = requests.post(baseURL + '/users/'+user+'/login?password='+password).json() diff --git a/archivesspace/asNotes.py b/archivesspace/asNotes.py index 077ef02..0dcecae 100644 --- a/archivesspace/asNotes.py +++ b/archivesspace/asNotes.py @@ -3,14 +3,12 @@ import os, requests, json, sys, logging, ConfigParser, urllib2 config = ConfigParser.ConfigParser() -config.read('publish_local_settings.cfg') +config.read('local_settings.cfg') # Logging configuration logging.basicConfig(filename=config.get('Logging', 'filename'),format=config.get('Logging', 'format', 1), datefmt=config.get('Logging', 'datefmt', 1), level=config.get('Logging', 'level', 0)) # Sets logging of requests to WARNING to avoid unneccessary info logging.getLogger("requests").setLevel(logging.WARNING) -# Adds randomly generated commit message from external text file -#commitMessage = line = random.choice(open(config.get('Git', 'commitMessageData')).readlines()); dictionary = {'baseURL': config.get('ArchivesSpace', 'baseURL'), 'repository':config.get('ArchivesSpace', 'repository'), 'user': config.get('ArchivesSpace', 'user'), 'password': config.get('ArchivesSpace', 'password')} repositoryBaseURL = '{baseURL}/repositories/{repository}'.format(**dictionary) @@ -68,7 +66,7 @@ def findBoxFolder(headers): boxfolder = u' '.join((ctypeone, cindicatorone)).encode('utf-8').strip() elif (ctypeone != 0 and cindicatorone != 0 and ctypetwo != 0 and cindicatortwo != 0): boxfolder = u' '.join((ctypeone, cindicatorone, ctypetwo, cindicatortwo)).encode('utf-8').strip() - + def deleteAccessRestrict(headers): # Deletes AccessRestrict notes that match input notecontent notes = ao["notes"] @@ -78,7 +76,7 @@ def deleteAccessRestrict(headers): for subnote in n["subnotes"]: if notecontent == subnote["content"] and boxfolder != []: del notes[index] - updated = requests.post(repositoryBaseURL + '/archival_objects/' + str(aoId), headers=headers, data=json.dumps(ao)) + updated = requests.post(repositoryBaseURL + '/archival_objects/' + str(aoId), headers=headers, data=json.dumps(ao)) logging.info('Deleted access restrict note with ' + str(notecontent) + ' content from archival object ' + str(aoId) + ' in resource ' + str(resourceID) + ' from ' + str(boxfolder)) elif notecontent == subnote["content"] and boxfolder == []: del notes[index] @@ -86,7 +84,7 @@ def deleteAccessRestrict(headers): logging.info('Deleted access restrict note with ' + str(notecontent) + ' content from archival object ' + str(aoId) + ' in resource ' + str(resourceID) + ' with no instances') except: pass - + #asks user to input note content notecontent = raw_input('Enter accessrestrict note content: ')