Conditions | 5 |
Total Lines | 60 |
Code Lines | 41 |
Lines | 13 |
Ratio | 21.67 % |
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 | # -*- coding: utf-8 -*- |
||
43 | def main(): |
||
44 | parser = create_parser( |
||
45 | description=HELP_TEXT, logfilename='gvm-script.log') |
||
46 | |||
47 | parser.add_protocol_argument() |
||
48 | |||
49 | parser.add_argument( |
||
50 | 'scriptname', metavar="SCRIPT", |
||
51 | help='Path to script to be executed (example: myscript.gmp)') |
||
52 | parser.add_argument( |
||
53 | 'scriptargs', nargs='*', metavar="ARG", |
||
54 | help='Arguments for the script') |
||
55 | |||
56 | args = parser.parse_args() |
||
57 | |||
58 | print(args) |
||
59 | |||
60 | if 'socket' in args.connection_type and args.sockpath: |
||
61 | print('The --sockpath parameter has been deprecated. Please use ' |
||
62 | '--socketpath instead', file=sys.stderr) |
||
63 | |||
64 | connection = create_connection(**vars(args)) |
||
65 | |||
66 | transform = EtreeCheckCommandTransform() |
||
67 | |||
68 | global_vars = { |
||
69 | '__version__': __version__, |
||
70 | '__api_version__': __api_version__, |
||
71 | } |
||
72 | |||
73 | username = None |
||
74 | password = None |
||
75 | |||
76 | View Code Duplication | if args.protocol == PROTOCOL_OSP: |
|
|
|||
77 | protocol = Osp(connection, transform=transform) |
||
78 | global_vars['osp'] = protocol |
||
79 | global_vars['__name__'] = '__osp__' |
||
80 | else: |
||
81 | protocol = Gmp(connection, transform=transform) |
||
82 | global_vars['gmp'] = protocol |
||
83 | global_vars['__name__'] = '__gmp__' |
||
84 | |||
85 | if args.gmp_username: |
||
86 | (username, password) = authenticate( |
||
87 | protocol, username=args.gmp_username, |
||
88 | password=args.gmp_password) |
||
89 | |||
90 | argv = [os.path.abspath(args.scriptname), *args.scriptargs] |
||
91 | |||
92 | shell_args = Namespace( |
||
93 | username=username, |
||
94 | password=password, |
||
95 | argv=argv, |
||
96 | # for backwards compatibility we add script here |
||
97 | script=argv, |
||
98 | ) |
||
99 | |||
100 | global_vars['args'] = shell_args |
||
101 | |||
102 | run_script(args.scriptname, global_vars) |
||
103 | |||
108 |