Skip to content

Commit

Permalink
Refactor most of cmd_shed_diff into planemo.shed.
Browse files Browse the repository at this point in the history
Trying to trim down the command files - I think the analogy to thin controllers is good.
  • Loading branch information
jmchilton committed May 1, 2015
1 parent 40a1f57 commit ffa4e28
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 49 deletions.
49 changes: 1 addition & 48 deletions planemo/commands/cmd_shed_diff.py
@@ -1,14 +1,12 @@
"""
"""
import os
import shutil
import tempfile
import sys

import click

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

Expand Down Expand Up @@ -55,54 +53,9 @@ def cli(ctx, path, **kwds):
def diff(realized_repository):
working = tempfile.mkdtemp(prefix="tool_shed_diff_")
try:
diff_in(ctx, working, realized_repository, **kwds)
shed.diff_in(ctx, working, realized_repository, **kwds)
finally:
shutil.rmtree(working)

exit_code = shed.for_each_repository(diff, path, **kwds)
sys.exit(exit_code)


def diff_in(ctx, working, realized_repository, **kwds):
path = realized_repository.path
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,
realized_repository,
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,
realized_repository,
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)
47 changes: 46 additions & 1 deletion planemo/shed/__init__.py
Expand Up @@ -178,6 +178,51 @@ def upload_repository(ctx, realized_repository, **kwds):
return 0


def diff_in(ctx, working, realized_repository, **kwds):
path = realized_repository.path
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 = tool_shed_client(ctx, read_only=True, **kwds)
download_tarball(
ctx,
tsi,
realized_repository,
destination=other,
clean=True,
**kwds
)
if shed_target_source:
new_kwds = kwds.copy()
new_kwds["shed_target"] = shed_target_source
tsi = tool_shed_client(ctx, read_only=True, **new_kwds)
download_tarball(
ctx,
tsi,
realized_repository,
destination=mine,
clean=True,
**new_kwds
)
else:
tar_path = 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)


def shed_repo_config(path, name=None):
shed_yaml_path = os.path.join(path, SHED_CONFIG_NAME)
config = {}
Expand Down Expand Up @@ -880,7 +925,7 @@ def _build_error(descript):
'for_each_repository',
'api_exception_to_message',
'tool_shed_client',
'build_tarball',
'diff_in',
'download_tarball',
'shed_init',
'CURRENT_CATEGORIES',
Expand Down

0 comments on commit ffa4e28

Please sign in to comment.