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

utils.gen_multiple_reference_tables.parse_args()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 0
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
#!/usr/bin/python3
2
3
import os
4
import re
5
import glob
6
import argparse
7
8
import ssg.build_yaml
9
import ssg.constants
10
11
from utils import gen_reference_table
12
13
14
def update_parser(parser):
15
    parser.add_argument("--build-dir", default="build", help="Path to the build directory")
16
    parser.add_argument(
17
        "product", help="The product to be built")
18
    parser.add_argument(
19
        "output_template", help="Template of the filename to generate. "
20
        "Occurrence of '{ref_id}' will be substituted by the respective reference ID "
21
        "that the generated table describes.")
22
    parser.add_argument(
23
        "refcategory", metavar="REFERENCE_ID", nargs="+",
24
        help="Category of the rule reference")
25
26
27
def parse_args():
28
    parser = argparse.ArgumentParser(
29
        description="Render multiple reference tables at once "
30
        "using the gen_reference_table script functionality")
31
    update_parser(parser)
32
    return parser.parse_args()
33
34
35
if __name__ == "__main__":
36
    args = parse_args()
37
    renderer = gen_reference_table.HtmlOutput(args.product, args.build_dir)
38
    for reference in args.refcategory:
39
        reference = ssg.constants.REFERENCES[reference]
40
41
        renderer.process_rules(reference)
42
        result = renderer.get_result()
43
        output = args.output_template.format(ref_id=reference.id)
44
        with open(output, "w") as outfile:
45
            outfile.write(result)
46