|
15 | 15 | from future import standard_library |
16 | 16 | from json import dumps |
17 | 17 | import urllib |
18 | | -from qiita_client import QiitaClient |
| 18 | +from qiita_client import QiitaClient, ArtifactInfo |
19 | 19 |
|
20 | 20 | import logging |
21 | 21 |
|
@@ -100,9 +100,45 @@ def __init__(self, name, description, function, required_parameters, |
100 | 100 | self.outputs = outputs |
101 | 101 | self.analysis_only = analysis_only |
102 | 102 |
|
| 103 | + @staticmethod |
| 104 | + def _push_artifacts_files_to_central(qclient, artifacts): |
| 105 | + """Pushes all files of a list of artifacts to BASE_DATA_DIR. |
| 106 | +
|
| 107 | + Parameters |
| 108 | + ---------- |
| 109 | + qclient : qiita_client.QiitaClient |
| 110 | + The Qiita server client |
| 111 | + artifacts : [ArtifactInfo] |
| 112 | + A list of qiita Artifacts |
| 113 | +
|
| 114 | + Returns |
| 115 | + ------- |
| 116 | + The input list of artifacts |
| 117 | + """ |
| 118 | + if artifacts is None: |
| 119 | + return artifacts |
| 120 | + |
| 121 | + for artifact in artifacts: |
| 122 | + if isinstance(artifact, ArtifactInfo): |
| 123 | + for i in range(len(artifact.files)): |
| 124 | + (fp, ftype) = artifact.files[i] |
| 125 | + # send file to Qiita central and potentially update |
| 126 | + # filepath, which is not done at the moment (2025-11-14) |
| 127 | + fp = qclient.push_file_to_central(fp) |
| 128 | + artifact.files[i] = (fp, ftype) |
| 129 | + |
103 | 130 | def __call__(self, qclient, server_url, job_id, output_dir): |
104 | 131 | logger.debug('Entered QiitaCommand.__call__()') |
105 | | - return self.function(qclient, server_url, job_id, output_dir) |
| 132 | + results = self.function( |
| 133 | + qclient, server_url, job_id, output_dir) |
| 134 | + # typical, but not all, functions of QiitaCommands return 3-tuple |
| 135 | + # status=bool, list of artifacts, error_message=str |
| 136 | + if isinstance(results, tuple) and (len(results) == 3) and \ |
| 137 | + isinstance(results[0], bool) and \ |
| 138 | + isinstance(results[1], list) and \ |
| 139 | + isinstance(results[2], str): |
| 140 | + QiitaCommand._push_artifacts_files_to_central(qclient, results[1]) |
| 141 | + return results |
106 | 142 |
|
107 | 143 |
|
108 | 144 | class QiitaArtifactType(object): |
|
0 commit comments