Example #1
0
def run(options):
    '''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 and "version string" of this version as well as the
    # version before it if this is an incremental release.
    version = options.major, options.minor, options.patch
    version_str = authors.get_version_string(options.major,
                                             options.minor,
                                             options.patch)
    tag = authors.find_tag(*version)
    if not options.main:
        prev_tag = authors.get_previous_tag(tag)
        prev_version = authors.get_version_from_git_tag(prev_tag)
        prev_version_str = authors.get_version_string(*prev_version)

    main_doi = '10.5286/Software/Mantid'

    if options.main:
        doi = main_doi
        prev_doi = ''
        has_previous_version = False
    else: # Incremental release DOI.
        prev_doi = '10.5286/Software/Mantid' + prev_version_str
        doi = '10.5286/Software/Mantid' + version_str

    if options.main:
        destination = 'http://www.mantidproject.org'
    else:
        destination = 'http://www.mantidproject.org/Release_Notes_' + \
                      version_str
        prev_destination = 'http://www.mantidproject.org/Release_Notes_' +\
                               prev_version_str

    # Use the test server if running in test mode.
    if options.test:
        server_url_base = 'https://test.datacite.org/mds/'
    else:
        server_url_base = 'https://mds.datacite.org/'

    if options.delete:
        delete_doi(server_url_base, doi, options)
        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 options.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, options)
        create_or_update_doi(server_url_base, doi, destination, options)
    # 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,
            options
        )

        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, options)
        create_or_update_doi(server_url_base, doi, destination, options)

        # 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,
                options
            )

    # Print out a custom success message, depending on the initial options.
    if not options.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()
Example #2
0
def run(options):
    '''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 and "version string" of this version as well as the
    # version before it if this is an incremental release.
    version = options.major, options.minor, options.patch
    version_str = authors.get_version_string(options.major, options.minor,
                                             options.patch)
    tag = authors.find_tag(*version)
    if not options.main:
        prev_tag = authors.get_previous_tag(tag)
        prev_version = authors.get_version_from_git_tag(prev_tag)
        prev_version_str = authors.get_version_string(*prev_version)

    main_doi = '10.5286/Software/Mantid'

    if options.main:
        doi = main_doi
        prev_doi = ''
        has_previous_version = False
    else:  # Incremental release DOI.
        prev_doi = '10.5286/Software/Mantid' + prev_version_str
        doi = '10.5286/Software/Mantid' + version_str

    if options.main:
        destination = 'http://www.mantidproject.org'
    else:
        destination = 'http://www.mantidproject.org/Release_Notes_' + \
                      version_str
        prev_destination = 'http://www.mantidproject.org/Release_Notes_' +\
                               prev_version_str

    # Use the test server if running in test mode.
    if options.test:
        server_url_base = 'https://test.datacite.org/mds/'
    else:
        server_url_base = 'https://mds.datacite.org/'

    if options.delete:
        delete_doi(server_url_base, doi, options)
        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 options.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, options)
        create_or_update_doi(server_url_base, doi, destination, options)
    # 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, options)

        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, options)
        create_or_update_doi(server_url_base, doi, destination, options)

        # 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,
                                      options)

    # Print out a custom success message, depending on the initial options.
    if not options.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()