summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2012-12-18 16:51:36 +0100
committerFlorian Bruhin <git@the-compiler.org>2012-12-18 16:51:36 +0100
commit32a0c1ba627fb854a3a788fbdfcb460661ea42da (patch)
treeee93485a12cd94fa346f5365cbfec142a4cab29c
parent67e6426a1adb5ddbb7bb108832b540f9b53b8342 (diff)
downloadnpc-32a0c1ba627fb854a3a788fbdfcb460661ea42da.tar.gz
npc-32a0c1ba627fb854a3a788fbdfcb460661ea42da.zip
move db settings to config file
-rw-r--r--npc.ini.example5
-rwxr-xr-xnpc.py22
2 files changed, 22 insertions, 5 deletions
diff --git a/npc.ini.example b/npc.ini.example
new file mode 100644
index 0000000..5ae9ff9
--- /dev/null
+++ b/npc.ini.example
@@ -0,0 +1,5 @@
+[mysql]
+user = npc
+password = secret
+host = localhost
+db = npc
diff --git a/npc.py b/npc.py
index 9cd0a75..291fee8 100755
--- a/npc.py
+++ b/npc.py
@@ -17,6 +17,7 @@
# along with npc.py. If not, see <http://www.gnu.org/licenses/>.
import sys
+import configparser
import bottle
import pygments
import pygments.util
@@ -59,11 +60,8 @@ HTML_FOOTER="""
"""
Base = sqlalchemy.ext.declarative.declarative_base()
-engine = sqlalchemy.create_engine(
- 'mysql+oursql://npc:rK3fzEuZ9p55X2Tm@localhost/npc',
- echo=False, pool_recycle=3600
-)
-create_session = sessionmaker(bind=engine)
+engine = None
+create_session = None
class Votes(Base):
__tablename__ = 'votes'
@@ -706,6 +704,20 @@ def serve_static(filename):
def serve_codemirror(path):
return static_file(path, root=(__PATH__ + '/codemirror'))
+def init_db():
+ global engine
+ global create_ession
+ config = configparser.ConfigParser()
+ config.read(__PATH__ + '/npc.ini')
+ d = config['mysql']
+
+ engine = sqlalchemy.create_engine(
+ 'mysql+oursql://{}:{}@{}/{}'.format(d['user'], d['password'],
+ d['host'], d['db']), echo=False, pool_recycle=3600
+ )
+
+init_db()
+create_session = sessionmaker(bind=engine)
bottle.install(SQLAlchemyPlugin(engine, Base.metadata, create=True))
if __name__ == '__main__':