- commit
- 8d29fede8e07a093ca028d82d7b2a5a6b7ae8b9a
- parent
- f09b4979da9f5a785fd85e4583e900890fd411ec
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2015-02-05 17:22
load config from local and home
Diffstat
| M | jsonproxy/__init__.py | 16 | ++++++++++++++-- |
1 files changed, 14 insertions, 2 deletions
diff --git a/jsonproxy/__init__.py b/jsonproxy/__init__.py
@@ -37,21 +37,33 @@ def check_config(config): 37 37 38 38 def main(): 39 39 parser = argparse.ArgumentParser(description='simple proxy and scraper')40 -1 parser.add_argument('config')-1 40 parser.add_argument('-c', '--config') 41 41 parser.add_argument('-d', '--debug', action='store_true') 42 42 parser.add_argument('-p', '--port', type=int) 43 43 parser.add_argument('-H', '--host') 44 44 args = parser.parse_args() 45 45 46 46 app = Flask(__name__)47 -1 app.config.from_pyfile(os.path.abspath(args.config))48 47 -1 48 # load config -1 49 config_files = [ -1 50 os.path.expanduser('~/.config/pyjsonproxy.cfg'), -1 51 os.path.abspath('.pyjsonproxy.cfg'), -1 52 ] -1 53 for path in config_files: -1 54 if os.path.exists(path): -1 55 app.config.from_pyfile(path) -1 56 if args.config is not None: -1 57 app.config.from_pyfile(os.path.abspath(args.config)) -1 58 -1 59 # check for config errors 49 60 errors = check_config(app.config) 50 61 if errors: 51 62 for error in errors: 52 63 app.logger.error(error) 53 64 sys.exit(1) 54 65 -1 66 # run 55 67 app.register_blueprint(api) 56 68 app.run(host=args.host, port=args.port, debug=args.debug) 57 69