Skip to content

Commit

Permalink
Merge pull request #33 from galaxyproject/shed_diff
Browse files Browse the repository at this point in the history
Implement shed_diff.
  • Loading branch information
jmchilton committed Dec 6, 2014
2 parents 8a8cf22 + ae6e2ee commit 3f8de7a
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 39 deletions.
1 change: 1 addition & 0 deletions docs/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ documentation describes these commands.
.. include:: commands/lint.rst
.. include:: commands/project_init.rst
.. include:: commands/serve.rst
.. include:: commands/shed_diff.rst
.. include:: commands/shed_upload.rst
.. include:: commands/syntax.rst
.. include:: commands/test.rst
Expand Down
47 changes: 47 additions & 0 deletions docs/commands/shed_diff.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

``shed_diff`` command
===============================

This section is auto-generated from the help text for the planemo command
``shed_diff``. This help message can be generated with ``planemo shed_diff
--help``.

**Usage**::

planemo shed_diff [OPTIONS] PROJECT

**Help**

Produce diff between local repository and Tool Shed contents.

By default, this will produce a diff between this repository and what
would be uploaded to the Tool Shed with the `shed_upload` command - but
this command can be made to compare other combinations of repositories.
Here are some examples::

% # diff for this repository and the main Tool Shed
% planemo shed_diff
% # diff for this repository and the test Tool Shed
% planemo shed_diff --shed_target testtoolshed
% # diff for the test Tool Shed and main Tool Shed
% planemo shed_diff --shed_target_source testtoolshed
% # diff for two an explicitly specified repositories (ignores
% # current project's shed YAML file.)
% planemo shed_diff --owner peterjc --name blast_rbh
--shed_target_source testtoolshed

**Options**::


--owner TEXT Tool Shed repository owner (username).
--name TEXT Tool Shed repository name (defaults to the
inferred tool directory name).
--shed_target TEXT Tool Shed to target (this can be 'toolshed',
'testtoolshed', 'local' (alias for
http://localhost:9009/) or an arbitraryurl).
--shed_target_source TEXT Source Tool Shed to diff against (will ignore
local project info specified). To compare the
main Tool Shed against the test, set this to
testtoolshed.
--help Show this message and exit.
19 changes: 11 additions & 8 deletions docs/commands/shed_upload.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ Upload a tool directory as a tarball to a tool shed.


--message TEXT Commit message for tool shed upload.
--owner TEXT Tool shed repository owner (username).
--name TEXT Repository name (default to tool directory name).
--shed_target TEXT Tool shed to target (toolshed/testtoolshed/local/url).
--shed_key TEXT API key for shed access (required unless e-mail/pass
specified).
--shed_email TEXT E-mail for shed auth (required unless shed_key is
specified).
--shed_password TEXT Password for shed auth (required unless shed_key is
--owner TEXT Tool Shed repository owner (username).
--name TEXT Tool Shed repository name (defaults to the inferred
tool directory name).
--shed_target TEXT Tool Shed to target (this can be 'toolshed',
'testtoolshed', 'local' (alias for
http://localhost:9009/) or an arbitraryurl).
--shed_key TEXT API key for Tool Shed access (required unless
e-mail/pass specified).
--shed_email TEXT E-mail for Tool Shed auth (required unless shed_key is
specified).
--shed_password TEXT Password for Tool Shed auth (required unless shed_key
is specified).
--tar_only Produce tar file for upload but do not publish to a
tool shed.
--tar PATH Specify a pre-existing tar file instead of
Expand Down
14 changes: 4 additions & 10 deletions planemo/commands/cmd_project_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

from planemo.cli import pass_context
from planemo import options
from planemo.io import warn, shell
from galaxy.tools.deps.commands import which
from planemo.io import warn, untar_to

SOURCE_HOST = "https://codeload.github.com"
DOWNLOAD_URL = "%s/galaxyproject/planemo/tar.gz/master" % SOURCE_HOST
UNTAR_FILTER = "--strip-components=3 --wildcards --no-anchored '%s/**'"
UNTAR_CMD = "tar -C %s -zxvf - " + UNTAR_FILTER
UNTAR_ARGS = "-C %s -zxvf - " + UNTAR_FILTER


@click.command("project_init")
Expand All @@ -32,10 +31,5 @@ def cli(ctx, path, template=None, **kwds):
if template is None:
return

if which("wget"):
download_cmd = "wget -O - %s"
else:
download_cmd = "curl %s"
download_cmd = download_cmd % DOWNLOAD_URL
untar_cmd = UNTAR_CMD % (path, template)
shell("%s | %s" % (download_cmd, untar_cmd))
untar_args = UNTAR_ARGS % (path, template)
untar_to(DOWNLOAD_URL, path, untar_args)
90 changes: 90 additions & 0 deletions planemo/commands/cmd_shed_diff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""
"""
import os
import shutil
import tempfile

import click

from planemo.cli import pass_context
from planemo.io import shell
from planemo import options
from planemo import shed


@click.command("shed_diff")
@options.optional_project_arg(exists=True)
@options.shed_owner_option()
@options.shed_name_option()
@options.shed_target_option()
@click.option(
'--shed_target_source',
help="Source Tool Shed to diff against (will ignore local project info"
" specified). To compare the main Tool Shed against the test, set"
" this to testtoolshed.",
default=None,
)
@pass_context
def cli(ctx, path, **kwds):
"""Produce diff between local repository and Tool Shed contents.
By default, this will produce a diff between this repository and what
would be uploaded to the Tool Shed with the `shed_upload` command - but
this command can be made to compare other combinations of repositories.
Here are some examples::
% # diff for this repository and the main Tool Shed
% planemo shed_diff
% # diff for this repository and the test Tool Shed
% planemo shed_diff --shed_target testtoolshed
% # diff for the test Tool Shed and main Tool Shed
% planemo shed_diff --shed_target_source testtoolshed
% # diff for two an explicitly specified repositories (ignores
% # current project's shed YAML file.)
% planemo shed_diff --owner peterjc --name blast_rbh
--shed_target_source testtoolshed
"""
working = tempfile.mkdtemp(prefix="tool_shed_diff_")
try:
diff_in(ctx, working, path, **kwds)
finally:
shutil.rmtree(working)


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")
label_b = "_%s_" % kwds.get("shed_target", "B")

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))

shell('cd "%s"; diff -r %s %s' % (working, label_a, label_b))
35 changes: 35 additions & 0 deletions planemo/commands/cmd_shed_download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
"""
import click

from planemo.cli import pass_context
from planemo import options
from planemo import shed

target_path = click.Path(
file_okay=True,
writable=True,
resolve_path=True,
)


@click.command("shed_download")
@options.optional_project_arg(exists=True)
@click.option(
'--destination',
default="shed_download.tar.gz",
type=target_path,
help="Destination of tarball to download - if this doesn't end in 'gz' it "
"will be treated as a directory to extract tool contents into"
"(defaults to shed_download.tar.gz)."
)
@options.shed_owner_option()
@options.shed_name_option()
@options.shed_target_option()
@pass_context
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)
27 changes: 10 additions & 17 deletions planemo/commands/cmd_shed_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,23 @@
'--message',
help="Commit message for tool shed upload."
)
@click.option(
'--owner',
help="Tool shed repository owner (username)."
)
@click.option(
'--name',
help="Repository name (default to tool directory name)."
)
@click.option(
'--shed_target',
help="Tool shed to target (toolshed/testtoolshed/local/url).",
default="toolshed",
)
@options.shed_owner_option()
@options.shed_name_option()
@options.shed_target_option()
@click.option(
'--shed_key',
help="API key for shed access (required unless e-mail/pass specified)."
help="API key for Tool Shed access (required unless e-mail/pass "
"specified)."
)
@click.option(
'--shed_email',
help="E-mail for shed auth (required unless shed_key is specified)."
help="E-mail for Tool Shed auth (required unless shed_key is "
"specified)."
)
@click.option(
'--shed_password',
help="Password for shed auth (required unless shed_key is specified)."
help="Password for Tool Shed auth (required unless shed_key is "
"specified)."
)
@click.option(
'--tar_only',
Expand All @@ -64,7 +57,7 @@
default=None,
)
@pass_context
def cli(ctx, path, template=None, **kwds):
def cli(ctx, path, **kwds):
"""Upload a tool directory as a tarball to a tool shed.
"""
tar_path = kwds.get("tar", None)
Expand Down
19 changes: 19 additions & 0 deletions planemo/io.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import os

import click
from galaxy.tools.deps import commands
from galaxy.tools.deps.commands import which


def shell(cmds, **kwds):
Expand All @@ -23,3 +26,19 @@ def warn(message, *args):
if args:
message = message % args
click.echo(click.style(message, fg='red'), err=True)


def untar_to(url, path, tar_args):
if which("wget"):
download_cmd = "wget -q --recursive -O - '%s'"
else:
download_cmd = "curl '%s'"
download_cmd = download_cmd % url
if tar_args:
if not os.path.exists(path):
os.makedirs(path)

untar_cmd = "tar %s" % tar_args
shell("%s | %s" % (download_cmd, untar_cmd))
else:
shell("%s > '%s'" % (download_cmd, path))
25 changes: 25 additions & 0 deletions planemo/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,28 @@ def docker_host_option():
help="Docker host to target when executing docker commands " +
"(defaults to localhost)."
)


def shed_owner_option():
return click.option(
'--owner',
help="Tool Shed repository owner (username)."
)


def shed_name_option():
return click.option(
'--name',
help="Tool Shed repository name (defaults to the inferred "
"tool directory name)."
)


def shed_target_option():
return click.option(
'--shed_target',
help="Tool Shed to target (this can be 'toolshed', 'testtoolshed', "
"'local' (alias for http://localhost:9009/) or an arbitrary"
"url).",
default="toolshed",
)
Loading

0 comments on commit 3f8de7a

Please sign in to comment.