comparison history_metadata_extractor.py @ 1:c7f4f2ac38f2 draft default tip

" master branch Updating"
author lain
date Tue, 09 Aug 2022 15:19:45 +0000
parents 426b0f85a311
children
comparison
equal deleted inserted replaced
0:426b0f85a311 1:c7f4f2ac38f2
7 import json 7 import json
8 import os 8 import os
9 import sys 9 import sys
10 10
11 11
12 with open(os.path.join(sys.path[0], "static", "app.css")) as css: 12 STATIC = os.path.join(sys.path[0], "static")
13 VENDOR = os.path.join(sys.path[0], "vendor")
14
15 with open(os.path.join(STATIC, "app.css")) as css:
13 CSS_STYLES = css.read() 16 CSS_STYLES = css.read()
14 17
15 with open(os.path.join(sys.path[0], "vendor", "bootstrap.min.css")) as bootstrap: 18 with open(os.path.join(VENDOR, "bootstrap.min.css")) as bootstrap:
16 CSS_STYLES = f"{CSS_STYLES}\n{bootstrap.read()}" 19 CSS_STYLES = f"{CSS_STYLES}\n{bootstrap.read()}"
17 20
18 with open(os.path.join(sys.path[0], "static", "app.js")) as js: 21 with open(os.path.join(STATIC, "app.js")) as js:
19 JAVASCRIPT = js.read() 22 JAVASCRIPT = js.read()
20 23
21 with open(os.path.join(sys.path[0], "static", "app.template.html")) as template: 24 with open(os.path.join(STATIC, "app.template.html")) as template:
22 PAGE_TEMPLATE = template.read() 25 PAGE_TEMPLATE = template.read()
23 26
24 with open(os.path.join(sys.path[0], "static", "title.template.html")) as template: 27 with open(os.path.join(STATIC, "title.template.html")) as template:
25 TITLE_TEMPLATE = template.read() 28 TITLE_TEMPLATE = template.read()
26 29
27 with open(os.path.join(sys.path[0], "static", "table.template.html")) as template: 30 with open(os.path.join(STATIC, "table.template.html")) as template:
28 TABLE_TEMPLATE = template.read() 31 TABLE_TEMPLATE = template.read()
29 32
30 with open(os.path.join(sys.path[0], "static", "header_list.template.html")) as template: 33 with open(os.path.join(STATIC, "header_list.template.html")) as template:
31 HEADER_LIST_TEMPLATE = template.read() 34 HEADER_LIST_TEMPLATE = template.read()
32 35
33 HEADER_LIST_TEMPLATE = '\n'.join(( 36 HEADER_LIST_TEMPLATE = '\n'.join((
34 "<thead>", 37 "<thead>",
35 " <tr>", 38 " <tr>",
111 else: 114 else:
112 status = f"Failed ({exit_code})" 115 status = f"Failed ({exit_code})"
113 classes = "alert alert-danger" 116 classes = "alert alert-danger"
114 if hid == "DELETED": 117 if hid == "DELETED":
115 classes += " history_metadata_extractor_deleted" 118 classes += " history_metadata_extractor_deleted"
116 print(job_attr)
117 tool_name = job_attr["tool_id"] or "unknown" 119 tool_name = job_attr["tool_id"] or "unknown"
118 if tool_name.count("/") >= 4: 120 if tool_name.count("/") >= 4:
119 tool_name = job_attr["tool_id"].split("/")[-2] 121 tool_name = job_attr["tool_id"].split("/")[-2]
120 tool_name = tool_name + " - " + job_attr["tool_version"] 122 tool_name = tool_name + " - " + job_attr["tool_version"]
121 tool_name = f"[{hid}] - {tool_name}" 123 tool_name = f"[{hid}] - {tool_name}"
122 return TABLE_TEMPLATE.format( 124 return TABLE_TEMPLATE.format(
123 classes=classes, 125 classes=classes,
124 tool_name=tool_name, 126 tool_name=tool_name,
125 tool_output="",
126 tool_status=status, 127 tool_status=status,
127 table=convert_parameters_to_html(job_attr) 128 table=convert_parameters_to_html(job_attr)
128 ) 129 )
129 130
130 def convert_parameters_to_html(job_attr): 131 def convert_parameters_to_html(job_attr):
138 indent(get_table_header(params, ["value", "name", "extension", "hid"])), 139 indent(get_table_header(params, ["value", "name", "extension", "hid"])),
139 indent(get_table_lines(params, keys)), 140 indent(get_table_lines(params, keys)),
140 )) 141 ))
141 142
142 def params_enrichment(job_attr, params): 143 def params_enrichment(job_attr, params):
143 print(params)
144 if ( 144 if (
145 all(map(params.__contains__, ("request_json", "files"))) 145 all(map(params.__contains__, ("request_json", "files")))
146 and "encoded_id" in job_attr 146 and "encoded_id" in job_attr
147 ): 147 ):
148 params.update(json.loads(params.pop("request_json"))) 148 params.update(json.loads(params.pop("request_json")))