caltechdata-api 1.10.5__tar.gz → 1.11.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/PKG-INFO +11 -5
  2. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/caltechdata_api/caltechdata_edit.py +28 -12
  3. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/caltechdata_api/caltechdata_write.py +14 -9
  4. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/caltechdata_api/cli.py +10 -20
  5. caltechdata_api-1.11.0/caltechdata_api/vocabularies/date_types.yaml +55 -0
  6. caltechdata_api-1.11.0/caltechdata_api/vocabularies/description_types.yaml +34 -0
  7. caltechdata_api-1.11.0/caltechdata_api/vocabularies/identifier_types.yaml +110 -0
  8. caltechdata_api-1.11.0/caltechdata_api/vocabularies/licenses.csv +419 -0
  9. caltechdata_api-1.11.0/caltechdata_api/vocabularies/relation_types.yaml +155 -0
  10. caltechdata_api-1.11.0/caltechdata_api/vocabularies/resource_types.yaml +675 -0
  11. caltechdata_api-1.11.0/caltechdata_api/vocabularies/roles.yaml +105 -0
  12. caltechdata_api-1.11.0/caltechdata_api/vocabularies/title_types.yaml +20 -0
  13. caltechdata_api-1.11.0/caltechdata_api/vocabularies.yaml +24 -0
  14. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/caltechdata_api.egg-info/PKG-INFO +12 -6
  15. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/caltechdata_api.egg-info/SOURCES.txt +13 -1
  16. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/caltechdata_api.egg-info/entry_points.txt +0 -1
  17. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/caltechdata_api.egg-info/requires.txt +1 -0
  18. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/setup.cfg +2 -1
  19. caltechdata_api-1.11.0/tests/test_download.py +27 -0
  20. caltechdata_api-1.11.0/tests/test_rdm.py +95 -0
  21. caltechdata_api-1.11.0/tests/test_unit.py +166 -0
  22. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/LICENSE +0 -0
  23. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/README.md +0 -0
  24. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/caltechdata_api/__init__.py +0 -0
  25. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/caltechdata_api/customize_schema.py +0 -0
  26. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/caltechdata_api/download_file.py +0 -0
  27. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/caltechdata_api/get_files.py +0 -0
  28. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/caltechdata_api/get_metadata.py +0 -0
  29. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/caltechdata_api/md_to_json.py +0 -0
  30. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/caltechdata_api/utils.py +0 -0
  31. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/caltechdata_api.egg-info/dependency_links.txt +0 -0
  32. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/caltechdata_api.egg-info/top_level.txt +0 -0
  33. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/pyproject.toml +0 -0
  34. {caltechdata_api-1.10.5 → caltechdata_api-1.11.0}/setup.py +0 -0
@@ -1,12 +1,11 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: caltechdata_api
3
- Version: 1.10.5
3
+ Version: 1.11.0
4
4
  Summary: Python wrapper for CaltechDATA API.
5
5
  Home-page: https://github.com/caltechlibrary/caltechdata_api
6
6
  Author: Thomas E Morrell, Rohan Bhattarai, Elizabeth Won, Alexander A Abakah, Kshemaahna Nagi
7
7
  Author-email: tmorrell@caltech.edu, aabakah@caltech.edu, knagi@caltech.edu
8
8
  License: MIT
9
- Platform: UNKNOWN
10
9
  Classifier: License :: OSI Approved :: MIT License
11
10
  Classifier: Programming Language :: Python :: 3
12
11
  Classifier: Programming Language :: Python :: 3.7
@@ -18,6 +17,15 @@ Classifier: Operating System :: OS Independent
18
17
  Requires-Python: >=3.6.0
19
18
  Description-Content-Type: text/markdown
20
19
  License-File: LICENSE
20
+ Requires-Dist: requests
21
+ Requires-Dist: datacite>1.1.0
22
+ Requires-Dist: tqdm>=4.62.3
23
+ Requires-Dist: pyyaml
24
+ Requires-Dist: s3fs
25
+ Requires-Dist: cryptography
26
+ Requires-Dist: s3cmd
27
+ Requires-Dist: jsonschema-specifications
28
+ Dynamic: license-file
21
29
 
22
30
  # CaltechDATA API Python Library
23
31
 
@@ -101,5 +109,3 @@ repository will generate junk records that are annoying to delete.
101
109
  ## Using the Command Line Interface
102
110
 
103
111
  If you would like to interact with the CaltechDATA API using the Command line Interface (CLI), please [see the detailed documentation](https://caltechlibrary.github.io/caltechdata_api/caltechdata_api/cli-documentation-for-users).
104
-
105
-
@@ -1,4 +1,4 @@
1
- import copy, os, json
1
+ import copy, os, json, time
2
2
 
3
3
  import requests
4
4
  from requests import session
@@ -193,7 +193,14 @@ def caltechdata_edit(
193
193
  headers=headers,
194
194
  )
195
195
  if existing.status_code != 200:
196
- raise Exception(f"Record {idv} does not exist, cannot edit")
196
+ # Try back again to the record
197
+ existing = requests.get(
198
+ url + "/api/records/" + idv,
199
+ headers=headers,
200
+ )
201
+
202
+ if existing.status_code != 200:
203
+ raise Exception(f"Record {idv} does not exist, cannot edit")
197
204
 
198
205
  existing = existing.json()
199
206
  status = existing["status"]
@@ -326,17 +333,16 @@ def caltechdata_edit(
326
333
  # We make a draft
327
334
  result = requests.post(
328
335
  url + "/api/records/" + idv + "/draft",
329
- json=data,
330
336
  headers=headers,
331
337
  )
332
338
  if result.status_code != 201:
333
- raise Exception(result.text)
334
- result = requests.get(
335
- url + "/api/records/" + idv,
336
- headers=headers,
337
- )
338
- if result.status_code != 200:
339
- raise Exception(result.text)
339
+ time.sleep(3)
340
+ result = requests.post(
341
+ url + "/api/records/" + idv + "/draft",
342
+ headers=headers,
343
+ )
344
+ if result.status_code != 201:
345
+ raise Exception(result.text)
340
346
  # We want files to stay the same as the existing record
341
347
  data["files"] = existing["files"]
342
348
  if default_preview:
@@ -348,13 +354,23 @@ def caltechdata_edit(
348
354
  json=data,
349
355
  )
350
356
  if result.status_code != 200:
351
- raise Exception(result.text)
357
+ time.sleep(3)
358
+ result = requests.put(
359
+ url + "/api/records/" + idv + "/draft",
360
+ headers=headers,
361
+ json=data,
362
+ )
363
+ if result.status_code != 200:
364
+ raise Exception(result.text)
352
365
 
353
366
  if publish:
354
367
  publish_link = f"{url}/api/records/{idv}/draft/actions/publish"
355
368
  result = requests.post(publish_link, headers=headers)
356
369
  if result.status_code != 202:
357
- raise Exception(result.text)
370
+ time.sleep(3)
371
+ result = requests.post(publish_link, headers=headers)
372
+ if result.status_code != 202:
373
+ raise Exception(result.text)
358
374
  if return_id:
359
375
  return result.json()["id"]
360
376
  else:
@@ -132,16 +132,21 @@ def send_to_community(
132
132
  if result.status_code != 202:
133
133
  raise Exception(result.text)
134
134
  if publish:
135
- accept_link = result.json()["links"]["actions"]["accept"]
136
- data = comment = {
137
- "payload": {
138
- "content": "This record is accepted automatically with the CaltechDATA API",
139
- "format": "html",
135
+ if "accept" in result.json()["links"]["actions"]:
136
+ accept_link = result.json()["links"]["actions"]["accept"]
137
+ data = comment = {
138
+ "payload": {
139
+ "content": "This record is accepted automatically with the CaltechDATA API",
140
+ "format": "html",
141
+ }
140
142
  }
141
- }
142
- result = requests.post(accept_link, json=data, headers=headers, verify=verify)
143
- if result.status_code != 200:
144
- raise Exception(result.text)
143
+ result = requests.post(
144
+ accept_link, json=data, headers=headers, verify=verify
145
+ )
146
+ if result.status_code != 200:
147
+ raise Exception(result.text)
148
+ # Otherwise we have direct publish permissions and don't need to acccept
149
+ # the request
145
150
  return result
146
151
 
147
152
 
@@ -173,11 +173,9 @@ def get_funding_details():
173
173
  award_number = get_user_input("Enter the award number for funding: ")
174
174
  award_exists = check_award_number(award_number)
175
175
  if not award_exists:
176
- print(
177
- f"""Error: No award with number '{award_number}' found in
176
+ print(f"""Error: No award with number '{award_number}' found in
178
177
  CaltechDATA. You will need to provide more details about the
179
- funding."""
180
- )
178
+ funding.""")
181
179
  award_title = get_user_input("Enter the award title for funding: ")
182
180
  while True:
183
181
  funder_identifier = get_user_input("Enter the funder ROR (https://ror.org): ")
@@ -185,11 +183,9 @@ def get_funding_details():
185
183
  if name:
186
184
  break
187
185
  else:
188
- print(
189
- """This funder identifier is not a ROR. Please enter a valid
186
+ print("""This funder identifier is not a ROR. Please enter a valid
190
187
  ROR identifier (without the url). For example the ROR for the
191
- NSF is 021nxhr62."""
192
- )
188
+ NSF is 021nxhr62.""")
193
189
  print("-" * 10)
194
190
  return {
195
191
  "awardNumber": award_number,
@@ -349,14 +345,12 @@ def write_s3cmd_config(endpoint):
349
345
  access_key = get_user_input("Enter the access key: ")
350
346
  secret_key = get_user_input("Enter the secret key: ")
351
347
  with open(configf, "w") as file:
352
- file.write(
353
- f"""[default]
348
+ file.write(f"""[default]
354
349
  access_key = {access_key}
355
350
  host_base = {endpoint}
356
351
  host_bucket = %(bucket).{endpoint}
357
352
  secret_key = {secret_key}
358
- """
359
- )
353
+ """)
360
354
 
361
355
 
362
356
  def upload_supporting_file(record_id=None):
@@ -431,11 +425,9 @@ def upload_supporting_file(record_id=None):
431
425
  elif filename in files:
432
426
  file_size = os.path.getsize(filename)
433
427
  if file_size > 1024 * 1024 * 1024:
434
- print(
435
- """The file is greater than 1 GB. Please upload the
428
+ print("""The file is greater than 1 GB. Please upload the
436
429
  metadata to CaltechDATA, and you'll be provided
437
- instructions to upload the files to S3 directly."""
438
- )
430
+ instructions to upload the files to S3 directly.""")
439
431
  else:
440
432
  filepath = os.path.abspath(filename)
441
433
  filepaths.append(filepath)
@@ -643,12 +635,10 @@ def print_upload_message(rec_id, production):
643
635
  if production
644
636
  else "https://data.caltechlibrary.dev/uploads/"
645
637
  )
646
- print(
647
- f"""You can view and publish this record at
638
+ print(f"""You can view and publish this record at
648
639
  {base_url}{rec_id}
649
640
  If you need to upload large files to S3, you can type
650
- `s3cmd put DATA_FILE s3://ini230004-bucket01/{rec_id}/`"""
651
- )
641
+ `s3cmd put DATA_FILE s3://ini230004-bucket01/{rec_id}/`""")
652
642
 
653
643
 
654
644
  def edit_record(production):
@@ -0,0 +1,55 @@
1
+ - id: accepted
2
+ props:
3
+ datacite: Accepted
4
+ title:
5
+ en: Accepted
6
+ - id: available
7
+ props:
8
+ datacite: Available
9
+ title:
10
+ en: Available
11
+ - id: collected
12
+ props:
13
+ datacite: Collected
14
+ title:
15
+ en: Collected
16
+ - id: copyrighted
17
+ props:
18
+ datacite: Copyrighted
19
+ title:
20
+ en: Copyrighted
21
+ - id: created
22
+ props:
23
+ datacite: Created
24
+ title:
25
+ en: Created
26
+ - id: issued
27
+ props:
28
+ datacite: Issued
29
+ title:
30
+ en: Issued
31
+ - id: other
32
+ props:
33
+ datacite: Other
34
+ title:
35
+ en: Other
36
+ - id: submitted
37
+ props:
38
+ datacite: Submitted
39
+ title:
40
+ en: Submitted
41
+ - id: updated
42
+ props:
43
+ datacite: Updated
44
+ title:
45
+ en: Updated
46
+ - id: valid
47
+ props:
48
+ datacite: Valid
49
+ title:
50
+ en: Valid
51
+ - id: withdrawn
52
+ props:
53
+ datacite: Withdrawn
54
+ title:
55
+ en: Withdrawn
@@ -0,0 +1,34 @@
1
+ - id: abstract
2
+ props:
3
+ datacite: Abstract
4
+ title:
5
+ en: Abstract
6
+ - id: methods
7
+ props:
8
+ datacite: Methods
9
+ title:
10
+ en: Methods
11
+ - id: series-information
12
+ props:
13
+ datacite: SeriesInformation
14
+ title:
15
+ en: Series information
16
+ - id: table-of-contents
17
+ props:
18
+ datacite: TableOfContents
19
+ title:
20
+ en: Table of contents
21
+ - id: technical-info
22
+ props:
23
+ datacite: TechnicalInfo
24
+ title:
25
+ en: Technical info
26
+ - id: other
27
+ props:
28
+ datacite: Other
29
+ title:
30
+ en: Other
31
+ # Not really a datacite mapping, but needed to support passing custom types
32
+ - id: files
33
+ props:
34
+ datacite: files
@@ -0,0 +1,110 @@
1
+ - id: ark
2
+ props:
3
+ datacite: ARK
4
+ title:
5
+ en: ARK
6
+ - id: arxiv
7
+ props:
8
+ datacite: arXiv
9
+ title:
10
+ en: arXiv
11
+ - id: bibcode
12
+ props:
13
+ datacite: bibcode
14
+ title:
15
+ en: Bibcode
16
+ - id: doi
17
+ props:
18
+ datacite: DOI
19
+ title:
20
+ en: DOI
21
+ - id: ean13
22
+ props:
23
+ datacite: EAN13
24
+ title:
25
+ en: EAN13
26
+ - id: eissn
27
+ props:
28
+ datacite: EISSN
29
+ title:
30
+ en: EISSN
31
+ - id: handle
32
+ props:
33
+ datacite: Handle
34
+ title:
35
+ en: Handle
36
+ - id: igsn
37
+ props:
38
+ datacite: IGSN
39
+ title:
40
+ en: IGSN
41
+ - id: isbn
42
+ props:
43
+ datacite: ISBN
44
+ title:
45
+ en: ISBN
46
+ - id: issn
47
+ props:
48
+ datacite: ISSN
49
+ title:
50
+ en: ISSN
51
+ - id: istc
52
+ props:
53
+ datacite: ISTC
54
+ title:
55
+ en: ISTC
56
+ - id: lissn
57
+ props:
58
+ datacite: LISSN
59
+ title:
60
+ en: LISSN
61
+ - id: lsid
62
+ props:
63
+ datacite: LSID
64
+ title:
65
+ en: LSID
66
+ - id: pmid
67
+ props:
68
+ datacite: PMID
69
+ title:
70
+ en: PMID
71
+ - id: purl
72
+ props:
73
+ datacite: PURL
74
+ title:
75
+ en: PURL
76
+ - id: upc
77
+ props:
78
+ datacite: UPC
79
+ title:
80
+ en: UPC
81
+ - id: url
82
+ props:
83
+ datacite: URL
84
+ title:
85
+ en: URL
86
+ - id: urn
87
+ props:
88
+ datacite: URN
89
+ title:
90
+ en: URN
91
+ - id: w3id
92
+ props:
93
+ datacite: w3id
94
+ title:
95
+ en: W3ID
96
+ - id: cdid
97
+ props:
98
+ datacite: cdid
99
+ title:
100
+ en: CALTECHDATA_ID
101
+ - id: tiltid
102
+ props:
103
+ datacite: tiltid
104
+ title:
105
+ en: TILT_SERIES_ID
106
+ - id: dsa-110-id
107
+ props:
108
+ datacite: dsa-110-id
109
+ title:
110
+ en: DSA_110_ID