Merge branch 'master' of git://repo.or.cz/fpbd-bostik

This commit is contained in:
Worros 2011-02-03 12:17:19 +08:00
commit ae414f1bd6
3 changed files with 29 additions and 9 deletions

View File

@ -415,12 +415,13 @@ class Database:
self.db_name = node.getAttribute("db_name")
self.db_desc = node.getAttribute("db_desc")
self.db_server = node.getAttribute("db_server").lower()
self.db_ip = node.getAttribute("db_ip")
self.db_ip = node.getAttribute("db_ip")
self.db_port = node.getAttribute("db_port")
self.db_user = node.getAttribute("db_user")
self.db_pass = node.getAttribute("db_pass")
self.db_selected = string_to_bool(node.getAttribute("default"), default=False)
log.debug("Database db_name:'%(name)s' db_server:'%(server)s' db_ip:'%(ip)s' db_user:'%(user)s' db_pass (not logged) selected:'%(sel)s'" \
% { 'name':self.db_name, 'server':self.db_server, 'ip':self.db_ip, 'user':self.db_user, 'sel':self.db_selected} )
log.debug("Database db_name:'%(name)s' db_server:'%(server)s' db_ip:'%(ip)s' db_port:'%(port)s' db_user:'%(user)s' db_pass (not logged) selected:'%(sel)s'" \
% { 'name':self.db_name, 'server':self.db_server, 'ip':self.db_ip, 'port':self.db_port, 'user':self.db_user, 'sel':self.db_selected} )
def __str__(self):
temp = 'Database = ' + self.db_name + '\n'
@ -1065,6 +1066,9 @@ class Config:
try: db['db-host'] = self.supported_databases[name].db_ip
except: pass
try: db['db-port'] = self.supported_databases[name].db_port
except KeyError: pass
try: db['db-user'] = self.supported_databases[name].db_user
except: pass
@ -1078,15 +1082,16 @@ class Config:
return db
def set_db_parameters(self, db_name = 'fpdb', db_ip = None, db_user = None,
db_pass = None, db_desc = None, db_server = None,
default = "False"):
def set_db_parameters(self, db_name = 'fpdb', db_ip = None, db_port = None,
db_user = None, db_pass = None, db_desc = None,
db_server = None, default = "False"):
db_node = self.get_db_node(db_name)
default = default.lower()
defaultb = string_to_bool(default, False)
if db_node != None:
if db_desc is not None: db_node.setAttribute("db_desc", db_desc)
if db_ip is not None: db_node.setAttribute("db_ip", db_ip)
if db_port is not None: db_node.setAttribute("db_port", db_port)
if db_user is not None: db_node.setAttribute("db_user", db_user)
if db_pass is not None: db_node.setAttribute("db_pass", db_pass)
if db_server is not None: db_node.setAttribute("db_server", db_server)
@ -1100,6 +1105,7 @@ class Config:
if self.supported_databases.has_key(db_name):
if db_desc is not None: self.supported_databases[db_name].dp_desc = db_desc
if db_ip is not None: self.supported_databases[db_name].dp_ip = db_ip
if db_port is not None: self.supported_databases[db_name].dp_port = db_port
if db_user is not None: self.supported_databases[db_name].dp_user = db_user
if db_pass is not None: self.supported_databases[db_name].dp_pass = db_pass
if db_server is not None: self.supported_databases[db_name].dp_server = db_server
@ -1154,6 +1160,7 @@ class Config:
if self.supported_databases.has_key(db_name):
if db_desc is not None: self.supported_databases[db_name].dp_desc = db_desc
if db_ip is not None: self.supported_databases[db_name].dp_ip = db_ip
if db_port is not None: self.supported_databases[db_name].dp_port = db_port
if db_user is not None: self.supported_databases[db_name].dp_user = db_user
if db_pass is not None: self.supported_databases[db_name].dp_pass = db_pass
if db_server is not None: self.supported_databases[db_name].dp_server = db_server

View File

@ -254,6 +254,7 @@ class Database:
self.db_server = db_params['db-server']
self.database = db_params['db-databaseName']
self.host = db_params['db-host']
self.db_port = db_params['db-port']
self.db_path = ''
gen = c.get_general_params()
self.day_start = 0
@ -349,6 +350,7 @@ class Database:
try:
self.connect(backend=db['db-backend'],
host=db['db-host'],
port=db['db-port'],
database=db['db-databaseName'],
user=db['db-user'],
password=db['db-password'])
@ -363,14 +365,17 @@ class Database:
self.db_server = db_params['db-server']
self.database = db_params['db-databaseName']
self.host = db_params['db-host']
self.db_port = db_params['db-port']
def connect(self, backend=None, host=None, database=None,
user=None, password=None, create=False):
def connect(self, backend=None, host=None, port=None,
database=None, user=None, password=None,
create=False):
"""Connects a database with the given parameters"""
if backend is None:
raise FpdbError('Database backend not defined')
self.backend = backend
self.host = host
self.port = port
self.user = user
self.password = password
self.database = database
@ -382,7 +387,8 @@ class Database:
if use_pool:
MySQLdb = pool.manage(MySQLdb, pool_size=5)
try:
self.connection = MySQLdb.connect(host=host, user=user, passwd=password, db=database, use_unicode=True)
self.connection = MySQLdb.connect(host=host, port=port, user=user,
passwd=password, db=database, use_unicode=True)
self.__connected = True
#TODO: Add port option
except MySQLdb.Error, ex:
@ -416,6 +422,7 @@ class Database:
if not self.is_connected():
try:
self.connection = psycopg2.connect(host = host,
port = port,
user = user,
password = password,
database = database)

View File

@ -796,6 +796,12 @@ Left-Drag to Move"
<raw_tourneys save="none" compression="none"/>
<supported_databases>
<!-- If you have multiple versions of database engine, or you
have the database listening on non-standard port, you can
add the option: db_port="PORTNUMBER"
NOTE: This only applies to users of MySQL and PostgreSQL,
sqlite users can happily ignore.
-->
<!-- <database db_name="fpdb" db_server="mysql" db_ip="localhost" db_user="fpdb" db_pass="YOUR MYSQL PASSWORD"></database> -->
<database db_ip="localhost" db_server="sqlite" db_name="fpdb.db3" db_user="fpdb" db_pass="fpdb"/>
</supported_databases>