Conditions | 1 |
Total Lines | 143 |
Code Lines | 109 |
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 | # Copyright (C) 2014-2021 Greenbone Networks GmbH |
||
51 | def __init__(self, description: str) -> None: |
||
52 | """Create a command-line arguments parser for OSPD.""" |
||
53 | self._name = description |
||
54 | parser = argparse.ArgumentParser(description=description) |
||
55 | |||
56 | parser.add_argument( |
||
57 | '--version', action='store_true', help='Print version then exit.' |
||
58 | ) |
||
59 | |||
60 | parser.add_argument( |
||
61 | '-s', |
||
62 | '--config', |
||
63 | nargs='?', |
||
64 | default=DEFAULT_CONFIG_PATH, |
||
65 | help='Configuration file path (default: %(default)s)', |
||
66 | ) |
||
67 | parser.add_argument( |
||
68 | '--log-config', |
||
69 | nargs='?', |
||
70 | default=DEFAULT_LOG_CONFIG_PATH, |
||
71 | help='Log configuration file path (default: %(default)s)', |
||
72 | ) |
||
73 | parser.add_argument( |
||
74 | '-p', |
||
75 | '--port', |
||
76 | default=DEFAULT_PORT, |
||
77 | type=self.network_port, |
||
78 | help='TCP Port to listen on. Default: %(default)s', |
||
79 | ) |
||
80 | parser.add_argument( |
||
81 | '-b', |
||
82 | '--bind-address', |
||
83 | default=DEFAULT_ADDRESS, |
||
84 | dest='address', |
||
85 | help='Address to listen on. Default: %(default)s', |
||
86 | ) |
||
87 | parser.add_argument( |
||
88 | '-u', |
||
89 | '--unix-socket', |
||
90 | default=DEFAULT_UNIX_SOCKET_PATH, |
||
91 | help='Unix file socket to listen on. Default: %(default)s', |
||
92 | ) |
||
93 | parser.add_argument( |
||
94 | '--pid-file', |
||
95 | default=DEFAULT_PID_PATH, |
||
96 | help='Location of the file for the process ID. ' |
||
97 | 'Default: %(default)s', |
||
98 | ) |
||
99 | parser.add_argument( |
||
100 | '--lock-file-dir', |
||
101 | default=DEFAULT_LOCKFILE_DIR_PATH, |
||
102 | help='Directory where lock files are placed. Default: %(default)s', |
||
103 | ) |
||
104 | parser.add_argument( |
||
105 | '-m', |
||
106 | '--socket-mode', |
||
107 | default=DEFAULT_UNIX_SOCKET_MODE, |
||
108 | help='Unix file socket mode. Default: %(default)s', |
||
109 | ) |
||
110 | parser.add_argument( |
||
111 | '-k', |
||
112 | '--key-file', |
||
113 | default=DEFAULT_KEY_FILE, |
||
114 | help='Server key file. Default: %(default)s', |
||
115 | ) |
||
116 | parser.add_argument( |
||
117 | '-c', |
||
118 | '--cert-file', |
||
119 | default=DEFAULT_CERT_FILE, |
||
120 | help='Server cert file. Default: %(default)s', |
||
121 | ) |
||
122 | parser.add_argument( |
||
123 | '--ca-file', |
||
124 | default=DEFAULT_CA_FILE, |
||
125 | help='CA cert file. Default: %(default)s', |
||
126 | ) |
||
127 | parser.add_argument( |
||
128 | '-L', |
||
129 | '--log-level', |
||
130 | default='INFO', |
||
131 | type=self.log_level, |
||
132 | help='Wished level of logging. Default: %(default)s', |
||
133 | ) |
||
134 | parser.add_argument( |
||
135 | '-f', |
||
136 | '--foreground', |
||
137 | action='store_true', |
||
138 | help='Run in foreground and logs all messages to console.', |
||
139 | ) |
||
140 | parser.add_argument( |
||
141 | '-t', |
||
142 | '--stream-timeout', |
||
143 | default=DEFAULT_STREAM_TIMEOUT, |
||
144 | type=int, |
||
145 | help='Stream timeout. Default: %(default)s', |
||
146 | ) |
||
147 | parser.add_argument( |
||
148 | '-l', '--log-file', help='Path to the logging file.' |
||
149 | ) |
||
150 | parser.add_argument( |
||
151 | '--niceness', |
||
152 | default=DEFAULT_NICENESS, |
||
153 | type=int, |
||
154 | help='Start the scan with the given niceness. Default %(default)s', |
||
155 | ) |
||
156 | parser.add_argument( |
||
157 | '--scaninfo-store-time', |
||
158 | default=DEFAULT_SCANINFO_STORE_TIME, |
||
159 | type=int, |
||
160 | help='Time in hours a scan is stored before being considered ' |
||
161 | 'forgotten and being delete from the scan table. ' |
||
162 | 'Default %(default)s, disabled.', |
||
163 | ) |
||
164 | parser.add_argument( |
||
165 | '--list-commands', |
||
166 | action='store_true', |
||
167 | help='Display all protocol commands', |
||
168 | ) |
||
169 | parser.add_argument( |
||
170 | '--max-scans', |
||
171 | default=DEFAULT_MAX_SCAN, |
||
172 | type=int, |
||
173 | help='Max. amount of parallel task that can be started. ' |
||
174 | 'Default %(default)s, disabled', |
||
175 | ) |
||
176 | parser.add_argument( |
||
177 | '--min-free-mem-scan-queue', |
||
178 | default=DEFAULT_MIN_FREE_MEM_SCAN_QUEUE, |
||
179 | type=int, |
||
180 | help='Minimum free memory in MB required to run the scan. ' |
||
181 | 'If no enough free memory is available, the scan queued. ' |
||
182 | 'Default %(default)s, disabled', |
||
183 | ) |
||
184 | parser.add_argument( |
||
185 | '--max-queued-scans', |
||
186 | default=DEFAULT_MAX_QUEUED_SCANS, |
||
187 | type=int, |
||
188 | help='Maximum number allowed of queued scans before ' |
||
189 | 'starting to reject new scans. ' |
||
190 | 'Default %(default)s, disabled', |
||
191 | ) |
||
192 | |||
193 | self.parser = parser |
||
194 | |||
255 |