Skip to content

Commit 6751dfa

Browse files
authored
Update cli.py to expand supported file options (#70)
Implementation a feature such that users can choose a file from inside the current directory based on a displayed index instead of a filename, collision of filenames with indices handled with the help of a special character
1 parent 89cb1bf commit 6751dfa

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

caltechdata_api/cli.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ def upload_supporting_file(record_id=None):
360360
filepaths = []
361361
file_link = ""
362362
file_links = []
363+
idx = 0
363364
while True:
364365
choice = get_user_input(
365366
"Do you want to upload or link data files? (upload/link/n): "
@@ -402,14 +403,28 @@ def upload_supporting_file(record_id=None):
402403
files = [
403404
f for f in os.listdir() if not f.endswith(".json") and os.path.isfile(f)
404405
]
405-
print("\n".join(files))
406+
idx+=1
407+
print((f"{idx}/ \n").join(files))
406408
while True:
407409
filename = get_user_input(
408-
"Enter the filename to upload as a supporting file (or 'n' to finish): "
410+
"Enter the filename to upload as a supporting file (or '*' to get all files currently in this directory, or the index number of the file as displayed followed by a /, otherwise 'n' to finish): "
409411
)
410-
if filename == "n":
412+
if filename == "*":
413+
for files_name in files:
414+
filepath = os.path.abspath(files_name)
415+
filepaths.append(filepath)
416+
print("All files added successfully")
417+
elif filename == "n":
411418
break
412-
if filename in files:
419+
elif (not len(filename) == 0) and (filename[len(filename) - 1] == '/'):
420+
try:
421+
files_name = files[int(filename[0])-1]
422+
filepath = os.path.abspath(files_name)
423+
filepaths.append(filepath)
424+
print("File added successfully")
425+
except ValueError:
426+
continue
427+
elif filename in files:
413428
file_size = os.path.getsize(filename)
414429
if file_size > 1024 * 1024 * 1024:
415430
print(
@@ -420,6 +435,7 @@ def upload_supporting_file(record_id=None):
420435
else:
421436
filepath = os.path.abspath(filename)
422437
filepaths.append(filepath)
438+
print("File added successfully")
423439
else:
424440
print(
425441
f"Error: File '{filename}' not found. Please enter a valid filename."

codemeta.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,18 @@
4949
},
5050
"email": "[email protected]",
5151
"@id": "https://orcid.org/0009-0003-5640-6691"
52-
}
52+
},
53+
{
54+
"@type": "Person",
55+
"givenName": "Kshemaahna",
56+
"familyName": "Nagi",
57+
"affiliation": {
58+
"@type": "Organization",
59+
"name": "Caltech"
60+
},
61+
"email": "[email protected]",
62+
"@id": "https://orcid.org/0009-0002-8113-3763"
63+
},
5364
],
5465
"developmentStatus": "active",
5566
"downloadUrl": "https://github.com/caltechlibrary/caltechdata_api/archive/1.9.1.zip",
@@ -84,4 +95,4 @@
8495
},
8596
"programmingLanguage": "Python",
8697
"identifier": "10.22002/3gdk4-j5504"
87-
}
98+
}

0 commit comments

Comments
 (0)