From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QgHGP-0007o3-4Z for garchives@archives.gentoo.org; Mon, 11 Jul 2011 14:15:09 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9DC4321C301; Mon, 11 Jul 2011 14:15:01 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 5DF7E21C2ED for ; Mon, 11 Jul 2011 14:15:01 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id BDC321B4080 for ; Mon, 11 Jul 2011 14:15:00 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id BD0788003D for ; Mon, 11 Jul 2011 14:14:59 +0000 (UTC) From: "Vikraman Choudhury" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Vikraman Choudhury" Message-ID: Subject: [gentoo-commits] proj/gentoostats:master commit in: /, server/ X-VCS-Repository: proj/gentoostats X-VCS-Files: .gitignore server/app.py server/config.py server/db.cfg.example server/dbconfig.py X-VCS-Directories: / server/ X-VCS-Committer: vikraman X-VCS-Committer-Name: Vikraman Choudhury X-VCS-Revision: b67120122f77805800208a5e48f7cf39782dcd2f Date: Mon, 11 Jul 2011 14:14:59 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: a9939a1fdc8e137e703c4ad1cbd6dc34 commit: b67120122f77805800208a5e48f7cf39782dcd2f Author: Vikraman Choudhury gmail com> AuthorDate: Mon Jul 11 14:14:32 2011 +0000 Commit: Vikraman Choudhury gmail com> CommitDate: Mon Jul 11 14:14:32 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoostats.g= it;a=3Dcommit;h=3Db6712012 make db configurable --- .gitignore | 1 + server/app.py | 2 +- server/config.py | 11 +++++++---- server/db.cfg.example | 6 ++++++ server/dbconfig.py | 24 ++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index a253c69..7ac969b 100644 --- a/.gitignore +++ b/.gitignore @@ -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 =3D ( r'/host/(.+)', 'Host' ) =20 -app =3D web.application(urls, globals()) +app =3D web.application(urls, globals(), autoreload=3DTrue) =20 app.notfound =3D config.notfound app.internalerror =3D 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 =20 +rootdir =3D os.path.abspath(os.path.dirname(__file__)) + '/' + +dbconfig =3D DBConfig(rootdir + 'db.cfg').get_config() db =3D web.database( dbn=3D'mysql', - user=3D'gentoostats', - pw=3D'poicyurp3ZaddajGhaf', - db=3D'gentoostats' + db=3Ddbconfig['DB'], + user=3Ddbconfig['USER'], + pw=3Ddbconfig['PASS'] ) =20 -rootdir =3D os.path.abspath(os.path.dirname(__file__)) + '/' render =3D web.template.render(rootdir + 'templates/', base=3D'layout') =20 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 =3D gentoostats +USER =3D gentoo +PASS =3D 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 =3D ConfigParser.ConfigParser() + if len(self.config.read(configfile)) =3D=3D 0: + sys.stderr.write('Cannot read ' + configfile) + sys.exit(1) + + def get_config(self): + ret =3D dict() + try: + ret['DB'] =3D self.config.get('MYSQL', 'DB') + ret['USER'] =3D self.config.get('MYSQL', 'USER') + ret['PASS'] =3D self.config.get('MYSQL', 'PASS') + + except ConfigParser.NoSectionError, ConfigParser.NoOptionError: + sys.stderr.write('Invalid db config') + sys.exit(1) + + return ret