Skip to content

Instantly share code, notes, and snippets.

@djpillen
djpillen / resource_archival_object_ids.rb
Last active February 9, 2017 20:29
API endpoint to get the Archival Object IDs associated with an ArchivesSpace Resource
# Add this to a plugin's backend/controllers directory
class ArchivesSpaceService < Sinatra::Base
Endpoint.get('/repositories/:repo_id/resources/:id/archival_object_ids')
.description("Get a list of archival objects IDs associated with a resource")
.params(["id", :id],
["repo_id", :repo_id])
.permissions([:view_repository])
.returns([200, "OK"]) \
do
@djpillen
djpillen / add_enumeration_value.py
Last active August 14, 2018 17:49
Add new enumeration values to an ArchivesSpace enumeration
import json
import requests
username = "username"
password = "password"
aspace_url = "http://localhost:8089"
authenticate = requests.post("{}/users/{}/login?password={}".format(aspace_url, username, password)).json()
token = authenticate["session"]
headers = {"X-ArchivesSpace-Session":token}
from lxml import etree
import os
from os.path import join
ead_dir = "path/to/eads"
unsplit_lines = []
for filename in os.listdir("reelmapfiles"):
with open(join("reelmapfiles", filename), "r") as f:
unsplit_lines.extend(f.readlines())
@djpillen
djpillen / aspace_find_by_id.py
Last active June 1, 2016 17:19
ASpace find_by_id
import requests
import json
# Proof of concept update for https://github.com/djpillen/bentley_scripts/blob/master/update_archival_object.py using the new find_by_id endpoint
aspace_url = 'http://localhost:8089'
username= 'admin'
password = 'admin'
auth = requests.post("{0}/users/{1}/login?password={2}".format(aspace_url, username, password)).json()
@djpillen
djpillen / publish_agents.py
Last active March 18, 2016 19:52
Publish ASpace agents that are linked to a published record
import requests
import json
#Change these
aspace_url = 'http://localhost:8089'
username = 'admin'
password = 'admin'
auth = requests.post("{0}/users/{1}/login?password={2}".format(aspace_url, username, password)).json()
session = auth['session']
@djpillen
djpillen / archivesspace_defaults.py
Last active January 18, 2016 17:49
Setup BHL ArchivesSpace defaults for Archivagrant
import requests
import time
import json
# This script is used to setup BHL ArchivesSpace defaults for running test migrations
def test_connection():
try:
requests.get('http://localhost:8089')
print 'Connected!'
@djpillen
djpillen / setup_archivesspace_2.sh
Last active January 18, 2016 17:41
Setup ArchivesSpace for Archivagrant -- Part 2
# These will be used to edit the ArchivesSpace config file to use the correct database URL and setup our plugins
DBURL='AppConfig[:db_url] = "jdbc:mysql://localhost:3306/archivesspace?user=as\&password=as123\&useUnicode=true\&characterEncoding=UTF-8"'
PLUGINS="AppConfig[:plugins] = ['bhl-ead-importer','bhl-ead-exporter','container_management','aspace-jsonmodel-from-format']"
echo "Installing plugins"
cd /home/vagrant
echo "Installing container management"
# Grab a release instead of cloning the repo to make sure it's a version compatible with latest ArchivesSpace releases
wget https://github.com/hudmol/container_management/releases/download/1.1/container_management-1.1.zip
@djpillen
djpillen / reset_archivesspace.sh
Created January 18, 2016 17:03
Reset ArchivesSpace for Archivagrant
#!/usr/bin/env bash
echo "Stopping ArchivesSpace"
service archivesspace stop
echo "Dropping and recreating database"
mysql -uroot -prootpwd -e "drop database archivesspace"
mysql -uroot -prootpwd -e "create database archivesspace"
mysql -uroot -prootpwd -e "grant all on archivesspace.* to 'as'@'localhost' identified by 'as123'"
@djpillen
djpillen / download_latest_archivesspace.py
Last active January 18, 2016 17:23
Download latest version of ArchivesSpace for Archivagrant
import requests
import json
import os
from os.path import join
latest_release_api = 'https://api.github.com/repos/archivesspace/archivesspace/releases/latest'
save_dir = '/home/vagrant'
if not os.path.exists(save_dir):
@djpillen
djpillen / setup_archivesspace_1.sh
Last active January 18, 2016 17:40
Setup ArchivesSpace for Archivagrant -- Part 1
#!/usr/bin/env bash
echo "Installing dependencies"
apt-get -y install default-jre
apt-get -y install unzip
apt-get -y install git
cd /vagrant
echo "Downloading latest ArchivesSpace release"