-
Notifications
You must be signed in to change notification settings - Fork 798
Expand file tree
/
Copy pathgen_reference_table.py
More file actions
67 lines (50 loc) · 1.92 KB
/
gen_reference_table.py
File metadata and controls
67 lines (50 loc) · 1.92 KB
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
66
67
#!/usr/bin/python3
import os
import re
import glob
import ssg.build_yaml
import ssg.constants
import tables.table_renderer
class HtmlOutput(tables.table_renderer.TableHtmlOutput):
TEMPLATE_NAME = "tables/reference_tables_template.html"
def __init__(self, * args, ** kwargs):
super(HtmlOutput, self).__init__(* args, ** kwargs)
self.cached_rules = []
def _fix_var_sub_in_text(self, text, varname, value):
return re.sub(
r'<sub\s+idref="{var}"\s*/>'.format(var=varname),
r'<abbr title="${var}"><tt>{val}</tt></abbr>'.format(var=varname, val=value), text)
def _get_eligible_rules(self, refcat):
filenames = glob.glob(os.path.join(self.rules_root, "*.json"))
if self.cached_rules:
all_rules = self.cached_rules
else:
all_rules = [
ssg.build_yaml.Rule.from_compiled_json(f, self.env_yaml) for f in filenames]
self.cached_rules = all_rules
rules = []
for rule in all_rules:
if refcat in rule.references:
rules.append(rule)
return rules
def process_rules(self, reference):
super(HtmlOutput, self).process_rules(reference)
self.template_data["title"] = (
"{product} rules by {refcat} references"
.format(product=self.product, refcat=reference.name)
)
def update_parser(parser):
pass
def parse_args():
parser = HtmlOutput.create_parser(
"Generate HTML table that maps references to rules "
"using compiled rules as source of data.")
tables.table_renderer.update_parser(parser)
update_parser(parser)
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
renderer = HtmlOutput(args.product, args.build_dir, args.verbose)
reference = ssg.constants.REFERENCES[args.refcategory]
renderer.process_rules(reference)
renderer.output_results(args)