-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheck_enumerations.py
208 lines (175 loc) · 9.67 KB
/
check_enumerations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# This script checks a standard list of controlled vocabularly lists and updates ArchivesSpace by deleting or merging
# values
from asnake.client import ASnakeClient
import logging
from secrets import *
logging.basicConfig(filename="AS_enums.log", level=logging.INFO)
as_username = input("Enter your ArchivesSpace username: ")
as_password = input("Enter your ArchivesSpace password: ")
client = ASnakeClient(baseurl=as_api, username=as_username, password=as_password)
client.authorize()
need_to_delete_extents = ["copies", "linear_foot"]
extent_types = ["gigabyte(s)", "linear_feet", "box(es)", "item(s)", "volume(s)", "moving_image(s)", "folder(s)",
"sound_recording(s)", "interview(s)", "photograph(s)", "oversize_folders", "interview", "photographs",
"item", "minutes", "unknown", "pages", "linear_foot", "copies"]
container_types = ["box", "folder", "oversized_box", "oversized_folder", "reel", "roll", "portfolio", "item", "volume",
"physdesc", "electronic_records", "carton", "drawer", "cassette", "rr", "cs"]
instance_types = ["artifacts", "audio", "books", "digital_object", "graphic_materials", "maps", "microform",
"mixed_materials", "moving_images", "electronic_records"]
do_types = ["cartographic", "mixed_materials", "moving_image", "software_multimedia", "sound_recording", "still_image",
"text"]
accession_res_types = ["collection", "papers", "records"]
subject_sources = ["aat", "lcsh", "local", "lcnaf"]
name_sources = ["local", "naf", "ingest"]
fa_status_terms = ["completed", "unprocessed", "in_process", "problem"]
def update_extents():
new_extents = client.get("/config/enumerations/14").json()
new_extents["values"] = []
new_extents["enumeration_values"] = []
aspace_extent_type = client.get("/config/enumerations/14").json()
for extent in aspace_extent_type["enumeration_values"]:
if extent["value"] in extent_types:
print("{}".format(extent["value"]))
new_extents["enumeration_values"].append(extent)
new_extents["values"].append(extent["value"])
update = client.post("/config/enumerations/14", json=new_extents)
print(update.json())
if 'error' in update.json():
logging.error("Extents error: {}".format(update.json()))
merge_extents = merge_enums("/config/enumerations/14", "item", "item(s)")
print(merge_extents)
logging.info("Merging Extents results: {}".format(merge_extents))
def update_containers():
new_container = client.get("/config/enumerations/16").json()
new_container["values"] = []
new_container["enumeration_values"] = []
aspace_container_type = client.get("/config/enumerations/16").json()
for container in aspace_container_type["enumeration_values"]:
if container["value"] in container_types:
print("{}".format(container["value"]))
new_container["enumeration_values"].append(container)
new_container["values"].append(container["value"])
update = client.post("/config/enumerations/16", json=new_container)
print(update.json())
if 'error' in update.json():
logging.error("Containers error: {}".format(update.json()))
merge_containers = merge_enums("/config/enumerations/16", "unknown_item", "item")
print(merge_containers)
logging.info("Merging Container types: {}".format(merge_containers))
def update_instances():
new_instances = client.get("/config/enumerations/22").json()
new_instances["values"] = []
new_instances["enumeration_values"] = []
aspace_instance_type = client.get("/config/enumerations/22").json()
for instance in aspace_instance_type["enumeration_values"]:
if instance["value"] in instance_types:
print("{}".format(instance["value"]))
new_instances["enumeration_values"].append(instance)
new_instances["values"].append(instance["value"])
update = client.post("/config/enumerations/22", json=new_instances)
print(update.json())
if 'error' in update.json():
logging.error("Instances error: {}".format(update.json()))
merge_instance_values = [{"mixed_materials": ["box_oversize", "box", "folder", "item", "page", "text",
"oversize_box", "bankers_box", "folder_oversize", "volume"]},
{"microform": ["reel", "cartridge"]},
{"artifacts": ["artifact"]},
{"moving_images": ["moving_image"]}]
for merge in merge_instance_values:
for to_value, from_values in merge.items():
for from_value in from_values:
merge_instance_types = merge_enums("/config/enumerations/22", from_value, to_value)
print(merge_instance_types)
logging.info("Merging Instance types: {}".format(merge_instance_types))
def update_acc_res_types():
new_acc_res_types = client.get("/config/enumerations/7").json()
new_acc_res_types["values"] = []
new_acc_res_types["enumeration_values"] = []
aspace_acc_res_type = client.get("/config/enumerations/7").json()
for acc_res_type in aspace_acc_res_type["enumeration_values"]:
if acc_res_type["value"] in accession_res_types:
print(acc_res_type["value"])
new_acc_res_types["enumeration_values"].append(acc_res_type)
new_acc_res_types["values"].append(acc_res_type["value"])
update = client.post("/config/enumerations/7", json=new_acc_res_types)
print(update.json())
if 'error' in update.json():
logging.error("Accession Resorce Type error: {}".format(update.json()))
def update_digital_objects():
new_digital_object_types = client.get("/config/enumerations/12").json()
new_digital_object_types["values"] = []
new_digital_object_types["enumeration_values"] = []
aspace_digital_object_types = client.get("/config/enumerations/12").json()
for dig_obj_type in aspace_digital_object_types["enumeration_values"]:
if dig_obj_type["value"] in do_types:
print(dig_obj_type["value"])
new_digital_object_types["enumeration_values"].append(dig_obj_type)
new_digital_object_types["values"].append(dig_obj_type["value"])
update = client.post("/config/enumerations/7", json=new_digital_object_types)
print(update.json())
if 'error' in update.json():
logging.error("Digital Object Types error: {}".format(update.json()))
def update_subject_sources():
new_subject_sources = client.get("/config/enumerations/23").json()
new_subject_sources["values"] = []
new_subject_sources["enumeration_values"] = []
aspace_subject_sources = client.get("/config/enumerations/23").json()
for subject_source in aspace_subject_sources["enumeration_values"]:
if subject_source["value"] in subject_sources:
print(subject_source["value"])
new_subject_sources["enumeration_values"].append(subject_source)
new_subject_sources["values"].append(subject_source["value"])
update = client.post("/config/enumerations/23", json=new_subject_sources)
print(update.json())
if 'error' in update.json():
logging.error("Subject Sources error: {}".format(update.json()))
merge_ss = merge_enums("/config/enumerations/23", "ingest", "local")
print(merge_ss)
logging.info(merge_ss)
def update_name_sources():
new_name_sources = client.get("/config/enumerations/4").json()
new_name_sources["values"] = []
new_name_sources["enumeration_values"] = []
aspace_name_sources = client.get("/config/enumerations/4").json()
for name_source in aspace_name_sources["enumeration_values"]:
if name_source["value"] in name_sources:
print(name_source["value"])
new_name_sources["enumeration_values"].append(name_source)
new_name_sources["values"].append(name_source["value"])
update = client.post("/config/enumerations/4", json=new_name_sources)
print(update.json())
if 'error' in update.json():
logging.error("Name Sources error: {}".format(update.json()))
merge_ns1 = merge_enums("/config/enumerations/4", "library_of_congress_subject_headings", "naf")
merge_ns2 = merge_enums("/config/enumerations/4", "mediadonor", "local")
merge_ns3 = merge_enums("/config/enumerations/4", "digital_library_of_georgia_name_database", "local")
print(merge_ns1, merge_ns2, merge_ns3)
logging.info("Merging Name Sources: {}, {}, {}".format(merge_ns1, merge_ns2, merge_ns3))
def update_fa_status_terms():
new_fa_status_terms = client.get("/config/enumerations/21").json()
new_fa_status_terms["values"] = []
new_fa_status_terms["enumeration_values"] = []
aspace_fa_status_terms = client.get("/config/enumerations/21").json()
for fa_status_term in aspace_fa_status_terms["enumeration_values"]:
if fa_status_term["value"] in fa_status_terms:
print(fa_status_term["value"])
new_fa_status_terms["enumeration_values"].append(fa_status_term)
new_fa_status_terms["values"].append(fa_status_term["value"])
update = client.post("/config/enumerations/21", json=new_fa_status_terms)
print(update.json())
if 'error' in update.json():
logging.error("Finding Aid Status Terms error: {}".format(update.json()))
def merge_enums(enum_uri, from_val, to_val):
merge_json = {"enum_uri": enum_uri, "from": from_val, "to": to_val}
merge_instance = client.post("/config/enumerations/migration", json=merge_json)
return merge_instance.json()
def run_update_suite():
update_extents()
update_containers()
update_instances()
update_acc_res_types()
update_digital_objects()
update_subject_sources()
update_name_sources()
update_fa_status_terms()
run_update_suite()