diff options
author | 2011-07-11 19:44:32 +0530 | |
---|---|---|
committer | 2011-07-11 19:44:32 +0530 | |
commit | b67120122f77805800208a5e48f7cf39782dcd2f (patch) | |
tree | f6ab2bd4506528465af78d84e3bb91798f0bf61e | |
parent | fixes for deploying on vulture (diff) | |
download | gentoostats-b67120122f77805800208a5e48f7cf39782dcd2f.tar.gz gentoostats-b67120122f77805800208a5e48f7cf39782dcd2f.tar.bz2 gentoostats-b67120122f77805800208a5e48f7cf39782dcd2f.zip |
make db configurable
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | server/app.py | 2 | ||||
-rw-r--r-- | server/config.py | 11 | ||||
-rw-r--r-- | server/db.cfg.example | 6 | ||||
-rw-r--r-- | server/dbconfig.py | 24 |
5 files changed, 39 insertions, 5 deletions
@@ -1,3 +1,4 @@ *.*~ *.pyc *.swp +server/db.cfg diff --git a/server/app.py b/server/app.py index 3d31d73..e957cde 100755 --- a/server/app.py +++ b/server/app.py @@ -33,7 +33,7 @@ urls = ( r'/host/(.+)', 'Host' ) -app = web.application(urls, globals()) +app = web.application(urls, globals(), autoreload=True) app.notfound = config.notfound app.internalerror = config.internalerror diff --git a/server/config.py b/server/config.py index a7b0f26..98326ae 100644 --- a/server/config.py +++ b/server/config.py @@ -2,15 +2,18 @@ import os import sys import web +from dbconfig import DBConfig +rootdir = os.path.abspath(os.path.dirname(__file__)) + '/' + +dbconfig = DBConfig(rootdir + 'db.cfg').get_config() db = web.database( dbn='mysql', - user='gentoostats', - pw='poicyurp3ZaddajGhaf', - db='gentoostats' + db=dbconfig['DB'], + user=dbconfig['USER'], + pw=dbconfig['PASS'] ) -rootdir = os.path.abspath(os.path.dirname(__file__)) + '/' render = web.template.render(rootdir + 'templates/', base='layout') def notfound(): diff --git a/server/db.cfg.example b/server/db.cfg.example new file mode 100644 index 0000000..1857e2f --- /dev/null +++ b/server/db.cfg.example @@ -0,0 +1,6 @@ + +[MYSQL] + +DB = gentoostats +USER = gentoo +PASS = gentoo diff --git a/server/dbconfig.py b/server/dbconfig.py new file mode 100644 index 0000000..e5eb42c --- /dev/null +++ b/server/dbconfig.py @@ -0,0 +1,24 @@ + +import sys +import ConfigParser + +class DBConfig(object): + + def __init__(self, configfile): + self.config = ConfigParser.ConfigParser() + if len(self.config.read(configfile)) == 0: + sys.stderr.write('Cannot read ' + configfile) + sys.exit(1) + + def get_config(self): + ret = dict() + try: + ret['DB'] = self.config.get('MYSQL', 'DB') + ret['USER'] = self.config.get('MYSQL', 'USER') + ret['PASS'] = self.config.get('MYSQL', 'PASS') + + except ConfigParser.NoSectionError, ConfigParser.NoOptionError: + sys.stderr.write('Invalid db config') + sys.exit(1) + + return ret |