Conditions | 1 |
Total Lines | 90 |
Code Lines | 62 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | #!/usr/bin/env python2 |
||
19 | def parse_args(): |
||
20 | parser = argparse.ArgumentParser() |
||
21 | |||
22 | common_parser = argparse.ArgumentParser(add_help=False) |
||
23 | common_parser.add_argument("--hypervisor", |
||
24 | dest="hypervisor", |
||
25 | metavar="HYPERVISOR", |
||
26 | default="qemu:///session", |
||
27 | help="libvirt hypervisor") |
||
28 | common_parser.add_argument("--domain", |
||
29 | dest="domain_name", |
||
30 | metavar="DOMAIN", |
||
31 | required=True, |
||
32 | help=("Specify libvirt domain to be used as a test " |
||
33 | "bed. This domain will get remediations " |
||
34 | "applied in it, possibly making system " |
||
35 | "unusable for a moment. Snapshot will be " |
||
36 | "reverted immediately afterwards. " |
||
37 | "Domain will be returned without changes")) |
||
38 | common_parser.add_argument("--datastream", |
||
39 | dest="datastream", |
||
40 | metavar="DATASTREAM", |
||
41 | required=True, |
||
42 | help=("Path to the Source DataStream on this " |
||
43 | "machine which is going to be tested")) |
||
44 | common_parser.add_argument("--xccdf-id", |
||
45 | dest="xccdf_id", |
||
46 | metavar="REF-ID", |
||
47 | required=True, |
||
48 | help="Reference ID related to benchmark to be used." |
||
49 | " Get one using 'oscap info <datastream>'.") |
||
50 | common_parser.add_argument("--loglevel", |
||
51 | dest="loglevel", |
||
52 | metavar="LOGLEVEL", |
||
53 | default="INFO", |
||
54 | help="Default level of console output") |
||
55 | common_parser.add_argument("--logdir", |
||
56 | dest="logdir", |
||
57 | metavar="LOGDIR", |
||
58 | default=None, |
||
59 | help="Directory to which all output is saved") |
||
60 | |||
61 | common_parser.add_argument( |
||
62 | "--remediate-using", |
||
63 | dest="remediate_using", |
||
64 | default="oscap", |
||
65 | choices=ssg_test_suite.oscap.REMEDIATION_RULE_RUNNERS.keys(), |
||
66 | help="What type of remediations to use - openscap online one, " |
||
67 | "or remediation done by using remediation roles " |
||
68 | "that are saved to disk beforehand.") |
||
69 | |||
70 | subparsers = parser.add_subparsers(dest='subparser_name', |
||
71 | help='Subcommands: profile, rule') |
||
72 | |||
73 | parser_profile = subparsers.add_parser('profile', |
||
74 | help=('Testing profile-based ' |
||
75 | 'remediation applied on already ' |
||
76 | 'installed machine'), |
||
77 | parents=[common_parser]) |
||
78 | parser_profile.set_defaults(func=ssg_test_suite.profile.perform_profile_check) |
||
79 | parser_rule = subparsers.add_parser('rule', |
||
80 | help=('Testing remediations of particular ' |
||
81 | 'rule for various situations - ' |
||
82 | 'currently not supported ' |
||
83 | 'by openscap!'), |
||
84 | parents=[common_parser]) |
||
85 | parser_rule.set_defaults(func=ssg_test_suite.rule.perform_rule_check) |
||
86 | |||
87 | parser_profile.add_argument("target", |
||
88 | nargs="+", |
||
89 | metavar="DSPROFILE", |
||
90 | help=("Profiles to be tested, 'ALL' means every " |
||
91 | "profile of particular benchmark will be " |
||
92 | "evaluated.")) |
||
93 | |||
94 | parser_rule.add_argument("target", |
||
95 | nargs="+", |
||
96 | metavar="RULE", |
||
97 | help=("Rule to be tested, 'ALL' means every " |
||
98 | "rule-testing scenario will be evaluated. Each " |
||
99 | "target is handled as a substring - so you can " |
||
100 | "ask for subset of all rules this way. (If you " |
||
101 | "type ipv6 as a target, all rules containing " |
||
102 | "ipv6 within id will be performed.")) |
||
103 | parser_rule.add_argument("--dontclean", |
||
104 | dest="dont_clean", |
||
105 | action="store_true", |
||
106 | help="Do not remove html reports of successful runs") |
||
107 | |||
108 | return parser.parse_args() |
||
109 | |||
159 |