1
|
|
|
#!/usr/bin/env python3 |
|
|
|
|
2
|
|
|
# -*- coding: future_fstrings -*- |
3
|
|
|
|
4
|
|
|
import os |
5
|
|
|
from lighthouse_garden.utility import output, system |
6
|
|
|
from lighthouse_garden.export import render |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
def get_data_dir(absolute_path=True): |
10
|
|
|
""" |
11
|
|
|
Return the data directory path and handle missing slashes |
12
|
|
|
:param absolute_path: Boolean |
13
|
|
|
:return: |
14
|
|
|
""" |
15
|
|
|
_data_dir_path = '' |
16
|
|
|
if absolute_path: |
17
|
|
|
_data_dir_path += get_export_dir() |
18
|
|
|
_data_dir_path += f'/{system.config["data_dir"]}' |
19
|
|
|
if _data_dir_path[-1] != '/': |
20
|
|
|
_data_dir_path += '/' |
21
|
|
|
return _data_dir_path.replace('//', '/') |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
def get_export_dir(): |
25
|
|
|
""" |
26
|
|
|
Return the export directory path and handle missing slashes |
27
|
|
|
:return: |
28
|
|
|
""" |
29
|
|
|
_export_dir_path = f'{system.config["export_path"]}' |
30
|
|
|
if _export_dir_path[-1] != '/': |
31
|
|
|
_export_dir_path += '/' |
32
|
|
|
return _export_dir_path |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
def remove_file(file_name): |
36
|
|
|
""" |
37
|
|
|
Remove a local file |
38
|
|
|
:param file_name: |
39
|
|
|
:return: |
40
|
|
|
""" |
41
|
|
|
if os.path.exists(file_name): |
42
|
|
|
os.remove(file_name) |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
def extend_html_report_with_info(result, file_name): |
46
|
|
|
""" |
47
|
|
|
Extend the existing lighthouse html report with an additional info box |
48
|
|
|
:param result: Dict |
49
|
|
|
:param file_name: String |
50
|
|
|
:return: |
51
|
|
|
""" |
52
|
|
|
if os.path.isfile(file_name): |
53
|
|
|
with open(file_name, "r") as read_file: |
54
|
|
|
_html = read_file.readlines() |
55
|
|
|
_info = render.render_template('partials/info.html.j2', |
56
|
|
|
title=result['title'], |
57
|
|
|
url=result['url'], |
58
|
|
|
date=result['date'], |
59
|
|
|
logo=render.render_logo() |
60
|
|
|
) |
61
|
|
|
_html[-2] = f'{_info}\n</body>\n</html>' |
62
|
|
|
del(_html[-1]) |
|
|
|
|
63
|
|
|
|
64
|
|
|
with open(file_name, 'w') as file: |
65
|
|
|
output.println(f'{output.Subject.INFO} Extend html report with info box', verbose_only=True) |
|
|
|
|
66
|
|
|
file.writelines(_html) |
67
|
|
|
|