lighthouse_garden.lighthouse.utility   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 34
dl 0
loc 67
rs 10
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A get_data_dir() 0 13 3
A remove_file() 0 8 2
A get_export_dir() 0 9 2
A extend_html_report_with_info() 0 22 4
1
#!/usr/bin/env python3
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
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])
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after del.
Loading history...
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)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (104/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
66
            file.writelines(_html)
67