Skip to content

Commit 40a1f57

Browse files
committed
Update shed_diff and shed_download for multi-repo-shed-yamls.
- Both realize repositories for configuration. - Both can now take in -r/--recursive arguments. - Download will attempt to download many repositories at once. - shed_diff now operates properly on the realized files instead of the local directory. Still need to do a "smart diff" that filters out toolshed and changeset_revision attributes before #141 can be closed.
1 parent 3a76f02 commit 40a1f57

File tree

5 files changed

+97
-32
lines changed

5 files changed

+97
-32
lines changed

planemo/commands/cmd_shed_diff.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import shutil
55
import tempfile
6+
import sys
67

78
import click
89

@@ -30,6 +31,7 @@
3031
" this to testtoolshed.",
3132
default=None,
3233
)
34+
@options.recursive_shed_option()
3335
@pass_context
3436
def cli(ctx, path, **kwds):
3537
"""Produce diff between local repository and Tool Shed contents.
@@ -50,14 +52,19 @@ def cli(ctx, path, **kwds):
5052
% planemo shed_diff --owner peterjc --name blast_rbh
5153
--shed_target_source testtoolshed
5254
"""
53-
working = tempfile.mkdtemp(prefix="tool_shed_diff_")
54-
try:
55-
diff_in(ctx, working, path, **kwds)
56-
finally:
57-
shutil.rmtree(working)
55+
def diff(realized_repository):
56+
working = tempfile.mkdtemp(prefix="tool_shed_diff_")
57+
try:
58+
diff_in(ctx, working, realized_repository, **kwds)
59+
finally:
60+
shutil.rmtree(working)
5861

62+
exit_code = shed.for_each_repository(diff, path, **kwds)
63+
sys.exit(exit_code)
5964

60-
def diff_in(ctx, working, path, **kwds):
65+
66+
def diff_in(ctx, working, realized_repository, **kwds):
67+
path = realized_repository.path
6168
shed_target_source = kwds.get("shed_target_source", None)
6269

6370
label_a = "_%s_" % (shed_target_source if shed_target_source else "local")
@@ -73,20 +80,19 @@ def diff_in(ctx, working, path, **kwds):
7380
shed.download_tarball(
7481
ctx,
7582
tsi,
76-
path,
83+
realized_repository,
7784
destination=other,
7885
clean=True,
7986
**kwds
8087
)
81-
8288
if shed_target_source:
8389
new_kwds = kwds.copy()
8490
new_kwds["shed_target"] = shed_target_source
8591
tsi = shed.tool_shed_client(ctx, read_only=True, **new_kwds)
8692
shed.download_tarball(
8793
ctx,
8894
tsi,
89-
path,
95+
realized_repository,
9096
destination=mine,
9197
clean=True,
9298
**new_kwds

planemo/commands/cmd_shed_download.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""
22
"""
3+
import sys
4+
35
import click
46

57
from planemo.cli import pass_context
@@ -19,17 +21,26 @@
1921
'--destination',
2022
default="shed_download.tar.gz",
2123
type=target_path,
22-
help="Destination of tarball to download - if this doesn't end in 'gz' it "
23-
"will be treated as a directory to extract tool contents into"
24-
"(defaults to shed_download.tar.gz)."
24+
help="Destination pattern of tarball(s) to download - if this doesn't "
25+
"end in 'gz' it will be treated as a directory to extract tool "
26+
"contents into (defaults to shed_download.tar.gz). If multiple "
27+
"repositories are discovered in a .shed.yml file these will be "
28+
"created as shed_download_<name>.tar.gz by default for instance, "
29+
"simpler repositories will just be downloaded to the specified file."
2530
)
2631
@options.shed_owner_option()
2732
@options.shed_name_option()
2833
@options.shed_target_option()
34+
@options.recursive_shed_option()
2935
@pass_context
3036
def cli(ctx, path, **kwds):
3137
"""Download a tool repository as a tarball from the tool shed and extract
3238
to the specified directory.
3339
"""
3440
tsi = shed.tool_shed_client(ctx, read_only=True, **kwds)
35-
shed.download_tarball(ctx, tsi, path, **kwds)
41+
42+
def download(realized_repository):
43+
return shed.download_tarball(ctx, tsi, realized_repository, **kwds)
44+
45+
exit_code = shed.for_each_repository(download, path, **kwds)
46+
sys.exit(exit_code)

planemo/shed/__init__.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,8 @@ def upload_repository(ctx, realized_repository, **kwds):
150150
if not tar_path:
151151
tar_path = build_tarball(path, **kwds)
152152
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))
153+
name = realized_repository.pattern_to_file_name("shed_upload.tar.gz")
154+
shell("cp '%s' '%s'" % (tar_path, name))
158155
return 0
159156
tsi = tool_shed_client(ctx, **kwds)
160157
update_kwds = {}
@@ -377,9 +374,10 @@ def create_repository_for(ctx, tsi, name, repo_config):
377374
return repo
378375

379376

380-
def download_tarball(ctx, tsi, path, **kwds):
381-
repo_id = find_repository_id(ctx, tsi, path, **kwds)
382-
destination = kwds.get('destination', 'shed_download.tar.gz')
377+
def download_tarball(ctx, tsi, realized_repository, **kwds):
378+
repo_id = realized_repository.find_repository_id(ctx, tsi)
379+
destination_pattern = kwds.get('destination', 'shed_download.tar.gz')
380+
destination = realized_repository.pattern_to_file_name(destination_pattern)
383381
to_directory = not destination.endswith("gz")
384382
download_tar(tsi, repo_id, destination, to_directory=to_directory)
385383
if to_directory:
@@ -778,6 +776,19 @@ def __init__(self, realized_path, real_path, config, multiple):
778776
self.name = config["name"]
779777
self.multiple = multiple
780778

779+
def pattern_to_file_name(self, pattern):
780+
if not self.multiple:
781+
return pattern
782+
783+
name = self.config["name"]
784+
suffix = "_%s" % name.replace("-", "_")
785+
786+
if "." not in pattern:
787+
return pattern + suffix
788+
else:
789+
parts = pattern.split(".", 1)
790+
return parts[0] + suffix + "." + parts[1]
791+
781792
def find_repository_id(self, ctx, tsi):
782793
try:
783794
repo_id = _find_repository_id(

tests/test_shed_download.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from os.path import join
2+
3+
from .test_utils import CliShedTestCase
4+
from .test_shed_upload import assert_exists
5+
6+
7+
class ShedUploadTestCase(CliShedTestCase):
8+
9+
def test_download_expansion_tars(self):
10+
with self._isolate_repo("multi_repos_flat_flag") as f:
11+
upload_command = [
12+
"shed_upload", "--force_repository_creation"
13+
]
14+
upload_command.extend(self._shed_args())
15+
self._check_exit_code(upload_command)
16+
download_command = [
17+
"shed_download",
18+
]
19+
download_command.extend(self._shed_args(read_only=True))
20+
self._check_exit_code(download_command)
21+
assert_exists(join(f, "shed_download_cs_cat1.tar.gz"))
22+
assert_exists(join(f, "shed_download_cs_cat2.tar.gz"))
23+
24+
def test_download_expansion_dir(self):
25+
with self._isolate_repo("multi_repos_flat_flag") as f:
26+
upload_command = [
27+
"shed_upload", "--force_repository_creation"
28+
]
29+
upload_command.extend(self._shed_args())
30+
self._check_exit_code(upload_command)
31+
download_command = [
32+
"shed_download", "--destination", "shed_d"
33+
]
34+
download_command.extend(self._shed_args(read_only=True))
35+
self._check_exit_code(download_command)
36+
assert_exists(join(f, "shed_d_cs_cat1", "cat1.xml"))
37+
assert_exists(join(f, "shed_d_cs_cat2", "cat2.xml"))

tests/test_shed_upload.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_tar_single(self):
1616
upload_command = ["shed_upload", "--tar_only"]
1717
upload_command.extend(self._shed_args())
1818
self._check_exit_code(upload_command)
19-
_assert_exists(join(f, "shed_upload.tar.gz"))
19+
assert_exists(join(f, "shed_upload.tar.gz"))
2020

2121
def test_upload_not_exists(self):
2222
with self._isolate_repo("single_tool"):
@@ -68,7 +68,7 @@ def test_upload_filters_invalid_suite(self):
6868
self._check_exit_code(upload_command)
6969
target = self._untar(f, "shed_upload.tar.gz")
7070
# Only one file was in archive
71-
_assert_exists(join(target, "repository_dependencies.xml"))
71+
assert_exists(join(target, "repository_dependencies.xml"))
7272
# this got filtered
7373
assert not exists(join(target, "README.rst"))
7474

@@ -79,7 +79,7 @@ def test_upload_suite_auto(self):
7979
self._check_exit_code(upload_command)
8080
target = self._untar(f, "shed_upload_suite_1.tar.gz")
8181
# Only one file was in archive
82-
_assert_exists(join(target, "repository_dependencies.xml"))
82+
assert_exists(join(target, "repository_dependencies.xml"))
8383

8484
def test_upload_filters_ignore(self):
8585
with self._isolate_repo("single_tool_exclude") as f:
@@ -120,7 +120,7 @@ def test_upload_filters_invalid_package(self):
120120
self._check_exit_code(upload_command)
121121
target = self._untar(f, "shed_upload.tar.gz")
122122
# Only one file was in archive
123-
_assert_exists(join(target, "tool_dependencies.xml"))
123+
assert_exists(join(target, "tool_dependencies.xml"))
124124
# this got filtered
125125
assert not exists(join(target, "README.rst"))
126126
# .shed.yml always gets filtered
@@ -133,8 +133,8 @@ def test_upload_not_filters_unrestricted(self):
133133
self._check_exit_code(upload_command)
134134
target = self._untar(f, "shed_upload.tar.gz")
135135
# Only one file was in archive
136-
_assert_exists(join(target, "repository_dependencies.xml"))
137-
_assert_exists(join(target, "README.rst"))
136+
assert_exists(join(target, "repository_dependencies.xml"))
137+
assert_exists(join(target, "README.rst"))
138138

139139
def test_upload_expansion_configured(self):
140140
with self._isolate_repo("multi_repos_flat_configured") as f:
@@ -205,15 +205,15 @@ def _verify_single_uploaded(self, f):
205205
def _verify_upload(self, f, download_files=[], download_args=[]):
206206
target = self._download_repo(f, download_args)
207207
for download_file in download_files:
208-
_assert_exists(join(target, download_file))
208+
assert_exists(join(target, download_file))
209209
return target
210210

211211
def _check_tar(self, f, tar_path, contains=[], not_contains=[]):
212212
tar_path = join(f, tar_path)
213-
_assert_exists(tar_path)
213+
assert_exists(tar_path)
214214
target = self._untar(f, tar_path)
215215
for path in contains:
216-
_assert_exists(join(target, path))
216+
assert_exists(join(target, path))
217217
for path in not_contains:
218218
assert not exists(join(target, path))
219219
return target
@@ -224,7 +224,7 @@ def _download_repo(self, f, download_args=[]):
224224
download_command.extend(self._shed_args(read_only=True))
225225
self._check_exit_code(download_command)
226226
download = join(f, "shed_download.tar.gz")
227-
_assert_exists(download)
227+
assert_exists(download)
228228
return self._untar(f, "shed_download.tar.gz", tarbomb=False)
229229

230230
def _untar(self, f, path, tarbomb=True):
@@ -247,7 +247,7 @@ def _untar(self, f, path, tarbomb=True):
247247
return target
248248

249249

250-
def _assert_exists(path):
250+
def assert_exists(path):
251251
dir_path = os.path.dirname(path)
252252
msg = None
253253
if not exists(dir_path):

0 commit comments

Comments
 (0)