-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml_processing.py
65 lines (56 loc) · 2.09 KB
/
html_processing.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
65
from prettytable import *
import logging
import os
module_logger = logging.getLogger("Perf_reporter.html_processing")
def html_file_name(template_path):
html_report_path = 'report_files/' + os.path.splitext(template_path)[0].split('/')[1] + '_report.html'
return html_report_path
def html_write(html_data, report_file_name):
"""
Пишем в html
"""
logger = logging.getLogger("Perf_reporter.html_processing.html_write")
x = PrettyTable(border=False, header=True, hrules=NONE, vrules=NONE, padding_width=2)
for h in html_data[0]:
logger.debug(h)
x.field_names.append(h)
# for r in range(1, len(html_data)):
# splitted_row = html_data[r]
# x.add_row(splitted_row)
# # x.print_html(attributes={"border": "1"})
# # logger.debug(x)
for r in range(1, len(html_data)):
splitted_row = html_data[r]
x.add_row(splitted_row)
html_code = x.get_html_string(format=False)
try:
with open(report_file_name, "w") as out_file:
html_file = out_file.write(html_code)
logger.info('HTML report created: ' + report_file_name)
except OSError as e:
print(e)
def html_add(html_data, report_file_name):
"""
Пишем в html
"""
logger = logging.getLogger("Perf_reporter.html_processing.html_add")
# logger.debug(html_data[0])
x = PrettyTable(border=True, header=False, padding_width=3)
# count = 0
# for i in html_data[0]:
# x.field_names.append(count.__str__())
# count += 1
# logger.debug("field names")
# logger.debug(x.field_names)
for j in range(1, len(html_data)):
splitted_row = html_data[j]
x.add_row(splitted_row)
# x.print_html(attributes={"border": "1"})
logger.info(x)
html_code = x.get_html_string(format=True)
try:
with open(report_file_name, "a") as out_file:
html_file = out_file.write(html_code)
logger.info('Added to: ' + report_file_name)
except OSError as e:
print(e)