Passed
Push — master ( d4a97d...a9acad )
by Matěj
02:20 queued 12s
created

build_rule_playbooks.parse_args()   A

Complexity

Conditions 1

Size

Total Lines 53
Code Lines 27

Duplication

Lines 53
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 27
nop 0
dl 53
loc 53
ccs 0
cts 11
cp 0
crap 2
rs 9.232
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
#!/usr/bin/python3
2
3
import argparse
4
import ssg.playbook_builder
5
import os
6
7
8 View Code Duplication
def parse_args():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9
    p = argparse.ArgumentParser()
10
    p.add_argument(
11
        "--input-dir",
12
        help="Input directory that contains all Ansible remediations "
13
        "snippets for the product we are building. "
14
        "e.g. ~/scap-security-guide/build/fedora/fixes/ansible. "
15
        "If --input-dir is not specified, it is derived from --ssg-root."
16
    )
17
    p.add_argument(
18
        "--output-dir",
19
        help="Output directory to which the rule-based Ansible playbooks "
20
        "will be generated. "
21
        "e.g. ~/scap-security-guide/build/fedora/playbooks. "
22
        "If --output-dir is not specified, it is derived from --ssg-root."
23
    )
24
    p.add_argument(
25
        "--resolved-rules-dir",
26
        help="Directory that contains preprocessed rules in YAML format "
27
        "eg. ~/scap-security-guide/build/fedora/rules. "
28
        "If --resolved-rules-dir is not specified, it is derived from "
29
        "--ssg-root."
30
    )
31
    p.add_argument(
32
        "--resolved-profiles-dir",
33
        help="Directory that contains preprocessed profiles in YAML format "
34
        "eg. ~/scap-security-guide/build/fedora/profiles. "
35
        "If --resolved-profiles-dir is not specified, it is derived from "
36
        "--ssg-root."
37
    )
38
    p.add_argument(
39
        "--ssg-root", required=True,
40
        help="Directory containing the source tree. "
41
        "e.g. ~/scap-security-guide/"
42
    )
43
    p.add_argument(
44
        "--product", required=True,
45
        help="ID of the product for which we are building Playbooks. "
46
        "e.g.: 'fedora'"
47
    )
48
    p.add_argument(
49
        "--profile",
50
        help="Generate Playbooks only for given Profile ID. Accepts profile "
51
        "ID in the short form, eg. 'ospp'. If not specified, Playbooks are "
52
        "built for all available profiles."
53
    )
54
    p.add_argument(
55
        "--rule",
56
        help="Generate Ansible Playbooks only for given rule specified by "
57
             "a shortened Rule ID, eg. 'package_sendmail_removed'. "
58
             "If not specified, Playbooks are built for every rule."
59
    )
60
    return p.parse_args()
61
62
63
def main():
64
    args = parse_args()
65
    product_yaml = os.path.join(args.ssg_root, args.product, "product.yml")
66
    if args.input_dir:
67
        input_dir = args.input_dir
68
    else:
69
        input_dir = os.path.join(
70
            args.ssg_root, "build", args.product, "fixes", "ansible"
71
        )
72
    if args.output_dir:
73
        output_dir = args.output_dir
74
    else:
75
        output_dir = os.path.join(
76
            args.ssg_root, "build", args.product, "playbooks"
77
        )
78
    if args.resolved_rules_dir:
79
        resolved_rules_dir = args.resolved_rules_dir
80
    else:
81
        resolved_rules_dir = os.path.join(
82
            args.ssg_root, "build", args.product, "rules"
83
        )
84
    if args.resolved_profiles_dir:
85
        resolved_profiles_dir = args.resolved_profiles_dir
86
    else:
87
        resolved_profiles_dir = os.path.join(
88
            args.ssg_root, "build", args.product, "profiles"
89
        )
90
    playbook_builder = ssg.playbook_builder.PlaybookBuilder(
91
        product_yaml, input_dir, output_dir, resolved_rules_dir, resolved_profiles_dir
92
    )
93
    playbook_builder.build(args.profile, args.rule)
94
95
96
if __name__ == "__main__":
97
    main()
98