Skip to content

Commit

Permalink
Fix insert/update doi, add --skip-registration option and refactor do…
Browse files Browse the repository at this point in the history
…i commands
  • Loading branch information
jochenklar committed Aug 5, 2024
1 parent 64e447c commit 18738d4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
15 changes: 11 additions & 4 deletions isimip_publisher/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@ def insert_doi():
session.commit()
session.close()

if not settings.SKIP_REGISTRATION and dois.confirm_upload():
dois.upload_doi(resource, settings.ISIMIP_DATA_URL,
settings.DATACITE_USERNAME, settings.DATACITE_PASSWORD,
settings.DATACITE_PREFIX, settings.DATACITE_TEST_MODE)


def update_doi():
session = database.init_database_session(settings.DATABASE)
Expand All @@ -483,12 +488,14 @@ def update_doi():
session.commit()
session.close()

if not settings.SKIP_REGISTRATION and dois.confirm_upload():
dois.upload_doi(resource, settings.ISIMIP_DATA_URL,
settings.DATACITE_USERNAME, settings.DATACITE_PASSWORD,
settings.DATACITE_PREFIX, settings.DATACITE_TEST_MODE)

def register_doi():
print('Registering a DOI with DataCite is permanent. Please type "yes" to confirm.')
string = input()

if string.lower() == 'yes':
def register_doi():
if dois.confirm_upload():
session = database.init_database_session(settings.DATABASE)
resource = database.fetch_resource(session, settings.DOI)
dois.upload_doi(resource, settings.ISIMIP_DATA_URL,
Expand Down
2 changes: 2 additions & 0 deletions isimip_publisher/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def get_parser(add_path=False, add_subparsers=False):
help='Rights/license for the files [default: None]')
parser.add_argument('--archived', dest='archived', action='store_true', default=False,
help='Check also archived files')
parser.add_argument('--skip-registration', dest='skip_registration', action='store_true', default=False,
help='Skip the registration of the DOI when inserting/updating a resource')
parser.add_argument('--skip-checksum', dest='skip_checksum', action='store_true', default=False,
help='Skip the computation of the checksum when checking')
parser.add_argument('--log-level', dest='log_level', default='WARN',
Expand Down
6 changes: 3 additions & 3 deletions isimip_publisher/utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,10 @@ def insert_resource(session, datacite, paths, datacite_prefix):
if not paths:
raise RuntimeError(f'No paths were provided for {doi}.')

# gather datasets
datasets = []
# gather datasets, use a set to remove duplicate datasets (for links)
datasets = set()
for path in paths:
datasets += retrieve_datasets(session, path, public=True, follow=True)
datasets.update(retrieve_datasets(session, path, public=True, follow=True))

if not datasets:
message = f'No datasets found for {doi}.'
Expand Down
5 changes: 5 additions & 0 deletions isimip_publisher/utils/dois.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ def upload_doi(resource, isimip_data_url,
# register the doi
mds_doi_response = mds_client.doi_post(doi, url)
print(mds_doi_response)


def confirm_upload():
print('Registering a DOI with DataCite is permanent. Please type "yes" to confirm.')
return input().lower() == 'yes'

0 comments on commit 18738d4

Please sign in to comment.