def run(args): '''Creating a usable DOI is (for our purposes at least) a two step process: metadata has to be constructed and then sent to the server, and then the DOI itself has to be sent once the metadata is in place. If pre-existing DOI's or metadata are submitted then they will overwrite what was there previously. We also have to amend the metadata for the previous DOI (if one exists), so that we can set up a IsPreviousVersionOf/IsNewVersionOf relationship between the two DOIs. ''' # Get the git tag as well as the version before it if this is an incremental release. version_str = args.version shortened_version_str = authors.get_shortened_version_string(version_str) tag = authors.find_tag(version_str) if not args.main: prev_tag = authors.get_previous_tag(tag) prev_version_str = authors.get_version_from_git_tag(prev_tag) shortened_prev_version_str = authors.get_shortened_version_string(prev_version_str) main_doi = '10.5286/Software/Mantid' if args.main: doi = main_doi prev_doi = '' has_previous_version = False else: # Incremental release DOI. prev_doi = '10.5286/Software/Mantid' + shortened_prev_version_str doi = '10.5286/Software/Mantid' + shortened_version_str if args.main: destination = 'http://www.mantidproject.org' else: destination, prev_destination = get_urls_for_doi(version_str, shortened_version_str, prev_version_str, shortened_prev_version_str) if args.test: server_url_base = 'https://test.datacite.org/mds/' else: server_url_base = 'https://mds.datacite.org/' if not args.password: args.password = getpass.getpass() if args.delete: delete_doi(server_url_base, doi, args) quit() # If the user ran this script with the --main flag, then all we need to do # is create a single, unlinked DOI to the main project page. if args.main: creator_name_list = authors.authors_up_to_git_tag(tag) # In the case of the main DOI we need to add the whitelisted names too. creator_name_list = sorted(set(creator_name_list + authors.whitelist)) xml_form = build_xml_form(doi, {}, creator_name_list, None) create_or_update_metadata(xml_form, server_url_base, doi, args) create_or_update_doi(server_url_base, doi, destination, args) # Else it's an incremental-release DOI that we need to make. else: has_previous_version = check_if_doi_exists( server_url_base, prev_doi, prev_destination, args ) relationships = { main_doi : 'IsPartOf' } if has_previous_version: relationships[prev_doi] = 'IsNewVersionOf' creator_name_list = authors.authors_under_git_tag(tag) xml_form = build_xml_form( doi, relationships, creator_name_list, version_str ) # Create/update the metadata and DOI. create_or_update_metadata(xml_form, server_url_base, doi, args) create_or_update_doi(server_url_base, doi, destination, args) # Create/update the metadata and DOI of the previous version, if it # was found to have a DOI. if has_previous_version: prev_relationships = { main_doi : 'IsPartOf', doi : 'IsPreviousVersionOf' } prev_creator_name_list = authors.authors_under_git_tag(prev_tag) prev_xml_form = build_xml_form( prev_doi, prev_relationships, prev_creator_name_list, prev_version_str ) create_or_update_metadata( prev_xml_form, server_url_base, prev_doi, args ) # Print out a custom success message, depending on the initial options. if not args.test: method = "resolved" doi_add = 'http://dx.doi.org/' + doi meta_add = 'https://mds.datacite.org/metadata/' + doi prev_meta_add = 'https://mds.datacite.org/metadata/' + prev_doi else: method = "inspected" doi_add = 'https://test.datacite.org/mds/doi/' + doi meta_add = 'https://test.datacite.org/mds/metadata/' + doi prev_meta_add = 'https://test.datacite.org/mds/metadata/' + prev_doi if has_previous_version: message = "\nSUCCESS!" + \ "\nThe DOI can be %s at \"%s\"." % (method, doi_add) + \ "\nThe new metadata can be inspected at \"%s\"." % (meta_add) + \ "\nThe previous version's metadata can be inspected at" + \ "\"%s\"." % (prev_meta_add) else: message = "\nSUCCESS!" + \ "\nThe DOI can be %s at \"%s\"." % (method, doi_add) + \ "\nThe metadata can be inspected at \"%s\"." % (meta_add) print message quit()
def run(args): '''Creating a usable DOI is (for our purposes at least) a two step process: metadata has to be constructed and then sent to the server, and then the DOI itself has to be sent once the metadata is in place. If pre-existing DOI's or metadata are submitted then they will overwrite what was there previously. We also have to amend the metadata for the previous DOI (if one exists), so that we can set up a IsPreviousVersionOf/IsNewVersionOf relationship between the two DOIs. ''' # Get the git tag as well as the version before it if this is an incremental release. version_str = args.version shortened_version_str = authors.get_shortened_version_string(version_str) tag = authors.find_tag(version_str) if not args.main: prev_tag = authors.get_previous_tag(tag) prev_version_str = authors.get_version_from_git_tag(prev_tag) shortened_prev_version_str = authors.get_shortened_version_string(prev_version_str) main_doi = '10.5286/Software/Mantid' if args.main: doi = main_doi prev_doi = '' has_previous_version = False else: # Incremental release DOI. prev_doi = '10.5286/Software/Mantid' + shortened_prev_version_str doi = '10.5286/Software/Mantid' + shortened_version_str if args.main: destination = 'http://www.mantidproject.org' else: destination, prev_destination = get_urls_for_doi(version_str, shortened_version_str, prev_version_str, shortened_prev_version_str) if args.test: server_url_base = 'https://test.datacite.org/mds/' else: server_url_base = 'https://mds.datacite.org/' if args.delete: delete_doi(server_url_base, doi, args) quit() # If the user ran this script with the --main flag, then all we need to do # is create a single, unlinked DOI to the main project page. if args.main: creator_name_list = authors.authors_up_to_git_tag(tag) # In the case of the main DOI we need to add the whitelisted names too. creator_name_list = sorted(set(creator_name_list + authors.whitelist)) xml_form = build_xml_form(doi, {}, creator_name_list, None) create_or_update_metadata(xml_form, server_url_base, doi, args) create_or_update_doi(server_url_base, doi, destination, args) # Else it's an incremental-release DOI that we need to make. else: has_previous_version = check_if_doi_exists( server_url_base, prev_doi, prev_destination, args ) relationships = { main_doi : 'IsPartOf' } if has_previous_version: relationships[prev_doi] = 'IsNewVersionOf' creator_name_list = authors.authors_under_git_tag(tag) xml_form = build_xml_form( doi, relationships, creator_name_list, version_str ) # Create/update the metadata and DOI. create_or_update_metadata(xml_form, server_url_base, doi, args) create_or_update_doi(server_url_base, doi, destination, args) # Create/update the metadata and DOI of the previous version, if it # was found to have a DOI. if has_previous_version: prev_relationships = { main_doi : 'IsPartOf', doi : 'IsPreviousVersionOf' } prev_creator_name_list = authors.authors_under_git_tag(prev_tag) prev_xml_form = build_xml_form( prev_doi, prev_relationships, prev_creator_name_list, prev_version_str ) create_or_update_metadata( prev_xml_form, server_url_base, prev_doi, args ) # Print out a custom success message, depending on the initial options. if not args.test: method = "resolved" doi_add = 'http://dx.doi.org/' + doi meta_add = 'https://mds.datacite.org/metadata/' + doi prev_meta_add = 'https://mds.datacite.org/metadata/' + prev_doi else: method = "inspected" doi_add = 'https://test.datacite.org/mds/doi/' + doi meta_add = 'https://test.datacite.org/mds/metadata/' + doi prev_meta_add = 'https://test.datacite.org/mds/metadata/' + prev_doi if has_previous_version: message = "\nSUCCESS!" + \ "\nThe DOI can be %s at \"%s\"." % (method, doi_add) + \ "\nThe new metadata can be inspected at \"%s\"." % (meta_add) + \ "\nThe previous version's metadata can be inspected at" + \ "\"%s\"." % (prev_meta_add) else: message = "\nSUCCESS!" + \ "\nThe DOI can be %s at \"%s\"." % (method, doi_add) + \ "\nThe metadata can be inspected at \"%s\"." % (meta_add) print message quit()