Skip to content

Commit

Permalink
Merge pull request #68 from erasche/master
Browse files Browse the repository at this point in the history
Implement recursive shed uploads
  • Loading branch information
jmchilton committed Feb 12, 2015
2 parents 6d06e66 + 701e44f commit 23c8e1d
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions planemo/commands/cmd_shed_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from planemo.io import info
from planemo.io import shell

import fnmatch
import os

tar_path = click.Path(
exists=True,
Expand Down Expand Up @@ -56,8 +58,37 @@
type=tar_path,
default=None,
)
@click.option(
'-r', '--recursive',
is_flag=True,
help="Recursively search for repositories to publish to a tool shed",
)
@pass_context
def cli(ctx, path, **kwds):
"""Handle possible recursion through paths for uploading files to a toolshed
"""
if kwds['recursive']:
if kwds['name'] is not None:
error("--name is incompatible with --recursive")
return -1
if kwds['tar'] is not None:
error("--tar is incompatible with --recursive")
return -1

ret_codes = []
for base_path, dirnames, filenames in os.walk(path):
for filename in fnmatch.filter(filenames, '.shed.yml'):
ret_codes.append(
__handle_upload(ctx, base_path, **kwds)
)
# "Good" returns are Nones, everything else is a -1 and should be
# passed upwards.
return None if all(x is None for x in ret_codes) else -1
else:
return __handle_upload(ctx, path, **kwds)


def __handle_upload(ctx, path, **kwds):
"""Upload a tool directory as a tarball to a tool shed.
"""
tar_path = kwds.get("tar", None)
Expand All @@ -71,10 +102,22 @@ def cli(ctx, path, **kwds):
message = kwds.get("message", None)
if message:
update_kwds["commit_message"] = message
repo_id = shed.find_repository_id(ctx, tsi, path, **kwds)
try:
repo_id = shed.find_repository_id(ctx, tsi, path, **kwds)
except Exception as e:
error("Could not update %s" % path)
try:
error(e.read())
except:
# I've seen a case where the error couldn't be read, so now
# wrapped in try/except
pass
return -1

try:
tsi.repositories.update_repository(repo_id, tar_path, **update_kwds)
except Exception as e:
error("Could not update %s" % path)
error(e.read())
return -1
info("Repository updated successfully.")
info("Repository %s updated successfully." % path)

0 comments on commit 23c8e1d

Please sign in to comment.