From 64af72abb503023b4ca7e45f65d994d166f3ac3c Mon Sep 17 00:00:00 2001 From: Ben Busby <33362396+benbusby@users.noreply.github.com> Date: Tue, 2 Jun 2020 14:38:29 -0600 Subject: [PATCH] Moved custom conf files to their own directory --- .gitignore | 2 ++ app/__init__.py | 4 ++++ app/routes.py | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index f6e039f..bbffdb4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,10 +3,12 @@ venv/ __pycache__/ *.pyc *.pem +*.conf config.json test/static flask_session/ app/static/config +app/static/custom_config # pip stuff build/ diff --git a/app/__init__.py b/app/__init__.py index 53d4a59..ecd1edd 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -12,12 +12,16 @@ app.config['VERSION_NUMBER'] = '0.2.0' app.config['APP_ROOT'] = os.getenv('APP_ROOT', os.path.dirname(os.path.abspath(__file__))) app.config['STATIC_FOLDER'] = os.getenv('STATIC_FOLDER', os.path.join(app.config['APP_ROOT'], 'static')) app.config['CONFIG_PATH'] = os.getenv('CONFIG_VOLUME', app.config['STATIC_FOLDER'] + '/config') +app.config['USER_CONFIG'] = os.path.join(app.config['STATIC_FOLDER'], 'custom_config') app.config['SESSION_FILE_DIR'] = app.config['CONFIG_PATH'] app.config['SESSION_COOKIE_SECURE'] = True if not os.path.exists(app.config['CONFIG_PATH']): os.makedirs(app.config['CONFIG_PATH']) +if not os.path.exists(app.config['USER_CONFIG']): + os.makedirs(app.config['USER_CONFIG']) + sess = Session() sess.init_app(app) diff --git a/app/routes.py b/app/routes.py index ca3bac4..b473073 100644 --- a/app/routes.py +++ b/app/routes.py @@ -157,7 +157,7 @@ def config(): return json.dumps(g.user_config.__dict__) elif request.method == 'PUT': if 'name' in request.args: - config_pkl = os.path.join(app.config['CONFIG_PATH'], request.args.get('name')) + config_pkl = os.path.join(app.config['USER_CONFIG'], request.args.get('name')) session['config'] = pickle.load(open(config_pkl, 'rb')) if os.path.exists(config_pkl) else session['config'] return json.dumps(session['config']) else: @@ -168,7 +168,7 @@ def config(): config_data['url'] = g.user_config.url if 'name' in request.args: - pickle.dump(config_data, open(os.path.join(app.config['CONFIG_PATH'], request.args.get('name')), 'wb')) + pickle.dump(config_data, open(os.path.join(app.config['USER_CONFIG'], request.args.get('name')), 'wb')) session['config'] = config_data return redirect(config_data['url'])