Skip to content
Snippets Groups Projects
Commit c62ca541 authored by vuillaut's avatar vuillaut
Browse files

raise error if entry not created

parent 33dae94b
No related branches found
No related tags found
1 merge request!57eossr upload unique function
Pipeline #138391 failed
...@@ -55,21 +55,18 @@ def upload(zenodo_token, sandbox_flag, input_directory): ...@@ -55,21 +55,18 @@ def upload(zenodo_token, sandbox_flag, input_directory):
# 1 - create empty deposit # 1 - create empty deposit
new_entry = zenodo.create_new_entry() new_entry = zenodo.create_new_entry()
ZenodoHTTPStatus(new_entry.status_code, new_entry.json())
record_id = new_entry.json()['id']
print(f" * Status {new_entry.status_code}. New entry to Zenodo created ! Deposition id {record_id}")
if new_entry.status_code < 399:
deposition_id = new_entry.json()['id']
doi = new_entry.json()['metadata']['prereserve_doi']['doi']
print(f" * Status {new_entry.status_code}. New entry to Zenodo created ! Deposition id {deposition_id}")
else:
print(f" ! ERROR; the NEW entry COULD NOT be created.")
print(new_entry.json())
# 2 - upload files # 2 - upload files
for file in os.listdir(input_directory): for file in os.listdir(input_directory):
full_path_file = input_directory + '/' + file full_path_file = input_directory + '/' + file
new_upload = zenodo.upload_file_entry( new_upload = zenodo.upload_file_entry(
deposition_id, record_id,
name_file=file, name_file=file,
path_file=full_path_file path_file=full_path_file
) )
...@@ -88,7 +85,7 @@ def upload(zenodo_token, sandbox_flag, input_directory): ...@@ -88,7 +85,7 @@ def upload(zenodo_token, sandbox_flag, input_directory):
# entry_info['metadata']['doi'] = doi # In the new version of the API the doi is updated automatically. # entry_info['metadata']['doi'] = doi # In the new version of the API the doi is updated automatically.
update_entry = zenodo.update_metadata_entry( update_entry = zenodo.update_metadata_entry(
deposition_id, record_id,
json_metadata=entry_metadata json_metadata=entry_metadata
) )
...@@ -97,12 +94,12 @@ def upload(zenodo_token, sandbox_flag, input_directory): ...@@ -97,12 +94,12 @@ def upload(zenodo_token, sandbox_flag, input_directory):
# 4 - publish entry # 4 - publish entry
publish = zenodo.publish_entry(deposition_id) publish = zenodo.publish_entry(record_id)
if publish.status_code == 204: if publish.status_code == 204:
print(" * New deposit correctly published !\n") print(" * New deposit correctly published !\n")
print(f" * The new doi should look like 10.5281/{deposition_id}. However please") print(f" * The new doi should look like 10.5281/{record_id}. However please")
print(f" ** Check the upload at {zenodo.zenodo_api_url[:-4]}/deposit/{deposition_id} **") print(f" ** Check the upload at {zenodo.zenodo_api_url[:-4]}/deposit/{record_id} **")
else: else:
print(f" ! New deposit NOT correctly published ! Status {publish.status_code}\n", print(f" ! New deposit NOT correctly published ! Status {publish.status_code}\n",
publish.json()) publish.json())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment