Test Failed
Push — master ( 1bab60...8e0a9b )
by Jan
02:31 queued 11s
created

HtmlOutput._get_eligible_rules()   A

Complexity

Conditions 4

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 11
nop 2
dl 0
loc 13
rs 9.85
c 0
b 0
f 0
ccs 0
cts 11
cp 0
crap 20
1
#!/usr/bin/python3
2
3
import os
4
import re
5
import glob
6
7
import ssg.build_yaml
8
import ssg.constants
9
10
import tables.table_renderer
11
12
13
class HtmlOutput(tables.table_renderer.TableHtmlOutput):
14
    TEMPLATE_NAME = "tables/reference_tables_template.html"
15
16
    def __init__(self, * args, ** kwargs):
17
        super(HtmlOutput, self).__init__(* args, ** kwargs)
18
        self.cached_rules = []
19
20
    def _fix_var_sub_in_text(self, text, varname, value):
21
        return re.sub(
22
            r'<sub\s+idref="{var}"\s*/>'.format(var=varname),
23
            r'<abbr title="${var}"><tt>{val}</tt></abbr>'.format(var=varname, val=value), text)
24
25
    def _get_eligible_rules(self, refcat):
26
        filenames = glob.glob(os.path.join(self.rules_root, "*.yml"))
27
        if self.cached_rules:
28
            all_rules = self.cached_rules
29
        else:
30
            all_rules = [ssg.build_yaml.Rule.from_yaml(f, self.env_yaml) for f in filenames]
31
            self.cached_rules = all_rules
32
33
        rules = []
34
        for rule in all_rules:
35
            if refcat in rule.references:
36
                rules.append(rule)
37
        return rules
38
39
    def process_rules(self, reference):
40
        super(HtmlOutput, self).process_rules(reference)
41
42
        self.template_data["title"] = (
43
            "{product} rules by {refcat} references"
44
            .format(product=self.product, refcat=reference.name)
45
        )
46
47
48
def update_parser(parser):
49
    pass
50
51
52
def parse_args():
53
    parser = HtmlOutput.create_parser(
54
        "Generate HTML table that maps references to rules "
55
        "using compiled rules as source of data.")
56
    tables.table_renderer.update_parser(parser)
57
    update_parser(parser)
58
    return parser.parse_args()
59
60
61
if __name__ == "__main__":
62
    args = parse_args()
63
    renderer = HtmlOutput(args.product, args.build_dir, args.verbose)
64
    reference = ssg.constants.REFERENCES[args.refcategory]
65
    renderer.process_rules(reference)
66
    renderer.output_results(args)
67