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