Exemplo n.º 1
0
 def _tsi(self):
     tsi = shed.tool_shed_client(
         None,
         shed_target=self.mock_shed.url,
         key="ignored",
     )
     return tsi
Exemplo n.º 2
0
def cli(ctx, paths, **kwds):
    """Update repository in shed from a ``.shed.yml`` file.

    By default this command will update both repository metadata
    from ``.shed.yml`` and upload new contents from the repository
    directory.

    ::

        % planemo shed_update

    This will update the main tool shed with the repository defined
    by a ``.shed.yml`` file in the current working directory. Both
    the location of the ``.shed.yml`` and the tool shed to upload to
    can be easily configured. For instance, the following command can
    be used if ``.shed.yml`` if contained in ``path/to/repo`` and the
    desire is to update the test tool shed.

    ::

        % planemo shed_update --shed_target testtoolshed path/to/repo

    Another important option is ``--check_diff`` - this doesn't affect the
    updating of shed metadata but it will check for differences before
    uploading new contents to the tool shed. This may important because the
    tool shed will automatically populate certain attributes in tool shed
    artifact files (such as ``tool_dependencies.xml``) and this may
    cause unwanted installable revisions to be created when there are no
    important changes.

    The lower-level ``shed_upload`` command should be used instead if
    the repository doesn't define complete metadata in a ``.shed.yml``.
    """
    tsi = shed.tool_shed_client(ctx, **kwds)

    def update(realized_repository):
        upload_ok = True
        if not kwds["skip_upload"]:
            upload_ok = not shed.upload_repository(
                ctx, realized_repository, **kwds
            )
        repo_id = realized_repository.find_repository_id(ctx, tsi)
        metadata_ok = True
        if not kwds["skip_metadata"]:
            metadata_ok = realized_repository.update(ctx, tsi, repo_id)
        if metadata_ok:
            info("Repository metadata updated.")
        else:
            error("Failed to update repository metadata.")
        if metadata_ok and upload_ok:
            return 0
        else:
            error("Failed to update a repository.")
            return 1

    exit_code = shed.for_each_repository(ctx, update, paths, **kwds)
    sys.exit(exit_code)
Exemplo n.º 3
0
def cli(ctx, paths, **kwds):
    """Update repository in shed from a ``.shed.yml`` file.

    By default this command will update both repository metadata
    from ``.shed.yml`` and upload new contents from the repository
    directory.

    ::

        % planemo shed_update

    This will update the main tool shed with the repository defined
    by a ``.shed.yml`` file in the current working directory. Both
    the location of the ``.shed.yml`` and the tool shed to upload to
    can be easily configured. For instance, the following command can
    be used if ``.shed.yml`` if contained in ``path/to/repo`` and the
    desire is to update the test tool shed.

    ::

        % planemo shed_update --shed_target testtoolshed path/to/repo

    Another important option is ``--check_diff`` - this doesn't affect the
    updating of shed metadata but it will check for differences before
    uploading new contents to the tool shed. This may important because the
    tool shed will automatically populate certain attributes in tool shed
    artifact files (such as ``tool_dependencies.xml``) and this may
    cause unwanted installable revisions to be created when there are no
    important changes.

    The lower-level ``shed_upload`` command should be used instead if
    the repository doesn't define complete metadata in a ``.shed.yml``.
    """
    tsi = shed.tool_shed_client(ctx, **kwds)

    def update(realized_repository):
        upload_ok = True
        if not kwds["skip_upload"]:
            upload_ok = not shed.upload_repository(ctx, realized_repository, **
                                                   kwds)
        repo_id = realized_repository.find_repository_id(ctx, tsi)
        metadata_ok = True
        if not kwds["skip_metadata"]:
            metadata_ok = realized_repository.update(ctx, tsi, repo_id)
        if metadata_ok:
            info("Repository metadata updated.")
        else:
            error("Failed to update repository metadata.")
        if metadata_ok and upload_ok:
            return 0
        else:
            error("Failed to update a repository.")
            return 1

    exit_code = shed.for_each_repository(ctx, update, paths, **kwds)
    sys.exit(exit_code)
Exemplo n.º 4
0
def diff_in(ctx, working, path, **kwds):
    shed_target_source = kwds.get("shed_target_source", None)

    label_a = "_%s_" % (shed_target_source if shed_target_source else "local")
    shed_target = kwds.get("shed_target", "B")
    if "/" in shed_target:
        shed_target = "custom_shed"
    label_b = "_%s_" % shed_target

    mine = os.path.join(working, label_a)
    other = os.path.join(working, label_b)

    tsi = shed.tool_shed_client(ctx, read_only=True, **kwds)
    shed.download_tarball(
        ctx,
        tsi,
        path,
        destination=other,
        clean=True,
        **kwds
    )

    if shed_target_source:
        new_kwds = kwds.copy()
        new_kwds["shed_target"] = shed_target_source
        tsi = shed.tool_shed_client(ctx, read_only=True, **new_kwds)
        shed.download_tarball(
            ctx,
            tsi,
            path,
            destination=mine,
            clean=True,
            **new_kwds
        )
    else:
        tar_path = shed.build_tarball(path)
        cmd_template = 'mkdir "%s"; tar -xzf "%s" -C "%s"; rm -rf %s'
        shell(cmd_template % (mine, tar_path, mine, tar_path))

    cmd = 'cd "%s"; diff -r %s %s' % (working, label_a, label_b)
    if kwds["output"]:
        cmd += "> '%s'" % kwds["output"]
    shell(cmd)
Exemplo n.º 5
0
def cli(ctx, paths, **kwds):
    """Download a tool repository as a tarball from the tool shed and extract
    to the specified directory.
    """
    tsi = shed.tool_shed_client(ctx, read_only=True, **kwds)

    def download(realized_repository):
        return shed.download_tarball(ctx, tsi, realized_repository, **kwds)

    exit_code = shed.for_each_repository(ctx, download, paths, **kwds)
    sys.exit(exit_code)
Exemplo n.º 6
0
def cli(ctx, paths, **kwds):
    """Download a tool repository as a tarball from the tool shed and extract
    to the specified directory.
    """
    tsi = shed.tool_shed_client(ctx, read_only=True, **kwds)

    def download(realized_repository):
        return shed.download_tarball(ctx, tsi, realized_repository, **kwds)

    exit_code = shed.for_each_repository(ctx, download, paths, **kwds)
    sys.exit(exit_code)
Exemplo n.º 7
0
def __handle_upload(ctx, realized_repository, **kwds):
    """Upload a tool directory as a tarball to a tool shed.
    """
    path = realized_repository.path
    tar_path = kwds.get("tar", None)
    if not tar_path:
        tar_path = shed.build_tarball(path, **kwds)
    if kwds["tar_only"]:
        suffix = ""
        if realized_repository.multiple:
            name = realized_repository.config["name"]
            suffix = "_%s" % name.replace("-", "_")
        shell("cp %s shed_upload%s.tar.gz" % (tar_path, suffix))
        return 0
    tsi = shed.tool_shed_client(ctx, **kwds)
    update_kwds = {}
    message = kwds.get("message", None)
    if message:
        update_kwds["commit_message"] = message

    # TODO: this needs to use realized repository
    repo_id = realized_repository.find_repository_id(ctx, tsi)
    if repo_id is None and kwds["force_repository_creation"]:
        repo_id = realized_repository.create(ctx, tsi)
    # failing to create the repo, give up
    if repo_id is None:
        return -1
    # TODO: support updating repo information if it changes in the config file

    try:
        tsi.repositories.update_repository(repo_id, tar_path, **update_kwds)
    except Exception as e:
        exception_content = e.read()
        try:
            # Galaxy passes nice JSON messages as their errors, which bioblend
            # blindly returns. Attempt to parse those.
            upstream_error = json.loads(exception_content)
            error(upstream_error['err_msg'])
        except Exception as e2:
            error("Could not update %s" % realized_repository.name)
            error(exception_content)
            error(e2.read())
        return -1
    info("Repository %s updated successfully." % realized_repository.name)
    return 0
Exemplo n.º 8
0
def cli(ctx, path, **kwds):
    """Create a repository in a Galaxy Tool Shed from a ``.shed.yml`` file.
    """
    tsi = shed.tool_shed_client(ctx, **kwds)

    def create(realized_reposiotry):
        repo_id = realized_reposiotry.find_repository_id(ctx, tsi)
        if repo_id is None:
            if realized_reposiotry.create(ctx, tsi):
                info("Repository created")
                return 0
            else:
                return 2
        else:
            return 1

    exit_code = shed.for_each_repository(create, path, **kwds)
    sys.exit(exit_code)
Exemplo n.º 9
0
def __handle_upload(ctx, path, **kwds):
    """Upload a tool directory as a tarball to a tool shed.
    """
    tar_path = kwds.get("tar", None)
    if not tar_path:
        tar_path = shed.build_tarball(path, **kwds)
    if kwds["tar_only"]:
        shell("cp %s shed_upload.tar.gz" % tar_path)
        return 0
    tsi = shed.tool_shed_client(ctx, **kwds)
    update_kwds = {}
    message = kwds.get("message", None)
    if message:
        update_kwds["commit_message"] = message
    repo_id = __find_repository(ctx, tsi, path, **kwds)
    if repo_id is None and kwds["force_repository_creation"]:
        repo_id = __create_repository(ctx, tsi, path, **kwds)
    # failing to create the repo, give up
    if repo_id is None:
        return -1
    # TODO: support updating repo information if it changes in the config file

    try:
        tsi.repositories.update_repository(repo_id, tar_path, **update_kwds)
    except Exception as e:
        exception_content = e.read()
        try:
            # Galaxy passes nice JSON messages as their errors, which bioblend
            # blindly returns. Attempt to parse those.
            upstream_error = json.loads(exception_content)
            error(upstream_error['err_msg'])
        except Exception as e2:
            error("Could not update %s" % path)
            error(exception_content)
            error(e2.read())
        return -1
    info("Repository %s updated successfully." % path)
    return 0
Exemplo n.º 10
0
def mock_shed_client():
    with mock_shed() as mock_shed_obj:
        yield shed.tool_shed_client(shed_target=mock_shed_obj.url)
Exemplo n.º 11
0
def cli(ctx, path, **kwds):
    """Download a tool repository as a tarball from the tool shed and extract
    to the specified directory.
    """
    tsi = shed.tool_shed_client(ctx, read_only=True, **kwds)
    shed.download_tarball(ctx, tsi, path, **kwds)
Exemplo n.º 12
0
def cli(ctx, path, **kwds):
    """Download a tool repository as a tarball from the tool shed and extract
    to the specified directory.
    """
    tsi = shed.tool_shed_client(ctx, read_only=True, **kwds)
    shed.download_tarball(ctx, tsi, path, **kwds)