Merge branch 'master' of git://git.assembla.com/fpdb-mme
Conflicts: pyfpdb/Configuration.py
This commit is contained in:
commit
bea6bf2d6b
|
@ -50,6 +50,10 @@ log.debug("config logger initialised")
|
||||||
APPLICATION_NAME_SHORT = 'fpdb'
|
APPLICATION_NAME_SHORT = 'fpdb'
|
||||||
APPLICATION_VERSION = 'xx.xx.xx'
|
APPLICATION_VERSION = 'xx.xx.xx'
|
||||||
|
|
||||||
|
DIR_SELF = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
#TODO: imo no good idea to place 'database' in parent dir
|
||||||
|
DIR_DATABASES = os.path.join(os.path.dirname(DIR_SELF), 'database')
|
||||||
|
|
||||||
DATABASE_TYPE_POSTGRESQL = 'postgresql'
|
DATABASE_TYPE_POSTGRESQL = 'postgresql'
|
||||||
DATABASE_TYPE_SQLITE = 'sqlite'
|
DATABASE_TYPE_SQLITE = 'sqlite'
|
||||||
DATABASE_TYPE_MYSQL = 'mysql'
|
DATABASE_TYPE_MYSQL = 'mysql'
|
||||||
|
@ -218,14 +222,13 @@ class Game:
|
||||||
class Database:
|
class Database:
|
||||||
def __init__(self, node):
|
def __init__(self, node):
|
||||||
self.db_name = node.getAttribute("db_name")
|
self.db_name = node.getAttribute("db_name")
|
||||||
self.db_server = node.getAttribute("db_server")
|
self.db_server = node.getAttribute("db_server").lower()
|
||||||
self.db_ip = node.getAttribute("db_ip")
|
self.db_ip = node.getAttribute("db_ip")
|
||||||
self.db_user = node.getAttribute("db_user")
|
self.db_user = node.getAttribute("db_user")
|
||||||
self.db_type = node.getAttribute("db_type")
|
|
||||||
self.db_pass = node.getAttribute("db_pass")
|
self.db_pass = node.getAttribute("db_pass")
|
||||||
self.db_selected = string_to_bool(node.getAttribute("default"), default=False)
|
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_type:'%(type)s' db_pass (not logged) selected:'%(sel)s'" \
|
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, 'type':self.db_type, 'sel':self.db_selected} )
|
% { 'name':self.db_name, 'server':self.db_server, 'ip':self.db_ip, 'user':self.db_user, 'sel':self.db_selected} )
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
temp = 'Database = ' + self.db_name + '\n'
|
temp = 'Database = ' + self.db_name + '\n'
|
||||||
|
@ -318,9 +321,9 @@ class HudUI:
|
||||||
|
|
||||||
class Tv:
|
class Tv:
|
||||||
def __init__(self, node):
|
def __init__(self, node):
|
||||||
self.combinedStealFold = node.getAttribute("combinedStealFold")
|
self.combinedStealFold = string_to_bool(node.getAttribute("combinedStealFold"), default=True)
|
||||||
self.combined2B3B = node.getAttribute("combined2B3B")
|
self.combined2B3B = string_to_bool(node.getAttribute("combined2B3B"), default=True)
|
||||||
self.combinedPostflop = node.getAttribute("combinedPostflop")
|
self.combinedPostflop = string_to_bool(node.getAttribute("combinedPostflop"), default=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return (" combinedStealFold = %s\n combined2B3B = %s\n combinedPostflop = %s\n" %
|
return (" combinedStealFold = %s\n combined2B3B = %s\n combinedPostflop = %s\n" %
|
||||||
|
@ -380,6 +383,8 @@ class Config:
|
||||||
self.hhcs = {}
|
self.hhcs = {}
|
||||||
self.popup_windows = {}
|
self.popup_windows = {}
|
||||||
self.db_selected = None # database the user would like to use
|
self.db_selected = None # database the user would like to use
|
||||||
|
self.tv = None
|
||||||
|
|
||||||
|
|
||||||
# s_sites = doc.getElementsByTagName("supported_sites")
|
# s_sites = doc.getElementsByTagName("supported_sites")
|
||||||
for site_node in doc.getElementsByTagName("site"):
|
for site_node in doc.getElementsByTagName("site"):
|
||||||
|
@ -436,8 +441,7 @@ class Config:
|
||||||
self.ui = hui
|
self.ui = hui
|
||||||
|
|
||||||
for tv_node in doc.getElementsByTagName("tv"):
|
for tv_node in doc.getElementsByTagName("tv"):
|
||||||
tv = Tv(node = tv_node)
|
self.tv = Tv(node = tv_node)
|
||||||
self.tv = tv
|
|
||||||
|
|
||||||
db = self.get_db_parameters()
|
db = self.get_db_parameters()
|
||||||
if db['db-password'] == 'YOUR MYSQL PASSWORD':
|
if db['db-password'] == 'YOUR MYSQL PASSWORD':
|
||||||
|
@ -554,8 +558,8 @@ class Config:
|
||||||
self.doc.writexml(f)
|
self.doc.writexml(f)
|
||||||
else:
|
else:
|
||||||
shutil.move(self.file, self.file+".backup")
|
shutil.move(self.file, self.file+".backup")
|
||||||
with open(self.file, 'w') as f:
|
with open(file, 'w') as f:
|
||||||
self.doc.writexml(f)
|
self.doc.writexml(f)
|
||||||
|
|
||||||
def edit_layout(self, site_name, max, width = None, height = None,
|
def edit_layout(self, site_name, max, width = None, height = None,
|
||||||
fav_seat = None, locations = None):
|
fav_seat = None, locations = None):
|
||||||
|
@ -612,20 +616,18 @@ class Config:
|
||||||
try: db['db-server'] = self.supported_databases[name].db_server
|
try: db['db-server'] = self.supported_databases[name].db_server
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
try: db['db-type'] = self.supported_databases[name].db_type
|
if self.supported_databases[name].db_server== DATABASE_TYPE_MYSQL:
|
||||||
except: pass
|
|
||||||
|
|
||||||
if string.lower(self.supported_databases[name].db_server) == 'mysql':
|
|
||||||
db['db-backend'] = 2
|
db['db-backend'] = 2
|
||||||
elif string.lower(self.supported_databases[name].db_server) == 'postgresql':
|
elif self.supported_databases[name].db_server== DATABASE_TYPE_POSTGRESQL:
|
||||||
db['db-backend'] = 3
|
db['db-backend'] = 3
|
||||||
elif string.lower(self.supported_databases[name].db_server) == 'sqlite':
|
elif self.supported_databases[name].db_server== DATABASE_TYPE_SQLITE:
|
||||||
db['db-backend'] = 4
|
db['db-backend'] = 4
|
||||||
else: db['db-backend'] = None # this is big trouble
|
else:
|
||||||
|
raise ValueError('Unsupported database backend: %s' % self.supported_databases[name].db_server)
|
||||||
return db
|
return db
|
||||||
|
|
||||||
def set_db_parameters(self, db_name = 'fpdb', db_ip = None, db_user = None,
|
def set_db_parameters(self, db_name = 'fpdb', db_ip = None, db_user = None,
|
||||||
db_pass = None, db_server = None, db_type = None):
|
db_pass = None, db_server = None):
|
||||||
db_node = self.get_db_node(db_name)
|
db_node = self.get_db_node(db_name)
|
||||||
if db_node != None:
|
if db_node != None:
|
||||||
if db_ip is not None: db_node.setAttribute("db_ip", db_ip)
|
if db_ip is not None: db_node.setAttribute("db_ip", db_ip)
|
||||||
|
@ -649,16 +651,13 @@ class Config:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_tv_parameters(self):
|
def get_tv_parameters(self):
|
||||||
tv = {}
|
if self.tv is not None:
|
||||||
try: tv['combinedStealFold'] = self.tv.combinedStealFold
|
return {
|
||||||
except: tv['combinedStealFold'] = True
|
'combinedStealFold': self.tv.combinedStealFold,
|
||||||
|
'combined2B3B': self.tv.combined2B3B,
|
||||||
try: tv['combined2B3B'] = self.tv.combined2B3B
|
'combinedPostflop': self.tv.combinedPostflop
|
||||||
except: tv['combined2B3B'] = True
|
}
|
||||||
|
return {}
|
||||||
try: tv['combinedPostflop'] = self.tv.combinedPostflop
|
|
||||||
except: tv['combinedPostflop'] = True
|
|
||||||
return tv
|
|
||||||
|
|
||||||
# Allow to change the menu appearance
|
# Allow to change the menu appearance
|
||||||
def get_hud_ui_parameters(self):
|
def get_hud_ui_parameters(self):
|
||||||
|
@ -756,31 +755,29 @@ class Config:
|
||||||
colors['hudfgcolor'] = self.supported_sites[site].hudfgcolor
|
colors['hudfgcolor'] = self.supported_sites[site].hudfgcolor
|
||||||
return colors
|
return colors
|
||||||
|
|
||||||
def get_default_font(self, site = 'PokerStars'):
|
def get_default_font(self, site='PokerStars'):
|
||||||
(font, font_size) = ("Sans", "8")
|
font = "Sans"
|
||||||
if site not in self.supported_sites:
|
font_size = "8"
|
||||||
return ("Sans", "8")
|
site = self.supported_sites.get(site, None)
|
||||||
if self.supported_sites[site].font == "":
|
if site is not None:
|
||||||
font = "Sans"
|
if site.font:
|
||||||
else:
|
font = site.font
|
||||||
font = self.supported_sites[site].font
|
if site.font_size:
|
||||||
|
font_size = site.font_size
|
||||||
if self.supported_sites[site].font_size == "":
|
return font, font_size
|
||||||
font_size = "8"
|
|
||||||
else:
|
|
||||||
font_size = self.supported_sites[site].font_size
|
|
||||||
return (font, font_size)
|
|
||||||
|
|
||||||
def get_locations(self, site = "PokerStars", max = "8"):
|
|
||||||
|
|
||||||
try:
|
|
||||||
locations = self.supported_sites[site].layout[max].location
|
|
||||||
except:
|
|
||||||
locations = ( ( 0, 0), (684, 61), (689, 239), (692, 346),
|
|
||||||
(586, 393), (421, 440), (267, 440), ( 0, 361),
|
|
||||||
( 0, 280), (121, 280), ( 46, 30) )
|
|
||||||
return locations
|
|
||||||
|
|
||||||
|
def get_locations(self, site_name="PokerStars", max=8):
|
||||||
|
site = self.supported_sites.get(site_name, None)
|
||||||
|
if site is not None:
|
||||||
|
location = site.layout.get(max, None)
|
||||||
|
if location is not None:
|
||||||
|
return location.location
|
||||||
|
return (
|
||||||
|
( 0, 0), (684, 61), (689, 239), (692, 346),
|
||||||
|
(586, 393), (421, 440), (267, 440), ( 0, 361),
|
||||||
|
( 0, 280), (121, 280), ( 46, 30)
|
||||||
|
)
|
||||||
|
|
||||||
def get_aux_locations(self, aux = "mucked", max = "9"):
|
def get_aux_locations(self, aux = "mucked", max = "9"):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -791,15 +788,13 @@ class Config:
|
||||||
( 0, 280), (121, 280), ( 46, 30) )
|
( 0, 280), (121, 280), ( 46, 30) )
|
||||||
return locations
|
return locations
|
||||||
|
|
||||||
def get_supported_sites(self, all = False):
|
def get_supported_sites(self, all=False):
|
||||||
"""Returns the list of supported sites."""
|
"""Returns the list of supported sites."""
|
||||||
the_sites = []
|
if all:
|
||||||
for site in self.supported_sites.keys():
|
return self.supported_sites.keys()
|
||||||
params = self.get_site_parameters(site)
|
else:
|
||||||
if all or params['enabled']:
|
return [site_name for (site_name, site) in self.supported_sites.items() if site.enabled]
|
||||||
the_sites.append(site)
|
|
||||||
return the_sites
|
|
||||||
|
|
||||||
def get_site_parameters(self, site):
|
def get_site_parameters(self, site):
|
||||||
"""Returns a dict of the site parameters for the specified site"""
|
"""Returns a dict of the site parameters for the specified site"""
|
||||||
parms = {}
|
parms = {}
|
||||||
|
@ -846,10 +841,7 @@ class Config:
|
||||||
|
|
||||||
def get_aux_windows(self):
|
def get_aux_windows(self):
|
||||||
"""Gets the list of mucked window formats in the configuration."""
|
"""Gets the list of mucked window formats in the configuration."""
|
||||||
mw = []
|
return self.aux_windows.keys()
|
||||||
for w in self.aux_windows.keys():
|
|
||||||
mw.append(w)
|
|
||||||
return mw
|
|
||||||
|
|
||||||
def get_aux_parameters(self, name):
|
def get_aux_parameters(self, name):
|
||||||
"""Gets a dict of mucked window parameters from the named mw."""
|
"""Gets a dict of mucked window parameters from the named mw."""
|
||||||
|
|
|
@ -205,7 +205,7 @@ class Database:
|
||||||
|
|
||||||
# where possible avoid creating new SQL instance by using the global one passed in
|
# where possible avoid creating new SQL instance by using the global one passed in
|
||||||
if sql is None:
|
if sql is None:
|
||||||
self.sql = SQL.Sql(type = self.type, db_server = self.db_server)
|
self.sql = SQL.Sql(db_server = self.db_server)
|
||||||
else:
|
else:
|
||||||
self.sql = sql
|
self.sql = sql
|
||||||
|
|
||||||
|
@ -249,7 +249,6 @@ class Database:
|
||||||
|
|
||||||
db_params = c.get_db_parameters()
|
db_params = c.get_db_parameters()
|
||||||
self.import_options = c.get_import_parameters()
|
self.import_options = c.get_import_parameters()
|
||||||
self.type = db_params['db-type']
|
|
||||||
self.backend = db_params['db-backend']
|
self.backend = db_params['db-backend']
|
||||||
self.db_server = db_params['db-server']
|
self.db_server = db_params['db-server']
|
||||||
self.database = db_params['db-databaseName']
|
self.database = db_params['db-databaseName']
|
||||||
|
|
|
@ -50,10 +50,10 @@ class DatabaseManager(gobject.GObject):
|
||||||
#TODO: fpdb stores databases in no particular order. this has to be fixed somehow
|
#TODO: fpdb stores databases in no particular order. this has to be fixed somehow
|
||||||
databases = []
|
databases = []
|
||||||
for name, fpdbDatabase in config.supported_databases.items():
|
for name, fpdbDatabase in config.supported_databases.items():
|
||||||
databaseKlass = klass.DatabaseTypes.get(fpdbDatabase.db_type, None)
|
databaseKlass = klass.DatabaseTypes.get(fpdbDatabase.db_server, None)
|
||||||
#NOTE: Config does not seem to validate user input, so anything may end up here
|
#NOTE: Config does not seem to validate user input, so anything may end up here
|
||||||
if databaseKlass is None:
|
if databaseKlass is None:
|
||||||
raise ValueError('Unknown databasetype: %s' % fpdbDatabase.db_type)
|
raise ValueError('Unknown databasetype: %s' % fpdbDatabase.db_server)
|
||||||
|
|
||||||
database = databaseKlass()
|
database = databaseKlass()
|
||||||
if database.Type == 'sqlite':
|
if database.Type == 'sqlite':
|
||||||
|
|
|
@ -570,8 +570,8 @@ Left-Drag to Move"
|
||||||
</hhcs>
|
</hhcs>
|
||||||
|
|
||||||
<supported_databases>
|
<supported_databases>
|
||||||
<database db_name="fpdb" db_server="mysql" db_ip="localhost" db_user="fpdb" db_pass="YOUR MYSQL PASSWORD" db_type="fpdb"></database>
|
<database db_name="fpdb" db_server="mysql" db_ip="localhost" db_user="fpdb" db_pass="YOUR MYSQL PASSWORD"></database>
|
||||||
<!-- <database db_ip="localhost" db_name="fpdb" db_pass="fpdb" db_server="sqlite" db_type="fpdb" db_user="fpdb"/> -->
|
<!-- <database db_ip="localhost" db_name="fpdb" db_pass="fpdb" db_server="sqlite" db_user="fpdb"/> -->
|
||||||
</supported_databases>
|
</supported_databases>
|
||||||
|
|
||||||
</FreePokerToolsConfig>
|
</FreePokerToolsConfig>
|
||||||
|
|
|
@ -37,7 +37,8 @@ if __name__== "__main__":
|
||||||
HUD_main.config = Configuration.Config()
|
HUD_main.config = Configuration.Config()
|
||||||
|
|
||||||
gobject.threads_init() # this is required
|
gobject.threads_init() # this is required
|
||||||
thread.start_new_thread(HUD_main.read_stdin, ()) # starts the thread
|
hud = HUD_main.HUD_main()
|
||||||
|
thread.start_new_thread(hud.read_stdin, ()) # starts the thread
|
||||||
|
|
||||||
HUD_main.main_window = gtk.Window()
|
HUD_main.main_window = gtk.Window()
|
||||||
HUD_main.main_window.connect("destroy", destroy)
|
HUD_main.main_window.connect("destroy", destroy)
|
||||||
|
|
6389
pyfpdb/SQL.py
6389
pyfpdb/SQL.py
File diff suppressed because it is too large
Load Diff
|
@ -450,7 +450,7 @@ class fpdb:
|
||||||
if self.db is not None and self.db.fdb is not None:
|
if self.db is not None and self.db.fdb is not None:
|
||||||
self.db.disconnect()
|
self.db.disconnect()
|
||||||
|
|
||||||
self.sql = SQL.Sql(type = self.settings['db-type'], db_server = self.settings['db-server'])
|
self.sql = SQL.Sql(db_server = self.settings['db-server'])
|
||||||
try:
|
try:
|
||||||
self.db = Database.Database(self.config, sql = self.sql)
|
self.db = Database.Database(self.config, sql = self.sql)
|
||||||
except FpdbMySQLFailedError:
|
except FpdbMySQLFailedError:
|
||||||
|
|
|
@ -33,12 +33,12 @@ except ImportError:
|
||||||
|
|
||||||
import fpdb_simple
|
import fpdb_simple
|
||||||
import FpdbSQLQueries
|
import FpdbSQLQueries
|
||||||
|
import Configuration
|
||||||
|
|
||||||
class fpdb_db:
|
class fpdb_db:
|
||||||
MYSQL_INNODB = 2
|
MYSQL_INNODB = 2
|
||||||
PGSQL = 3
|
PGSQL = 3
|
||||||
SQLITE = 4
|
SQLITE = 4
|
||||||
sqlite_db_dir = ".." + os.sep + "database"
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Simple constructor, doesnt really do anything"""
|
"""Simple constructor, doesnt really do anything"""
|
||||||
|
@ -123,10 +123,10 @@ class fpdb_db:
|
||||||
else:
|
else:
|
||||||
logging.warning("SQLite won't work well without 'sqlalchemy' installed.")
|
logging.warning("SQLite won't work well without 'sqlalchemy' installed.")
|
||||||
|
|
||||||
if not os.path.isdir(self.sqlite_db_dir):
|
if not os.path.isdir(Configuration.DIR_DATABASES):
|
||||||
print "Creating directory: '%s'" % (self.sqlite_db_dir)
|
print "Creating directory: '%s'" % (Configuration.DIR_DATABASES)
|
||||||
os.mkdir(self.sqlite_db_dir)
|
os.mkdir(Configuration.DIR_DATABASES)
|
||||||
self.db = sqlite3.connect( self.sqlite_db_dir + os.sep + database
|
self.db = sqlite3.connect( os.path.join(Configuration.DIR_DATABASES, database)
|
||||||
, detect_types=sqlite3.PARSE_DECLTYPES )
|
, detect_types=sqlite3.PARSE_DECLTYPES )
|
||||||
sqlite3.register_converter("bool", lambda x: bool(int(x)))
|
sqlite3.register_converter("bool", lambda x: bool(int(x)))
|
||||||
sqlite3.register_adapter(bool, lambda x: "1" if x else "0")
|
sqlite3.register_adapter(bool, lambda x: "1" if x else "0")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user