()
| 360 | |
| 361 | |
| 362 | def init_config(): |
| 363 | parser = argparse.ArgumentParser() |
| 364 | config_file = os.path.join(_base_dir, 'configs', 'config.json') |
| 365 | web_dir = "web" |
| 366 | |
| 367 | # If config file exists, load variables from json |
| 368 | load = {} |
| 369 | |
| 370 | def _json_loader(filename): |
| 371 | try: |
| 372 | with open(filename, 'rb') as data: |
| 373 | load.update(json.load(data)) |
| 374 | except ValueError: |
| 375 | if jsonlint: |
| 376 | with open(filename, 'rb') as data: |
| 377 | lint = jsonlint() |
| 378 | rc = lint.main(['-v', filename]) |
| 379 | |
| 380 | logger.critical('Error with configuration file') |
| 381 | sys.exit(-1) |
| 382 | |
| 383 | # Select a config file code |
| 384 | parser.add_argument("-cf", "--config", help="Config File to use") |
| 385 | parser.add_argument("-af", "--auth", help="Auth File to use") |
| 386 | |
| 387 | for _config in ['auth', 'config']: |
| 388 | config_file = os.path.join(_base_dir, 'configs', _config + '.json') |
| 389 | config_arg = parser.parse_known_args() and parser.parse_known_args()[0].__dict__[_config] or None |
| 390 | |
| 391 | if config_arg and os.path.isfile(config_arg): |
| 392 | _json_loader(config_arg) |
| 393 | config_file = config_arg |
| 394 | elif os.path.isfile(config_file): |
| 395 | logger.info('No ' + _config + ' argument specified, checking for ' + config_file) |
| 396 | _json_loader(config_file) |
| 397 | else: |
| 398 | logger.info('Error: No /configs/' + _config + '.json') |
| 399 | |
| 400 | # Read passed in Arguments |
| 401 | required = lambda x: x not in load |
| 402 | add_config( |
| 403 | parser, |
| 404 | load, |
| 405 | short_flag="-a", |
| 406 | long_flag="--auth_service", |
| 407 | help="Auth Service ('ptc' or 'google')", |
| 408 | required=required("auth_service"), |
| 409 | default=None |
| 410 | ) |
| 411 | add_config( |
| 412 | parser, |
| 413 | load, |
| 414 | short_flag="-u", |
| 415 | long_flag="--username", |
| 416 | help="Username", |
| 417 | default=None |
| 418 | ) |
| 419 | add_config( |
no test coverage detected