caltechdata-api 1.6.1__tar.gz → 1.7.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.
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/PKG-INFO +3 -3
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api/caltechdata_edit.py +2 -1
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api/caltechdata_write.py +5 -4
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api/cli.py +48 -20
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api/md_to_json.py +2 -1
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api.egg-info/PKG-INFO +3 -3
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/setup.py +3 -3
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/LICENSE +0 -0
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/README.md +0 -0
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api/__init__.py +0 -0
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api/customize_schema.py +0 -0
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api/download_file.py +0 -0
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api/get_files.py +0 -0
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api/get_metadata.py +0 -0
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api/utils.py +0 -0
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api.egg-info/SOURCES.txt +0 -0
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api.egg-info/dependency_links.txt +0 -0
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api.egg-info/entry_points.txt +0 -0
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api.egg-info/requires.txt +0 -0
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api.egg-info/top_level.txt +0 -0
- {caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/setup.cfg +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: caltechdata_api
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.0
|
|
4
4
|
Summary: Python wrapper for CaltechDATA API.
|
|
5
5
|
Home-page: https://github.com/caltechlibrary/caltechdata_api
|
|
6
|
-
Author: Thomas E Morrell
|
|
7
|
-
Author-email: tmorrell@caltech.edu
|
|
6
|
+
Author: Thomas E Morrell, Bhattarai Rohan , Won Elizabeth
|
|
7
|
+
Author-email: tmorrell@caltech.edu, ,
|
|
8
8
|
License: https://data.caltech.edu/license
|
|
9
9
|
Platform: UNKNOWN
|
|
10
10
|
Classifier: License :: OSI Approved :: BSD License
|
|
@@ -65,6 +65,7 @@ def caltechdata_edit(
|
|
|
65
65
|
s3_link=None,
|
|
66
66
|
default_preview=None,
|
|
67
67
|
authors=False,
|
|
68
|
+
keepfiles=False,
|
|
68
69
|
):
|
|
69
70
|
# Make a copy of the metadata to make sure our local changes don't leak
|
|
70
71
|
metadata = copy.deepcopy(metadata)
|
|
@@ -246,7 +247,7 @@ def caltechdata_edit(
|
|
|
246
247
|
if result.status_code != 200:
|
|
247
248
|
raise Exception(result.text)
|
|
248
249
|
file_link = result.json()["links"]["files"]
|
|
249
|
-
write_files_rdm(files, file_link, headers, f_headers)
|
|
250
|
+
write_files_rdm(files, file_link, headers, f_headers, keepfiles=keepfiles)
|
|
250
251
|
|
|
251
252
|
else:
|
|
252
253
|
# Check for existing draft
|
|
@@ -9,7 +9,7 @@ from caltechdata_api import customize_schema
|
|
|
9
9
|
from caltechdata_api.utils import humanbytes
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
def write_files_rdm(files, file_link, headers, f_headers, s3=None):
|
|
12
|
+
def write_files_rdm(files, file_link, headers, f_headers, s3=None, keepfiles=False):
|
|
13
13
|
f_json = []
|
|
14
14
|
f_list = {}
|
|
15
15
|
fnames = []
|
|
@@ -59,9 +59,10 @@ def write_files_rdm(files, file_link, headers, f_headers, s3=None):
|
|
|
59
59
|
raise Exception(result.text)
|
|
60
60
|
else:
|
|
61
61
|
# Delete any files not included in this write command
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
if keepfiles == False:
|
|
63
|
+
result = requests.delete(self, headers=f_headers)
|
|
64
|
+
if result.status_code != 204:
|
|
65
|
+
raise Exception(result.text)
|
|
65
66
|
|
|
66
67
|
|
|
67
68
|
def add_file_links(
|
|
@@ -21,6 +21,7 @@ funderIdentifier = ""
|
|
|
21
21
|
funderIdentifierType = ""
|
|
22
22
|
funderName = ""
|
|
23
23
|
|
|
24
|
+
|
|
24
25
|
home_directory = os.path.expanduser("~")
|
|
25
26
|
caltechdata_directory = os.path.join(home_directory, ".caltechdata")
|
|
26
27
|
|
|
@@ -60,6 +61,7 @@ def decrypt_token(encrypted_token, key):
|
|
|
60
61
|
|
|
61
62
|
# Function to get or set token
|
|
62
63
|
def get_or_set_token():
|
|
64
|
+
|
|
63
65
|
key = load_or_generate_key()
|
|
64
66
|
token_file = os.path.join(caltechdata_directory, "token.txt")
|
|
65
67
|
try:
|
|
@@ -267,6 +269,7 @@ def write_s3cmd_config(access_key, secret_key, endpoint):
|
|
|
267
269
|
def upload_supporting_file(record_id=None):
|
|
268
270
|
filepath = ""
|
|
269
271
|
filepaths = []
|
|
272
|
+
file_link = ""
|
|
270
273
|
file_links = []
|
|
271
274
|
while True:
|
|
272
275
|
choice = get_user_input(
|
|
@@ -285,7 +288,6 @@ def upload_supporting_file(record_id=None):
|
|
|
285
288
|
s3 = s3fs.S3FileSystem(anon=True, client_kwargs={"endpoint_url": endpoint})
|
|
286
289
|
# Find the files
|
|
287
290
|
files = s3.glob(path + record_id + "/*")
|
|
288
|
-
|
|
289
291
|
for link in files:
|
|
290
292
|
fname = link.split("/")[-1]
|
|
291
293
|
if "." not in fname:
|
|
@@ -335,16 +337,16 @@ def upload_supporting_file(record_id=None):
|
|
|
335
337
|
print(
|
|
336
338
|
f"Error: File '{filename}' not found. Please enter a valid filename."
|
|
337
339
|
)
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
340
|
+
add_more = get_user_input(
|
|
341
|
+
"Do you want to add more files? (y/n): "
|
|
342
|
+
).lower()
|
|
343
|
+
if add_more != "y":
|
|
344
|
+
break
|
|
345
|
+
break
|
|
343
346
|
elif choice == "n":
|
|
344
347
|
break
|
|
345
348
|
else:
|
|
346
349
|
print("Invalid input. Please enter 'link' or 'upload' or 'n'.")
|
|
347
|
-
|
|
348
350
|
return filepaths, file_links
|
|
349
351
|
|
|
350
352
|
|
|
@@ -399,7 +401,7 @@ def create_record():
|
|
|
399
401
|
if existing_data:
|
|
400
402
|
if filepath != "":
|
|
401
403
|
response = caltechdata_write(
|
|
402
|
-
existing_data, token, filepath, production=
|
|
404
|
+
existing_data, token, filepath, production=True, publish=False
|
|
403
405
|
)
|
|
404
406
|
elif file_link != "":
|
|
405
407
|
response = caltechdata_write(
|
|
@@ -407,16 +409,17 @@ def create_record():
|
|
|
407
409
|
token,
|
|
408
410
|
file_links=[file_link],
|
|
409
411
|
s3_link=file_link,
|
|
410
|
-
production=
|
|
412
|
+
production=True,
|
|
411
413
|
publish=False,
|
|
412
414
|
)
|
|
413
415
|
else:
|
|
414
416
|
response = caltechdata_write(
|
|
415
|
-
existing_data, token, production=
|
|
417
|
+
existing_data, token, production=True, publish=False
|
|
416
418
|
)
|
|
417
419
|
rec_id = response
|
|
418
420
|
print(
|
|
419
|
-
f"""You can view and publish this record at
|
|
421
|
+
f"""You can view and publish this record at
|
|
422
|
+
https://data.caltech.edu/uploads/{rec_id}
|
|
420
423
|
If you need to upload large files to S3, you can type
|
|
421
424
|
`s3cmd put DATA_FILE s3://ini230004-bucket01/{rec_id}/"""
|
|
422
425
|
)
|
|
@@ -465,23 +468,24 @@ def create_record():
|
|
|
465
468
|
if confirm_upload():
|
|
466
469
|
if filepath != "":
|
|
467
470
|
response = caltechdata_write(
|
|
468
|
-
metadata, token, filepath, production=
|
|
471
|
+
metadata, token, filepath, production=True, publish=False
|
|
469
472
|
)
|
|
470
473
|
elif file_link != "":
|
|
471
474
|
response = caltechdata_write(
|
|
472
475
|
metadata,
|
|
473
476
|
token,
|
|
474
477
|
file_links=[file_link],
|
|
475
|
-
production=
|
|
478
|
+
production=True,
|
|
476
479
|
publish=False,
|
|
477
480
|
)
|
|
478
481
|
else:
|
|
479
482
|
response = caltechdata_write(
|
|
480
|
-
metadata, token, production=
|
|
483
|
+
metadata, token, production=True, publish=False
|
|
481
484
|
)
|
|
482
485
|
rec_id = response
|
|
483
486
|
print(
|
|
484
|
-
f"""You can view and publish this record at
|
|
487
|
+
f"""You can view and publish this record at
|
|
488
|
+
https://data.caltech.edu/uploads/{rec_id}
|
|
485
489
|
If you need to upload large files to S3, you can type
|
|
486
490
|
`s3cmd put DATA_FILE s3://ini230004-bucket01/{rec_id}/"""
|
|
487
491
|
)
|
|
@@ -504,7 +508,7 @@ def edit_record():
|
|
|
504
508
|
with open(file_name, "r") as file:
|
|
505
509
|
metadata = json.load(file)
|
|
506
510
|
response = caltechdata_edit(
|
|
507
|
-
record_id, metadata, token, production=
|
|
511
|
+
record_id, metadata, token, production=True, publish=False
|
|
508
512
|
)
|
|
509
513
|
if response:
|
|
510
514
|
print("Metadata edited successfully.")
|
|
@@ -516,11 +520,33 @@ def edit_record():
|
|
|
516
520
|
print("No metadata file found.")
|
|
517
521
|
choice = get_user_input("Do you want to add files? (y/n): ").lower()
|
|
518
522
|
if choice == "y":
|
|
523
|
+
API_URL_TEMPLATE = "https://data.caltech.edu/api/records/{record_id}/files"
|
|
524
|
+
url = API_URL_TEMPLATE.format(record_id=record_id)
|
|
525
|
+
|
|
526
|
+
API_URL_TEMPLATE2 = (
|
|
527
|
+
"https://data.caltech.edu/api/records/{record_id}/draft/files"
|
|
528
|
+
)
|
|
529
|
+
url2 = API_URL_TEMPLATE2.format(record_id=record_id)
|
|
530
|
+
response = requests.get(url)
|
|
531
|
+
response2 = requests.get(url2)
|
|
519
532
|
filepath, file_link = upload_supporting_file(record_id)
|
|
520
533
|
print(file_link)
|
|
534
|
+
if response.status_code == 404 and response2.status_code == 404:
|
|
535
|
+
keepfile = False
|
|
536
|
+
else:
|
|
537
|
+
keepfile = input("Do you want to keep existing files? y/n: ")
|
|
538
|
+
if keepfile == "y":
|
|
539
|
+
keepfile = True
|
|
540
|
+
else:
|
|
541
|
+
keepfile = False
|
|
521
542
|
if filepath != "":
|
|
522
543
|
response = caltechdata_edit(
|
|
523
|
-
record_id,
|
|
544
|
+
record_id,
|
|
545
|
+
token=token,
|
|
546
|
+
files=filepath,
|
|
547
|
+
production=True,
|
|
548
|
+
publish=False,
|
|
549
|
+
keepfiles=keepfile,
|
|
524
550
|
)
|
|
525
551
|
elif file_link != "":
|
|
526
552
|
response = caltechdata_edit(
|
|
@@ -528,17 +554,18 @@ def edit_record():
|
|
|
528
554
|
metadata,
|
|
529
555
|
token=token,
|
|
530
556
|
file_links=file_link,
|
|
531
|
-
production=
|
|
557
|
+
production=True,
|
|
532
558
|
publish=False,
|
|
559
|
+
keepfile=keepfile,
|
|
533
560
|
)
|
|
534
561
|
rec_id = response
|
|
535
562
|
print(
|
|
536
|
-
f"You can view and publish this record at https://data.
|
|
563
|
+
f"You can view and publish this record at https://data.caltech.edu/uploads/{rec_id}\n"
|
|
537
564
|
)
|
|
538
565
|
|
|
539
566
|
|
|
540
567
|
def download_file_by_id(record_id, token=None):
|
|
541
|
-
url = f"https://data.
|
|
568
|
+
url = f"https://data.caltech.edu/api/records/{record_id}"
|
|
542
569
|
|
|
543
570
|
headers = {
|
|
544
571
|
"accept": "application/vnd.datacite.datacite+json",
|
|
@@ -549,6 +576,7 @@ def download_file_by_id(record_id, token=None):
|
|
|
549
576
|
|
|
550
577
|
try:
|
|
551
578
|
response = requests.get(url, headers=headers)
|
|
579
|
+
|
|
552
580
|
if response.status_code != 200:
|
|
553
581
|
# Might have a draft
|
|
554
582
|
response = requests.get(
|
|
@@ -157,7 +157,8 @@ def parse_readme_to_json(readme_path):
|
|
|
157
157
|
link_match = link_pattern.search(value)
|
|
158
158
|
if link_match:
|
|
159
159
|
value = link_match.group(1)
|
|
160
|
-
|
|
160
|
+
|
|
161
|
+
current_object[key] = value
|
|
161
162
|
|
|
162
163
|
elif line.strip() and not section_match:
|
|
163
164
|
raise ReadmeFormatException(
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: caltechdata-api
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.0
|
|
4
4
|
Summary: Python wrapper for CaltechDATA API.
|
|
5
5
|
Home-page: https://github.com/caltechlibrary/caltechdata_api
|
|
6
|
-
Author: Thomas E Morrell
|
|
7
|
-
Author-email: tmorrell@caltech.edu
|
|
6
|
+
Author: Thomas E Morrell, Bhattarai Rohan , Won Elizabeth
|
|
7
|
+
Author-email: tmorrell@caltech.edu, ,
|
|
8
8
|
License: https://data.caltech.edu/license
|
|
9
9
|
Platform: UNKNOWN
|
|
10
10
|
Classifier: License :: OSI Approved :: BSD License
|
|
@@ -40,9 +40,9 @@ version = meta["version"]
|
|
|
40
40
|
author = ""
|
|
41
41
|
author_email = ""
|
|
42
42
|
for obj in meta["author"]:
|
|
43
|
-
given = obj
|
|
44
|
-
family = obj
|
|
45
|
-
email = obj
|
|
43
|
+
given = obj.get("givenName", "")
|
|
44
|
+
family = obj.get("familyName", "")
|
|
45
|
+
email = obj.get("email", "")
|
|
46
46
|
if len(author) == 0:
|
|
47
47
|
author = given + " " + family
|
|
48
48
|
else:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{caltechdata_api-1.6.1 → caltechdata_api-1.7.0}/caltechdata_api.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|