Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/planemo/commands/cmd_shed_update.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 """Module describing the planemo ``shed_update`` command.""" | |
2 import sys | |
3 | |
4 import click | |
5 | |
6 from planemo import options | |
7 from planemo import shed | |
8 from planemo.cli import command_function | |
9 from planemo.io import ( | |
10 captured_io_for_xunit, | |
11 error, | |
12 info, | |
13 ) | |
14 from planemo.reports.xunit_handler import handle_report_xunit_kwd | |
15 | |
16 | |
17 @click.command("shed_update") | |
18 @options.report_xunit() | |
19 @options.shed_publish_options() | |
20 @options.shed_upload_options() | |
21 @options.shed_skip_upload() | |
22 @options.shed_skip_metadata() | |
23 @command_function | |
24 def cli(ctx, paths, **kwds): | |
25 """Update Tool Shed repository. | |
26 | |
27 By default this command will update both repository metadata | |
28 from ``.shed.yml`` and upload new contents from the repository | |
29 directory. | |
30 | |
31 \b | |
32 % planemo shed_update | |
33 | |
34 This will update the main tool shed with the repository defined | |
35 by a ``.shed.yml`` file in the current working directory. Both | |
36 the location of the ``.shed.yml`` and the tool shed to upload to | |
37 can be easily configured. For instance, the following command can | |
38 be used if ``.shed.yml`` if contained in ``path/to/repo`` and the | |
39 desire is to update the test tool shed. | |
40 | |
41 \b | |
42 % planemo shed_update --shed_target testtoolshed path/to/repo | |
43 | |
44 Another important option is ``--check_diff`` - this doesn't affect the | |
45 updating of shed metadata but it will check for differences before | |
46 uploading new contents to the tool shed. This may important because the | |
47 tool shed will automatically populate certain attributes in tool shed | |
48 artifact files (such as ``tool_dependencies.xml``) and this may | |
49 cause unwanted installable revisions to be created when there are no | |
50 important changes. | |
51 | |
52 The lower-level ``shed_upload`` command should be used instead if | |
53 the repository doesn't define complete metadata in a ``.shed.yml``. | |
54 """ | |
55 # In a little bit of cheating, we're defining this variable here to collect | |
56 # a "report" on the shed_update command | |
57 collected_data = { | |
58 'results': { | |
59 'total': 0, | |
60 'errors': 0, | |
61 'failures': 0, | |
62 'skips': 0, | |
63 }, | |
64 'suitename': 'update', | |
65 'tests': [], | |
66 } | |
67 | |
68 shed_context = shed.get_shed_context(ctx, **kwds) | |
69 | |
70 def update(realized_repository): | |
71 collected_data['results']['total'] += 1 | |
72 skip_upload = kwds["skip_upload"] | |
73 skip_metadata = kwds["skip_metadata"] | |
74 upload_ret_code = 0 | |
75 upload_ok = True | |
76 | |
77 captured_io = {} | |
78 if not skip_upload: | |
79 with captured_io_for_xunit(kwds, captured_io): | |
80 upload_ret_code = shed.upload_repository( | |
81 ctx, realized_repository, **kwds | |
82 ) | |
83 upload_ok = not upload_ret_code | |
84 | |
85 repo_result = { | |
86 'classname': realized_repository.name, | |
87 'time': captured_io.get("time", None), | |
88 'name': 'shed-update', | |
89 'stdout': captured_io.get("stdout", None), | |
90 'stderr': captured_io.get("stderr", None), | |
91 } | |
92 | |
93 # Now that we've uploaded (or skipped appropriately), collect results. | |
94 if upload_ret_code == 2: | |
95 collected_data['results']['failures'] += 1 | |
96 message = "Failed to update repository '%s' as it does not exist on the %s." % (realized_repository.name, shed_context.label) | |
97 repo_result.update({ | |
98 'errorType': 'FailedUpdate', | |
99 'errorMessage': message, | |
100 }) | |
101 collected_data['tests'].append(repo_result) | |
102 error(message) | |
103 return upload_ret_code | |
104 | |
105 exit = 0 | |
106 metadata_ok = True | |
107 repository_destination_label = "repository '%s' on the %s" % (realized_repository.name, shed_context.label) | |
108 if not skip_metadata: | |
109 repo_id = shed.handle_force_create(realized_repository, ctx, shed_context, **kwds) | |
110 # failing to create the repo, give up | |
111 if repo_id is None: | |
112 exit = shed.report_non_existent_repository(realized_repository) | |
113 metadata_ok = False | |
114 error("Failed to update metadata for %s." % repository_destination_label) | |
115 else: | |
116 metadata_ok = realized_repository.update(ctx, shed_context, repo_id) | |
117 if metadata_ok: | |
118 info("Repository metadata updated successfully for %s." % repository_destination_label) | |
119 else: | |
120 info("Skipping metadata update for %s" % repository_destination_label) | |
121 | |
122 if metadata_ok and upload_ok: | |
123 pass | |
124 elif upload_ok: | |
125 collected_data['results']['skips'] += 1 | |
126 repo_result.update({ | |
127 'errorType': 'FailedMetadata', | |
128 'errorMessage': 'Failed to update repository metadata', | |
129 }) | |
130 if not skip_upload: | |
131 error("Repository contents updated but failed to update metadata for %s." % repository_destination_label) | |
132 exit = exit or 1 | |
133 else: | |
134 collected_data['results']['failures'] += 1 | |
135 repo_result.update({ | |
136 'errorType': 'FailedUpdate', | |
137 'errorMessage': 'Failed to update repository', | |
138 }) | |
139 if metadata_ok: | |
140 error("Failed to update repository contents for %s." % repository_destination_label) | |
141 else: | |
142 error("Failed to update repository contents and metadata for %s." % repository_destination_label) | |
143 exit = exit or 1 | |
144 collected_data['tests'].append(repo_result) | |
145 return exit | |
146 | |
147 exit_code = shed.for_each_repository(ctx, update, paths, **kwds) | |
148 | |
149 handle_report_xunit_kwd(kwds, collected_data) | |
150 | |
151 sys.exit(exit_code) |