From 71226a4ed3bce695d1c3acf03d1fce1276099cb6 Mon Sep 17 00:00:00 2001 From: Peter Hansen Date: Sat, 28 Dec 2019 11:32:00 +0100 Subject: [PATCH] specify config file as cli argument --- lg.py | 6 +++++- lgproxy.py | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lg.py b/lg.py index b8f829c..e9a7c6c 100644 --- a/lg.py +++ b/lg.py @@ -31,6 +31,7 @@ from urllib2 import urlopen from urllib import quote, unquote import json import random +import argparse from toolbox import mask_is_valid, ipv6_is_valid, ipv4_is_valid, resolve, save_cache_pickle, load_cache_pickle, unescape #from xml.sax.saxutils import escape @@ -38,9 +39,12 @@ from toolbox import mask_is_valid, ipv6_is_valid, ipv4_is_valid, resolve, save_c import pydot from flask import Flask, render_template, jsonify, redirect, session, request, abort, Response, Markup +parser = argparse.ArgumentParser() +parser.add_argument('-c', dest='config_file', help='path to config file', default='lg.cfg') +args = parser.parse_args() app = Flask(__name__) -app.config.from_pyfile('lg.cfg') +app.config.from_pyfile(args.config_file) app.secret_key = app.config["SESSION_KEY"] app.debug = app.config["DEBUG"] diff --git a/lgproxy.py b/lgproxy.py index e6018f0..34f13c3 100644 --- a/lgproxy.py +++ b/lgproxy.py @@ -26,14 +26,19 @@ from logging.handlers import TimedRotatingFileHandler from logging import FileHandler import subprocess from urllib import unquote +import argparse from bird import BirdSocket from flask import Flask, request, abort +parser = argparse.ArgumentParser() +parser.add_argument('-c', dest='config_file', help='path to config file', default='lgproxy.cfg') +args = parser.parse_args() + app = Flask(__name__) app.debug = app.config["DEBUG"] -app.config.from_pyfile('lgproxy.cfg') +app.config.from_pyfile(args.config_file) file_handler = TimedRotatingFileHandler(filename=app.config["LOG_FILE"], when="midnight") app.logger.setLevel(getattr(logging, app.config["LOG_LEVEL"].upper()))