Skip to content

Commit 8e1fe72

Browse files
committed
Add s3cmd instructions
1 parent 2fe8e98 commit 8e1fe72

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

caltechdata_api/cli.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from .md_to_json import parse_readme_to_json
66
import json
77
import os
8-
#import configparser
8+
9+
# import configparser
910
from cryptography.fernet import Fernet
1011

1112
CALTECHDATA_API = "https://data.caltech.edu/api/names?q=identifiers.identifier:{}"
@@ -23,7 +24,7 @@
2324
funderName = ""
2425

2526

26-
#CONFIG_FILE = "caltechdata_config.ini"
27+
# CONFIG_FILE = "caltechdata_config.ini"
2728

2829

2930
home_directory = os.path.expanduser("~")
@@ -33,9 +34,11 @@
3334
if not os.path.exists(caltechdata_directory):
3435
os.makedirs(caltechdata_directory)
3536

37+
3638
def generate_key():
3739
return Fernet.generate_key()
3840

41+
3942
# Load the key from a file or generate a new one if not present
4043
def load_or_generate_key(key_file="key.key"):
4144
if os.path.exists(key_file):
@@ -47,19 +50,21 @@ def load_or_generate_key(key_file="key.key"):
4750
f.write(key)
4851
return key
4952

53+
5054
# Encrypt the token
5155
def encrypt_token(token, key):
5256
f = Fernet(key)
5357
return f.encrypt(token.encode())
5458

59+
5560
# Decrypt the token
5661
def decrypt_token(encrypted_token, key):
5762
f = Fernet(key)
5863
return f.decrypt(encrypted_token).decode()
5964

65+
6066
# Function to get or set token
6167
def get_or_set_token():
62-
6368
key = load_or_generate_key()
6469
try:
6570
with open("token.txt", "rb") as f:
@@ -77,7 +82,8 @@ def get_or_set_token():
7782
return token
7883
else:
7984
print("Tokens do not match. Please try again.")
80-
85+
86+
8187
def welcome_message():
8288
print("Welcome to CaltechDATA CLI")
8389

@@ -261,8 +267,12 @@ def upload_supporting_file(record_id=None):
261267
path = "ini230004-bucket01/"
262268

263269
if not record_id:
264-
record_id = get_user_input("Folder where OSN files are uploaded")
265-
270+
print(
271+
"""Please upload the
272+
metadata to CaltechDATA, and you'll be provided
273+
instructions to upload the files to S3 directly."""
274+
)
275+
break
266276
s3 = s3fs.S3FileSystem(anon=True, client_kwargs={"endpoint_url": endpoint})
267277
# Find the files
268278
files = s3.glob(path + record_id + "/*")
@@ -306,11 +316,11 @@ def upload_supporting_file(record_id=None):
306316
if filename in files:
307317
file_size = os.path.getsize(filename)
308318
if file_size > 1024 * 1024 * 1024:
309-
file_link = get_user_input(
310-
"Enter the S3 link to the file (File size is more than 1GB): "
319+
print(
320+
"""The file is greater than 1 GB. Please upload the
321+
metadata to CaltechDATA, and you'll be provided
322+
instructions to upload the files to S3 directly."""
311323
)
312-
if file_link:
313-
file_links.append(file_link)
314324
else:
315325
filepath = os.path.abspath(filename)
316326
filepaths.append(filepath)
@@ -330,6 +340,7 @@ def upload_supporting_file(record_id=None):
330340

331341
return filepaths, file_links
332342

343+
333344
def upload_data_from_file():
334345
while True:
335346
print("Current JSON files in the directory:")
@@ -511,7 +522,11 @@ def edit_record():
511522
)
512523
rec_id = response
513524
print(
514-
f"You can view and publish this record at https://data.caltechlibrary.dev/uploads/{rec_id}"
525+
f"""You can view and publish this record at
526+
https://data.caltechlibrary.dev/uploads/{rec_id}\n
527+
If you need to upload large files to S3, you can type `s3cmd
528+
--endpoint-url https://renc.osn.xsede.org:443 cp DATA_FILE
529+
s3://ini210004tommorrell/{rec_id}"""
515530
)
516531

517532

caltechdata_api/md_to_json.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def parse_readme_to_json(readme_path):
5555
raise ValueError('README.md needs to start with "# Title"')
5656
else:
5757
json_data["titles"] = [{"title": title_line.replace("# ", "")}]
58-
58+
5959
contributors = []
6060
identifiers = []
6161
item_list = []
@@ -182,6 +182,7 @@ def parse_readme_to_json(readme_path):
182182

183183
return json_data
184184

185+
185186
if __name__ == "__main__":
186187
readme_path = "/Users/elizabethwon/downloads/exampleREADME.md"
187188
try:

0 commit comments

Comments
 (0)