-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsummary.py
64 lines (53 loc) · 2.09 KB
/
summary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -----------------------------------------------------------------------------
# Copyright (c) 2016, Ming Wang.
#
# Distributed under the terms of the BSD 3-clause License License.
#
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------
from os.path import join
def generate_html_summary(qclient, job_id, parameters, out_dir):
"""Generates the HTML summary of an artifact
Parameters
----------
qclient : qiita_client.QiitaClient
The Qiita server client
job_id : str
The job id
parameters : dict
The parameter values to validate and create the artifact
out_dir : str
The path to the job's output directory
Returns
-------
bool, None, str
Whether the job is successful
Ignored
The error message, if not successful
"""
# Step 1: gather file information from qiita using REST api
qclient.update_job_step(job_id, "Step 1: Gathering information from Qiita")
# This is the only parameter provided by Qiita: the artifact id. From here,
# the developer should be able to retrieve any further information needed
# to generate the HTML summary
artifact_id = parameters['input_data']
print(artifact_id)
qclient_url = "/qiita_db/artifacts/%s/" % artifact_id
artifact_info = qclient.get(qclient_url)
# Get the artifact files
artifact_files = artifact_info['files']
# Step 2: generate HTML summary
# TODO: Generate the HTML summary and store it in html_summary_fp
qclient.update_job_step(job_id, "Step 2: Generating HTML summary")
html_summary_fp = join(out_dir, "summary.html")
# Step 3: add the new file to the artifact using REST api
qclient.update_job_step(job_id, "Step 3: Transferring summary to Qiita")
success = True
error_msg = ""
try:
qclient.patch(qclient_url, 'add', '/html_summary/',
value=html_summary_fp)
except Exception as e:
success = False
error_msg = str(e)
return success, None, error_msg