Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement recursive shed uploads #68

Merged
merged 3 commits into from
Feb 12, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)