summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2016-11-12 11:56:24 +0100
committerschneefux <schneefux+commit@schneefux.xyz>2016-11-12 11:56:24 +0100
commit1fc0e087e320d9cfe9cb11dc11cb62fac4deaf81 (patch)
tree852b5f75f92921dccda56aea31deb2a78303a531
parent9a983203c4c22f6e6494f7596433e6c857f9a591 (diff)
downloadjokevote-1fc0e087e320d9cfe9cb11dc11cb62fac4deaf81.tar.gz
jokevote-1fc0e087e320d9cfe9cb11dc11cb62fac4deaf81.zip
use json config format, expose db path
-rw-r--r--.gitignore5
-rw-r--r--app.py12
-rw-r--r--config-template.py8
-rw-r--r--config.json.template9
4 files changed, 21 insertions, 13 deletions
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"
+}