(is_local)
| 189 | |
| 190 | |
| 191 | def get_config(is_local): |
| 192 | global verbose |
| 193 | |
| 194 | logging.basicConfig(level=logging.INFO, |
| 195 | format='%(levelname)-s: %(message)s') |
| 196 | if is_local: |
| 197 | shortopts = 'hd:s:b:p:k:l:m:c:t:vqa' |
| 198 | longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'user=', |
| 199 | 'version'] |
| 200 | else: |
| 201 | shortopts = 'hd:s:p:k:m:c:t:vqa' |
| 202 | longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'workers=', |
| 203 | 'forbidden-ip=', 'user=', 'manager-address=', 'version', |
| 204 | 'prefer-ipv6'] |
| 205 | try: |
| 206 | config_path = find_config() |
| 207 | optlist, args = getopt.getopt(sys.argv[1:], shortopts, longopts) |
| 208 | for key, value in optlist: |
| 209 | if key == '-c': |
| 210 | config_path = value |
| 211 | |
| 212 | if config_path: |
| 213 | logging.info('loading config from %s' % config_path) |
| 214 | with open(config_path, 'rb') as f: |
| 215 | try: |
| 216 | config = parse_json_in_str(f.read().decode('utf8')) |
| 217 | except ValueError as e: |
| 218 | logging.error('found an error in config.json: %s', |
| 219 | e.message) |
| 220 | sys.exit(1) |
| 221 | else: |
| 222 | config = {} |
| 223 | |
| 224 | v_count = 0 |
| 225 | for key, value in optlist: |
| 226 | if key == '-p': |
| 227 | config['server_port'] = int(value) |
| 228 | elif key == '-k': |
| 229 | config['password'] = to_bytes(value) |
| 230 | elif key == '-l': |
| 231 | config['local_port'] = int(value) |
| 232 | elif key == '-s': |
| 233 | config['server'] = to_str(value) |
| 234 | elif key == '-m': |
| 235 | config['method'] = to_str(value) |
| 236 | elif key == '-b': |
| 237 | config['local_address'] = to_str(value) |
| 238 | elif key == '-v': |
| 239 | v_count += 1 |
| 240 | # '-vv' turns on more verbose mode |
| 241 | config['verbose'] = v_count |
| 242 | elif key == '-a': |
| 243 | config['one_time_auth'] = True |
| 244 | elif key == '-t': |
| 245 | config['timeout'] = int(value) |
| 246 | elif key == '--fast-open': |
| 247 | config['fast_open'] = True |
| 248 | elif key == '--workers': |
nothing calls this directly
no test coverage detected