[llvm-commits] [zorg] r147507 - in /zorg/trunk/lnt/lnt: lnttool/import_data.py server/config.py server/ui/app.py
Daniel Dunbar
daniel at zuster.org
Tue Jan 3 16:49:49 PST 2012
Author: ddunbar
Date: Tue Jan 3 18:49:49 2012
New Revision: 147507
URL: http://llvm.org/viewvc/llvm-project?rev=147507&view=rev
Log:
[lnt/v0.4] lnt.server.config: Add a get_database method to centralize the version based instantiation, and switch to it.
Modified:
zorg/trunk/lnt/lnt/lnttool/import_data.py
zorg/trunk/lnt/lnt/server/config.py
zorg/trunk/lnt/lnt/server/ui/app.py
Modified: zorg/trunk/lnt/lnt/lnttool/import_data.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/lnttool/import_data.py?rev=147507&r1=147506&r2=147507&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/lnttool/import_data.py (original)
+++ zorg/trunk/lnt/lnt/lnttool/import_data.py Tue Jan 3 18:49:49 2012
@@ -48,19 +48,8 @@
exec open(config) in config_data
config = lnt.server.config.Config.fromData(config, config_data)
- # Get the database entry to use.
- db_entry = config.databases.get(opts.database)
- if db_entry is None:
- parser.error("invalid database name")
-
- # Load the appropriate version of the database.
- if db_entry.db_version == '0.3':
- db = lnt.db.perfdb.PerfDB(db_entry.path, echo=opts.show_sql)
- elif db_entry.db_version == '0.4':
- db = lnt.server.db.v4db.V4DB(db_entry.path, echo=opts.show_sql)
- else:
- raise NotImplementedError,"unable to import to version %r database" % (
- db_entry.db_version,)
+ # Get the database.
+ db = config.get_database(opts.database, echo=opts.show_sql)
# Load the database.
success = True
Modified: zorg/trunk/lnt/lnt/server/config.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/server/config.py?rev=147507&r1=147506&r2=147507&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/server/config.py (original)
+++ zorg/trunk/lnt/lnt/server/config.py Tue Jan 3 18:49:49 2012
@@ -5,6 +5,9 @@
import os
import re
+import lnt.db.perfdb
+import lnt.server.db.v4db
+
class EmailConfig:
@staticmethod
def fromData(data):
@@ -94,3 +97,24 @@
while self.zorgURL.endswith('/'):
self.zorgURL = zorgURL[:-1]
self.databases = databases
+
+ def get_database(self, name, echo=False):
+ """
+ get_database(name, echo=False) -> db or None
+
+ Return the appropriate instance of the database with the given name, or
+ None if there is no database with that name."""
+
+ # Get the database entry.
+ db_entry = self.databases.get(name)
+ if db_entry is None:
+ return None
+
+ # Instantiate the appropriate database version.
+ if db_entry.db_version == '0.3':
+ return lnt.db.perfdb.PerfDB(db_entry.path, echo=echo)
+ if db_entry.db_version == '0.4':
+ return lnt.server.db.v4db.V4DB(db_entry.path, echo=echo)
+
+ raise NotImplementedError,"unable to import to version %r database" % (
+ db_entry.db_version,)
Modified: zorg/trunk/lnt/lnt/server/ui/app.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/server/ui/app.py?rev=147507&r1=147506&r2=147507&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/server/ui/app.py (original)
+++ zorg/trunk/lnt/lnt/server/ui/app.py Tue Jan 3 18:49:49 2012
@@ -44,20 +44,18 @@
def get_db(self):
if self.db is None:
- if g.db_info.db_version == '0.3':
- self.db = perfdb.PerfDB(g.db_info.path)
- else:
- self.db = lnt.server.db.v4db.V4DB(g.db_info.path)
+ echo = bool(self.args.get('db_log') or self.form.get('db_log'))
+
+ self.db = current_app.old_config.get_database(g.db_name, echo=echo)
# Enable SQL logging with db_log.
#
# FIXME: Conditionalize on an is_production variable.
- if self.args.get('db_log') or self.form.get('db_log'):
+ if echo:
import logging, StringIO
g.db_log = StringIO.StringIO()
logger = logging.getLogger("sqlalchemy")
logger.addHandler(logging.StreamHandler(g.db_log))
- self.db.engine.echo = True
return self.db
More information about the llvm-commits
mailing list