diff options
Diffstat (limited to 'server')
-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 |
4 files changed, 38 insertions, 5 deletions
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 |