Skip to content

Update cli.py #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions caltechdata_api/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ def upload_supporting_file(record_id=None):
filepaths = []
file_link = ""
file_links = []
idx = 0
while True:
choice = get_user_input(
"Do you want to upload or link data files? (upload/link/n): "
Expand Down Expand Up @@ -402,14 +403,24 @@ def upload_supporting_file(record_id=None):
files = [
f for f in os.listdir() if not f.endswith(".json") and os.path.isfile(f)
]
print("\n".join(files))
print((""+ str(++idx) + "/ \n").join(files))
while True:
filename = get_user_input(
"Enter the filename to upload as a supporting file (or 'n' to finish): "
"Enter the filename to upload as a supporting file (or '*' to get all files currently in the directory, or the index number of the file as displayed followed by a /, otherwise 'n' to finish): "
)
if filename == "n":
if filename == "*":
for files_name in files:
filepath = os.path.abspath(files_name)
filepaths.append(filepath)
print("All files added successfully")
elif filename == "n":
break
if filename in files:
elif filename[len(filename)-1] == '/':
files_name = files[int(filename[0])-1]
filepath = os.path.abspath(files_name)
filepaths.append(filepath)
print("File added successfully")
elif filename in files:
file_size = os.path.getsize(filename)
if file_size > 1024 * 1024 * 1024:
print(
Expand All @@ -420,6 +431,7 @@ def upload_supporting_file(record_id=None):
else:
filepath = os.path.abspath(filename)
filepaths.append(filepath)
print("File added successfully")
else:
print(
f"Error: File '{filename}' not found. Please enter a valid filename."
Expand Down
Loading