Skip to content
Merged
Show file tree
Hide file tree
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
50 changes: 50 additions & 0 deletions planemo/commands/cmd_shed_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@
from planemo import options
from planemo import shed
from planemo.io import info, error
from planemo.reports import build_report


@click.command("shed_update")
@click.option(
"--report_xunit",
type=click.Path(file_okay=True, resolve_path=True),
help="Output update as a faked XUnit report, useful when you want to "
"automatically update repositories in bulk.",
default=None,
)
@options.shed_publish_options()
@options.shed_upload_options()
@options.shed_skip_upload()
Expand Down Expand Up @@ -49,9 +57,23 @@ def cli(ctx, paths, **kwds):
The lower-level ``shed_upload`` command should be used instead if
the repository doesn't define complete metadata in a ``.shed.yml``.
"""
# In a little bit of cheating, we're defining this variable here to collect
# a "report" on the shed_update command
collected_data = {
'results': {
'total': 0,
'errors': 0,
'failures': 0,
'skips': 0,
},
'tests': [],
}

shed_context = shed.get_shed_context(ctx, **kwds)


def update(realized_repository):
collected_data['results']['total'] += 1
upload_ret_code = 0
upload_ok = True
if not kwds["skip_upload"]:
Expand All @@ -60,6 +82,11 @@ def update(realized_repository):
)
upload_ok = not upload_ret_code
if upload_ret_code == 2:
collected_data['results']['failures'] += 1
collected_data['tests'].append({
'classname': realized_repository.name,
'result': 2,
})
error("Failed to update repository it does not exist "
"in target ToolShed.")
return upload_ret_code
Expand All @@ -72,10 +99,33 @@ def update(realized_repository):
else:
error("Failed to update repository metadata.")
if metadata_ok and upload_ok:
collected_data['tests'].append({
'classname': realized_repository.name,
'result': 0,
})
return 0
elif upload_ok:
collected_data['results']['skips'] += 1
collected_data['tests'].append({
'classname': realized_repository.name,
'result': 3,
})
error("Repo updated but metadata was not.")
return 1
else:
collected_data['results']['failures'] += 1
collected_data['tests'].append({
'classname': realized_repository.name,
'result': 1,
})
error("Failed to update a repository.")
return 1

exit_code = shed.for_each_repository(ctx, update, paths, **kwds)

if kwds.get('report_xunit', False):
with open(kwds['report_xunit'], 'w') as handle:
handle.write(build_report.template_data(
collected_data, template_name='update_xunit.tpl'))

sys.exit(exit_code)
27 changes: 27 additions & 0 deletions planemo/reports/update_xunit.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="planemoupdate"
tests="{{ results.total }}"
errors="{{ results.errors }}"
failures="{{ results.failures }}"
skip="{{ results.skips }}">
{% for testcase in tests %}
<testcase classname="{{ testcase.classname }}" name="recursive_update" time="{{ testcase.time }}">
{% if testcase.result == 1 %}
<error type="planemo.FailedUpdate" message="Failed to update repository">
</error>
{% endif %}
{% if testcase.result == 2 %}
<error type="planemo.RepoDoesNotExit" message="Target repository does not exist">
</error>
{% endif %}
{% if testcase.result == 3 %}
<error type="planemo.FailedMetadata" message="Failed to update repo metadata">
</error>
{% endif %}
{% if testcase.result > 3 %}
<error type="planemo.UpdateError" message="Error executing update">
</error>
{% endif %}
</testcase>
{% endfor %}
</testsuite>