Skip to content

Commit 3a76f02

Browse files
committed
Refactor most of cmd_shed_upload logic into planemo.shed.
Trying to trim down the command files - I think the analogy to thin controllers is good. Also want to reuse the logic related converting the pattern shed_upload.tar.gz to shed_upload_<repo_name>.tar.gz when .shed.yml map to multiple repositories.
1 parent c18b7a9 commit 3a76f02

2 files changed

Lines changed: 42 additions & 44 deletions

File tree

planemo/commands/cmd_shed_upload.py

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
from planemo.cli import pass_context
88
from planemo import options
99
from planemo import shed
10-
from planemo.io import error
11-
from planemo.io import info
12-
from planemo.io import shell
1310

1411

1512
tar_path = click.Path(
@@ -57,47 +54,7 @@ def cli(ctx, path, **kwds):
5754
"""Handle possible recursion through paths for uploading files to a toolshed
5855
"""
5956
def upload(realized_repository):
60-
return __handle_upload(ctx, realized_repository, **kwds)
57+
return shed.upload_repository(ctx, realized_repository, **kwds)
6158

6259
exit_code = shed.for_each_repository(upload, path, **kwds)
6360
sys.exit(exit_code)
64-
65-
66-
def __handle_upload(ctx, realized_repository, **kwds):
67-
"""Upload a tool directory as a tarball to a tool shed.
68-
"""
69-
path = realized_repository.path
70-
tar_path = kwds.get("tar", None)
71-
if not tar_path:
72-
tar_path = shed.build_tarball(path, **kwds)
73-
if kwds["tar_only"]:
74-
suffix = ""
75-
if realized_repository.multiple:
76-
name = realized_repository.config["name"]
77-
suffix = "_%s" % name.replace("-", "_")
78-
shell("cp %s shed_upload%s.tar.gz" % (tar_path, suffix))
79-
return 0
80-
tsi = shed.tool_shed_client(ctx, **kwds)
81-
update_kwds = {}
82-
message = kwds.get("message", None)
83-
if message:
84-
update_kwds["commit_message"] = message
85-
86-
# TODO: this needs to use realized repository
87-
repo_id = realized_repository.find_repository_id(ctx, tsi)
88-
if repo_id is None and kwds["force_repository_creation"]:
89-
repo_id = realized_repository.create(ctx, tsi)
90-
# failing to create the repo, give up
91-
if repo_id is None:
92-
return -1
93-
# TODO: support updating repo information if it changes in the config file
94-
95-
try:
96-
tsi.repositories.update_repository(repo_id, tar_path, **update_kwds)
97-
except Exception as e:
98-
message = shed.api_exception_to_message(e)
99-
error("Could not update %s" % realized_repository.name)
100-
error(message)
101-
return -1
102-
info("Repository %s updated successfully." % realized_repository.name)
103-
return 0

planemo/shed/__init__.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
from planemo.io import (
1818
error,
19+
shell,
20+
info,
1921
can_write_to_path,
2022
)
2123
from planemo import glob
@@ -140,6 +142,45 @@ def shed_init(ctx, path, **kwds):
140142
return 0
141143

142144

145+
def upload_repository(ctx, realized_repository, **kwds):
146+
"""Upload a tool directory as a tarball to a tool shed.
147+
"""
148+
path = realized_repository.path
149+
tar_path = kwds.get("tar", None)
150+
if not tar_path:
151+
tar_path = build_tarball(path, **kwds)
152+
if kwds["tar_only"]:
153+
suffix = ""
154+
if realized_repository.multiple:
155+
name = realized_repository.config["name"]
156+
suffix = "_%s" % name.replace("-", "_")
157+
shell("cp %s shed_upload%s.tar.gz" % (tar_path, suffix))
158+
return 0
159+
tsi = tool_shed_client(ctx, **kwds)
160+
update_kwds = {}
161+
message = kwds.get("message", None)
162+
if message:
163+
update_kwds["commit_message"] = message
164+
165+
# TODO: this needs to use realized repository
166+
repo_id = realized_repository.find_repository_id(ctx, tsi)
167+
if repo_id is None and kwds["force_repository_creation"]:
168+
repo_id = realized_repository.create(ctx, tsi)
169+
# failing to create the repo, give up
170+
if repo_id is None:
171+
return -1
172+
# TODO: support updating repo information if it changes in the config file
173+
try:
174+
tsi.repositories.update_repository(repo_id, tar_path, **update_kwds)
175+
except Exception as e:
176+
message = api_exception_to_message(e)
177+
error("Could not update %s" % realized_repository.name)
178+
error(message)
179+
return -1
180+
info("Repository %s updated successfully." % realized_repository.name)
181+
return 0
182+
183+
143184
def shed_repo_config(path, name=None):
144185
shed_yaml_path = os.path.join(path, SHED_CONFIG_NAME)
145186
config = {}

0 commit comments

Comments
 (0)