too much changes to go into master

This commit is contained in:
Matt Turnbull
2009-08-12 01:46:39 +01:00
parent bd12fc6410
commit 222d713169
11 changed files with 163 additions and 77 deletions
+26 -7
View File
@@ -33,6 +33,11 @@ import shutil
import xml.dom.minidom
from xml.dom.minidom import Node
import logging, logging.config
logging.config.fileConfig("logging.conf")
log = logging.getLogger("config")
log.debug("config logger initialised")
def fix_tf(x, default = True):
# The xml parser doesn't translate "True" to True. Therefore, we never get
# True or False from the parser only "True" or "False". So translate the
@@ -193,6 +198,9 @@ class Database:
self.db_user = node.getAttribute("db_user")
self.db_type = node.getAttribute("db_type")
self.db_pass = node.getAttribute("db_pass")
self.db_selected = fix_tf(node.getAttribute("default"),"False")
log.debug("Database db_name:'%(name)s' db_server:'%(server)s' db_ip:'%(ip)s' db_user:'%(user)s' db_type:'%(type)s' db_pass (not logged) selected:'%(sel)s'" \
% { 'name':self.db_name, 'server':self.db_server, 'ip':self.db_ip, 'user':self.db_user, 'type':self.db_type, 'sel':self.db_selected} )
def __str__(self):
temp = 'Database = ' + self.db_name + '\n'
@@ -271,11 +279,10 @@ class Tv:
(self.combinedStealFold, self.combined2B3B, self.combinedPostflop) )
class Config:
def __init__(self, file = None, dbname = 'fpdb'):
def __init__(self, file = None, dbname = ''):
# "file" is a path to an xml file with the fpdb/HUD configuration
# we check the existence of "file" and try to recover if it doesn't exist
self.dbname = dbname
self.default_config_path = self.get_default_config_path()
if file != None: # configuration file path has been passed
@@ -301,10 +308,10 @@ class Config:
# Parse even if there was no real config file found and we are using the example
# If using the example, we'll edit it later
try:
print "Reading configuration file %s\n" % (file)
log.info("Reading configuration file %s" % (file))
doc = xml.dom.minidom.parse(file)
except:
print "Error parsing %s. See error log file." % (file)
log.error("Error parsing %s. See error log file." % (file))
traceback.print_exc(file=sys.stderr)
print "press enter to continue"
sys.stdin.readline()
@@ -330,9 +337,21 @@ class Config:
self.supported_games[game.game_name] = game
# s_dbs = doc.getElementsByTagName("supported_databases")
if dbname and dbname in self.supported_databases:
self.db_selected = dbname
for db_node in doc.getElementsByTagName("database"):
db = Database(node = db_node)
self.supported_databases[db.db_name] = db
try:
db = Database(node = db_node)
if db.db_name in self.supported_databases:
raise FpdbError("Database names must be unique")
# If there is only one Database node, or none are marked default, the first is selected
if len(self.supported_databases) == 0:
self.db_selected = db.db_name
self.supported_databases[db.db_name] = db
if db.db_selected:
self.db_selected = db.db_name
except:
raise
# s_dbs = doc.getElementsByTagName("mucked_windows")
for aw_node in doc.getElementsByTagName("aw"):
@@ -499,7 +518,7 @@ class Config:
def get_db_parameters(self):
db = {}
name = self.dbname
name = self.db_selected
try: db['db-databaseName'] = name
except: pass