Esempio n. 1
0
def publish(*params):
    parser = parser_publish()
    results = parser.parse_args(params)

    from boutiques.publisher import Publisher
    publisher = Publisher(results.boutiques_descriptor, results.zenodo_token,
                          results.verbose, results.sandbox, results.no_int,
                          results.replace, results.id)
    publisher.publish()
    if hasattr(publisher, 'doi'):
        return publisher.doi
Esempio n. 2
0
def publish(*params):
    parser = ArgumentParser("Boutiques publisher",
                            description="A publisher of Boutiques tools"
                            " in Zenodo (http://zenodo.org). Requires "
                            "a Zenodo access token, see "
                            "http://developers.zenodo.org/#authentication.")
    parser.add_argument("boutiques_descriptor",
                        action="store",
                        help="local path of the "
                        " Boutiques descriptor to publish.")
    parser.add_argument("--sandbox",
                        action="store_true",
                        help="publish to Zenodo's sandbox instead of "
                        "production server. Recommended for tests.")
    parser.add_argument("--zenodo-token",
                        action="store",
                        help="Zenodo API token to use for authentication. "
                        "If not used, token will be read from configuration "
                        "file or requested interactively.")
    parser.add_argument("--no-int",
                        '-y',
                        action="store_true",
                        help="disable interactive input.")
    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        help="print information messages.")
    group = parser.add_mutually_exclusive_group()
    group.add_argument("-r",
                       "--replace",
                       action="store_true",
                       help="Publish an updated version of an existing "
                       "record. The descriptor must contain a DOI, which "
                       "will be replaced with a new one.")
    group.add_argument("--id",
                       action="store",
                       help="Zenodo ID of an existing record you wish to "
                       "update with a new version, prefixed by "
                       "'zenodo.' (e.g. zenodo.123456).")

    results = parser.parse_args(params)

    from boutiques.publisher import Publisher
    publisher = Publisher(results.boutiques_descriptor, results.zenodo_token,
                          results.verbose, results.sandbox, results.no_int,
                          results.replace, results.id)
    publisher.publish()
    if hasattr(publisher, 'doi'):
        return publisher.doi
Esempio n. 3
0
def publish(*params):
    parser = ArgumentParser("Boutiques publisher",
                            description="A publisher of Boutiques tools"
                            " in Zenodo (http://zenodo.org). Requires "
                            "a Zenodo access token, see "
                            "http://developers.zenodo.org/#authentication.")
    parser.add_argument("boutiques_descriptor",
                        action="store",
                        help="local path of the "
                        " Boutiques descriptor to publish.")
    parser.add_argument("--sandbox",
                        action="store_true",
                        help="publish to Zenodo's sandbox instead of "
                        "production server. Recommended for tests.")
    parser.add_argument("--zenodo-token",
                        action="store",
                        help="Zenodo API token to use for authentication. "
                        "If not used, token will be read from configuration "
                        "file or requested interactively.")
    parser.add_argument("--no-int",
                        '-y',
                        action="store_true",
                        help="disable interactive input.")
    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        help="print information messages.")

    results = parser.parse_args(params)

    from boutiques.publisher import Publisher
    publisher = Publisher(results.boutiques_descriptor, results.verbose,
                          results.sandbox, results.no_int,
                          results.zenodo_token)
    publisher.publish()
    if hasattr(publisher, 'doi'):
        return publisher.doi
Esempio n. 4
0
def publish(*params):
    neurolinks_github_repo_url = "https://github.com/brainhack101/neurolinks"
    neurolinks_dest_path = os.path.join(os.getenv("HOME"), "neurolinks")

    def get_neurolinks_default():
        if os.path.isdir(neurolinks_dest_path):
            return neurolinks_dest_path
        return neurolinks_github_repo_url

    parser = ArgumentParser(
        "Boutiques publisher",
        description="A publisher of Boutiques tools in Neurolinks"
        "(https://brainhack101.github.io/neurolinks). Crawls a Git"
        "repository for valid Boutiques descriptors and imports them"
        "in Neurolinks format. Uses your GitHub account to fork the "
        "Neurolinks repository and commit new tools in it. Requires "
        "that your GitHub ssh key is configured and usable without"
        "password.")
    parser.add_argument(
        "boutiques_repo",
        action="store",
        help="Local path to a Git repository containing Boutiques "
        "descriptors to publish.")
    parser.add_argument("author_name",
                        action="store",
                        help="Default author name.")
    parser.add_argument("tool_url", action="store", help="Default tool URL.")
    parser.add_argument(
        "--neurolinks-repo",
        "-n",
        action="store",
        default=get_neurolinks_default(),
        help="Local path to a Git clone of {0}. Remotes: 'origin' "
        "should point to a writable fork from which a PR will be "
        "initiated; 'base' will be pulled before any update, should "
        "point to {0}. If a URL is provided, will attempt to fork it on"
        " GitHub and clone it to {1}.".format(neurolinks_github_repo_url,
                                              neurolinks_dest_path))
    parser.add_argument(
        "--boutiques-remote",
        "-r",
        action="store",
        default='origin',
        help="Name of Boutiques Git repo remote used to get URLs of"
        " Boutiques descriptor.")
    parser.add_argument(
        "--no-github",
        action="store_true",
        help="Do not interact with GitHub at all (useful for tests).")
    parser.add_argument(
        "--github-login",
        "-u",
        action="store",
        help="GitHub login used to fork, clone and PR to {}. Defaults to"
        " value in $HOME/.pygithub. Saved in $HOME/.pygithub if "
        "specified.".format(neurolinks_github_repo_url))
    parser.add_argument(
        "--github-password",
        "-p",
        action="store",
        help="GitHub password used to fork, clone and PR to {}. Defaults"
        " to value in $HOME/.pygithub. Saved in $HOME/.pygithub if "
        "specified.".format(neurolinks_github_repo_url))
    parser.add_argument(
        "--inter",
        "-i",
        action="store_true",
        default=False,
        help="Interactive mode. Does not use default values everywhere, "
        "checks if URLs are correct or accessible.")

    results = parser.parse_args(params)

    from boutiques.publisher import Publisher
    publisher = Publisher(results.boutiques_repo, results.boutiques_remote,
                          results.author_name, results.tool_url, results.inter,
                          results.neurolinks_repo, neurolinks_dest_path,
                          results.github_login, results.github_password,
                          results.no_github).publish()
Esempio n. 5
0
def deprecate(zenodo_id,
              by_zenodo_id=None,
              sandbox=False,
              verbose=False,
              zenodo_token=None,
              download_function=urlretrieve):

    # Get the descriptor and Zenodo id
    puller = Puller([zenodo_id], verbose=verbose, sandbox=sandbox)
    descriptor_fname = puller.pull()[0]
    descriptor_json = loadJson(descriptor_fname,
                               sandbox=sandbox,
                               verbose=verbose)

    # Return if tool is already deprecated
    deprecated = descriptor_json.get('deprecated-by-doi')
    if deprecated is not None:
        if isinstance(deprecated, str):
            print_info('Tool {0} is already deprecated by {1} '.format(
                zenodo_id, deprecated))
        if by_zenodo_id is not None:
            prompt = ("Tool {0} will be deprecated by {1}, "
                      "this cannot be undone. Are you sure? (Y/n) ")\
                          .format(zenodo_id, by_zenodo_id)
            ret = input(prompt)
            if ret.upper() != "Y":
                return
        else:
            print_warning('Tool {0} is already deprecated'.format(zenodo_id))
            return
    # Set record id and Zenodo id
    zhelper = ZenodoHelper(sandbox=sandbox, no_int=True, verbose=verbose)
    zid = zhelper.get_zid_from_filename(descriptor_fname)
    record_id = zhelper.get_record_id_from_zid(zid)

    # Return if tool has a newer version
    record = zhelper.zenodo_get_record(record_id)
    if not record['metadata']['relations']['version'][0]['is_last']:
        new_version = (record['metadata']['relations']['version'][0]
                       ['last_child']['pid_value'])
        raise_error(
            DeprecateError, 'Tool {0} has a newer version '
            '(zenodo.{1}), it cannot be deprecated.'.format(
                zenodo_id, new_version))
        return

    # Add deprecated property
    if by_zenodo_id is None:
        descriptor_json['deprecated-by-doi'] = True
    else:
        # Check that by_zenodo_id exists
        by_record_id = zhelper.get_record_id_from_zid(by_zenodo_id)
        if zhelper.record_exists(by_record_id) is False:
            raise_error(DeprecateError,
                        "Tool does not exist: {0}".format(by_zenodo_id))
        # Assign deprecated-by property
        by_doi_id = zhelper.get_doi_from_zid(by_zenodo_id)
        descriptor_json['deprecated-by-doi'] = by_doi_id

    # Add doi to descriptor (mandatory for update)
    if descriptor_json.get('doi') is None:
        descriptor_json['doi'] = zhelper.get_doi_from_zid(zid)

    # Save descriptor in temp file
    tmp = tempfile.NamedTemporaryFile(delete=False, mode='w', suffix=".json")
    content = json.dumps(descriptor_json, indent=4, sort_keys=True)
    tmp.write(content)
    tmp.close()

    # Publish updated descriptor
    publisher = Publisher(tmp.name,
                          zenodo_token,
                          replace=True,
                          sandbox=sandbox,
                          no_int=True,
                          id="zenodo." + zid,
                          verbose=verbose)
    return publisher.publish()