From 1fc0e087e320d9cfe9cb11dc11cb62fac4deaf81 Mon Sep 17 00:00:00 2001 From: schneefux Date: Sat, 12 Nov 2016 11:56:24 +0100 Subject: use json config format, expose db path --- .gitignore | 5 ++--- app.py | 12 ++++++++++-- config-template.py | 8 -------- config.json.template | 9 +++++++++ 4 files changed, 21 insertions(+), 13 deletions(-) delete mode 100644 config-template.py create mode 100644 config.json.template diff --git a/.gitignore b/.gitignore index 67fb743..828e9dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -votes.db -votes*.db -config.py +*.db +*.json __pycache__/ diff --git a/app.py b/app.py index c35c130..0871e26 100644 --- a/app.py +++ b/app.py @@ -4,6 +4,7 @@ import sqlite3 import hashlib import os import re +import json import datetime from flask import ( Flask, @@ -17,7 +18,6 @@ from flask import ( session, flash ) -from config import config class Markup(object): @@ -513,7 +513,7 @@ class DBProxy(object): def db(): database = getattr(g, "_database", None) if database is None: - database = g._database = DBProxy("votes.db", + database = g._database = DBProxy(config['database'], config['superuser'].lower()) return database @@ -677,6 +677,14 @@ def get_static(path): def robotstxt(): return send_from_directory('static', 'robots.txt') +if 'VOTE_CONFIG' in os.environ: + configf = open(os.environ['VOTE_CONFIG']) +else: + configf = open('config.json') + +config = json.load(configf) +configf.close() + app.debug = config['debug'] app.secret_key = config['secret_key'] if __name__ == '__main__': diff --git a/config-template.py b/config-template.py deleted file mode 100644 index 2fc1310..0000000 --- a/config-template.py +++ /dev/null @@ -1,8 +0,0 @@ -config = { - 'secret_key': b'', - 'debug': False, - 'superuser': 'admin', - 'abusemail': 'admin@host.example.com', - 'featured': ['sticky'], - 'title': 'My awesome voting page' -} diff --git a/config.json.template b/config.json.template new file mode 100644 index 0000000..888d11e --- /dev/null +++ b/config.json.template @@ -0,0 +1,9 @@ +{ + "database": "votes.db", + "secret_key": "", + "debug": false, + "superuser": "admin", + "abusemail": "admin@host.example.com", + "featured": ["sticky"], + "title": "My awesome voting page" +} -- cgit v1.3.1