Skip to content

Commit

Permalink
general cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
helrond committed Sep 15, 2016
1 parent 025bb78 commit d2adfc1
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 50 deletions.
44 changes: 36 additions & 8 deletions archivesspace/README.md
Expand Up @@ -41,24 +41,52 @@ 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
In the console or terminal, navigate to the directory containing the script you want and execute the script.
* 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
10 changes: 5 additions & 5 deletions archivesspace/advancedNoteEdit.py
Expand Up @@ -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))
Expand Down Expand Up @@ -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"]
Expand All @@ -78,15 +78,15 @@ 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]
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) + ' with no instances')
except:
pass

def replaceNotes(headers):
# Deletes AccessRestrict notes that match input notecontent
notes = ao["notes"]
Expand All @@ -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
Expand Down
14 changes: 4 additions & 10 deletions archivesspace/asExport-associatedMets.py
Expand Up @@ -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"]

Expand Down
16 changes: 5 additions & 11 deletions 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
Expand Down
14 changes: 4 additions & 10 deletions archivesspace/asExport-mets.py
Expand Up @@ -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()
Expand Down
10 changes: 4 additions & 6 deletions archivesspace/asNotes.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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"]
Expand All @@ -78,15 +76,15 @@ 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]
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) + ' with no instances')
except:
pass

#asks user to input note content
notecontent = raw_input('Enter accessrestrict note content: ')

Expand Down

0 comments on commit d2adfc1

Please sign in to comment.