Merge branch 'master' of git://git.assembla.com/fpdb-sql
This commit is contained in:
commit
3e90f42e89
|
@ -39,7 +39,8 @@ import SQL
|
||||||
import Card
|
import Card
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
def __init__(self, c, db_name = None, game = None): # db_name and game not used any more
|
def __init__(self, c, db_name = None, game = None, sql = None): # db_name and game not used any more
|
||||||
|
print "creating Database instance, sql =", sql
|
||||||
self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql
|
self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql
|
||||||
self.fdb.do_connect(c)
|
self.fdb.do_connect(c)
|
||||||
self.connection = self.fdb.db
|
self.connection = self.fdb.db
|
||||||
|
@ -48,7 +49,12 @@ class Database:
|
||||||
self.import_options = c.get_import_parameters()
|
self.import_options = c.get_import_parameters()
|
||||||
self.type = db_params['db-type']
|
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']
|
||||||
|
# where possible avoid creating new SQL instance by using the global one passed in
|
||||||
|
if sql == None:
|
||||||
self.sql = SQL.Sql(type = self.type, db_server = db_params['db-server'])
|
self.sql = SQL.Sql(type = self.type, db_server = db_params['db-server'])
|
||||||
|
else:
|
||||||
|
self.sql = sql
|
||||||
self.connection.rollback()
|
self.connection.rollback()
|
||||||
|
|
||||||
# To add to config:
|
# To add to config:
|
||||||
|
|
|
@ -231,7 +231,7 @@ def discover_nt_by_name(c, tablename):
|
||||||
titles = {}
|
titles = {}
|
||||||
win32gui.EnumWindows(win_enum_handler, titles)
|
win32gui.EnumWindows(win_enum_handler, titles)
|
||||||
for hwnd in titles:
|
for hwnd in titles:
|
||||||
print "Tbales.py: tablename =", tablename, "title =", titles[hwnd]
|
#print "Tables.py: tablename =", tablename, "title =", titles[hwnd]
|
||||||
try:
|
try:
|
||||||
# this can blow up in XP on some windows, eg firefox displaying http://docs.python.org/tutorial/classes.html
|
# this can blow up in XP on some windows, eg firefox displaying http://docs.python.org/tutorial/classes.html
|
||||||
if not tablename in titles[hwnd]: continue
|
if not tablename in titles[hwnd]: continue
|
||||||
|
|
|
@ -41,6 +41,7 @@ import GuiTableViewer
|
||||||
import GuiAutoImport
|
import GuiAutoImport
|
||||||
import GuiGraphViewer
|
import GuiGraphViewer
|
||||||
import GuiSessionViewer
|
import GuiSessionViewer
|
||||||
|
import SQL
|
||||||
import Database
|
import Database
|
||||||
import FpdbSQLQueries
|
import FpdbSQLQueries
|
||||||
import Configuration
|
import Configuration
|
||||||
|
@ -179,20 +180,21 @@ class fpdb:
|
||||||
def dia_load_profile(self, widget, data=None):
|
def dia_load_profile(self, widget, data=None):
|
||||||
"""Dialogue to select a file to load a profile from"""
|
"""Dialogue to select a file to load a profile from"""
|
||||||
if self.obtain_global_lock() == 0: # returns 0 if successful
|
if self.obtain_global_lock() == 0: # returns 0 if successful
|
||||||
try:
|
#try:
|
||||||
chooser = gtk.FileChooserDialog(title="Please select a profile file to load",
|
# chooser = gtk.FileChooserDialog(title="Please select a profile file to load",
|
||||||
action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
# action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||||
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
|
# buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
|
||||||
chooser.set_filename(self.profile)
|
# chooser.set_filename(self.profile)
|
||||||
|
|
||||||
response = chooser.run()
|
# response = chooser.run()
|
||||||
chooser.destroy()
|
# chooser.destroy()
|
||||||
if response == gtk.RESPONSE_OK:
|
# if response == gtk.RESPONSE_OK:
|
||||||
self.load_profile(chooser.get_filename())
|
# self.load_profile(chooser.get_filename())
|
||||||
elif response == gtk.RESPONSE_CANCEL:
|
# elif response == gtk.RESPONSE_CANCEL:
|
||||||
print 'User cancelled loading profile'
|
# print 'User cancelled loading profile'
|
||||||
except:
|
#except:
|
||||||
pass
|
# pass
|
||||||
|
self.load_profile()
|
||||||
self.release_global_lock()
|
self.release_global_lock()
|
||||||
#end def dia_load_profile
|
#end def dia_load_profile
|
||||||
|
|
||||||
|
@ -347,6 +349,7 @@ class fpdb:
|
||||||
|
|
||||||
def load_profile(self):
|
def load_profile(self):
|
||||||
"""Loads profile from the provided path name."""
|
"""Loads profile from the provided path name."""
|
||||||
|
self.config = Configuration.Config(file=options.config, dbname=options.dbname)
|
||||||
self.settings = {}
|
self.settings = {}
|
||||||
if (os.sep=="/"):
|
if (os.sep=="/"):
|
||||||
self.settings['os']="linuxmac"
|
self.settings['os']="linuxmac"
|
||||||
|
@ -383,9 +386,17 @@ class fpdb:
|
||||||
response = diaDbVersionWarning.run()
|
response = diaDbVersionWarning.run()
|
||||||
diaDbVersionWarning.destroy()
|
diaDbVersionWarning.destroy()
|
||||||
|
|
||||||
|
if self.status_bar == None:
|
||||||
|
self.status_bar = gtk.Label("Status: Connected to %s database named %s on host %s"%(self.db.get_backend_name(),self.db.database, self.db.host))
|
||||||
|
self.main_vbox.pack_end(self.status_bar, False, True, 0)
|
||||||
|
self.status_bar.show()
|
||||||
|
else:
|
||||||
|
self.status_bar.set_text("Status: Connected to %s database named %s on host %s" % (self.db.get_backend_name(),self.db.database, self.db.host))
|
||||||
|
|
||||||
# Database connected to successfully, load queries to pass on to other classes
|
# Database connected to successfully, load queries to pass on to other classes
|
||||||
self.querydict = FpdbSQLQueries.FpdbSQLQueries(self.db.get_backend_name())
|
self.querydict = FpdbSQLQueries.FpdbSQLQueries(self.db.get_backend_name())
|
||||||
self.dbi = Database.Database(self.config) # dbi for db interface and to avoid clashes with db/database/etc
|
self.sql = SQL.Sql(type = self.settings['db-type'], db_server = self.settings['db-server'])
|
||||||
|
self.dbi = Database.Database(self.config, sql = self.sql) # dbi for db interface and to avoid clashes with db/database/etc
|
||||||
# can rename later if required
|
# can rename later if required
|
||||||
self.db.db.rollback()
|
self.db.db.rollback()
|
||||||
#end def load_profile
|
#end def load_profile
|
||||||
|
@ -476,10 +487,9 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt")
|
||||||
#end def tabGraphViewer
|
#end def tabGraphViewer
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.threads=[]
|
self.threads = []
|
||||||
self.db=None
|
self.db = None
|
||||||
self.config = Configuration.Config(file=options.config, dbname=options.dbname)
|
self.status_bar = None
|
||||||
self.load_profile()
|
|
||||||
|
|
||||||
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||||
self.window.connect("delete_event", self.delete_event)
|
self.window.connect("delete_event", self.delete_event)
|
||||||
|
@ -514,11 +524,8 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt")
|
||||||
|
|
||||||
self.tab_main_help(None, None)
|
self.tab_main_help(None, None)
|
||||||
|
|
||||||
self.status_bar = gtk.Label("Status: Connected to %s database named %s on host %s"%(self.db.get_backend_name(),self.db.database, self.db.host))
|
|
||||||
self.main_vbox.pack_end(self.status_bar, False, True, 0)
|
|
||||||
self.status_bar.show()
|
|
||||||
|
|
||||||
self.window.show()
|
self.window.show()
|
||||||
|
self.load_profile()
|
||||||
sys.stderr.write("fpdb starting ...")
|
sys.stderr.write("fpdb starting ...")
|
||||||
#end def __init__
|
#end def __init__
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ import re
|
||||||
|
|
||||||
import fpdb_simple
|
import fpdb_simple
|
||||||
import fpdb_db
|
import fpdb_db
|
||||||
|
import Database
|
||||||
import fpdb_parse_logic
|
import fpdb_parse_logic
|
||||||
import Configuration
|
import Configuration
|
||||||
|
|
||||||
|
@ -57,7 +58,8 @@ class Importer:
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
self.caller = caller
|
self.caller = caller
|
||||||
self.config = config
|
self.config = config
|
||||||
self.fdb = None
|
self.database = None # database will be the main db interface eventually
|
||||||
|
self.fdb = None # fdb may disappear or just hold the simple db connection
|
||||||
self.cursor = None
|
self.cursor = None
|
||||||
self.filelist = {}
|
self.filelist = {}
|
||||||
self.dirlist = {}
|
self.dirlist = {}
|
||||||
|
@ -75,6 +77,7 @@ class Importer:
|
||||||
self.settings.setdefault("minPrint", 30)
|
self.settings.setdefault("minPrint", 30)
|
||||||
self.settings.setdefault("handCount", 0)
|
self.settings.setdefault("handCount", 0)
|
||||||
|
|
||||||
|
self.database = Database.Database(self.config) # includes .connection and .sql variables
|
||||||
self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql
|
self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql
|
||||||
self.fdb.do_connect(self.config)
|
self.fdb.do_connect(self.config)
|
||||||
self.fdb.db.rollback()
|
self.fdb.db.rollback()
|
||||||
|
@ -392,8 +395,9 @@ class Importer:
|
||||||
self.hand=hand
|
self.hand=hand
|
||||||
|
|
||||||
try:
|
try:
|
||||||
handsId = fpdb_parse_logic.mainParser(self.settings, self.fdb
|
handsId = fpdb_parse_logic.mainParser( self.settings, self.fdb
|
||||||
, self.siteIds[site], category, hand, self.config)
|
, self.siteIds[site], category, hand
|
||||||
|
, self.config, self.database )
|
||||||
self.fdb.db.commit()
|
self.fdb.db.commit()
|
||||||
|
|
||||||
stored += 1
|
stored += 1
|
||||||
|
|
|
@ -21,10 +21,13 @@ import fpdb_simple
|
||||||
import Database
|
import Database
|
||||||
|
|
||||||
#parses a holdem hand
|
#parses a holdem hand
|
||||||
def mainParser(settings, fdb, siteID, category, hand, config):
|
def mainParser(settings, fdb, siteID, category, hand, config, db = None):
|
||||||
backend = settings['db-backend']
|
backend = settings['db-backend']
|
||||||
#This is redundant - hopefully fdb will be a Database object in an interation soon
|
if db == None:
|
||||||
db = Database.Database(config, 'fpdb', '')
|
#This is redundant - hopefully fdb will be a Database object in an iteration soon
|
||||||
|
db = Database.Database(c = config, sql = None)
|
||||||
|
else:
|
||||||
|
db = db
|
||||||
category = fpdb_simple.recogniseCategory(hand[0])
|
category = fpdb_simple.recogniseCategory(hand[0])
|
||||||
|
|
||||||
base = "hold" if category == "holdem" or category == "omahahi" or category == "omahahilo" else "stud"
|
base = "hold" if category == "holdem" or category == "omahahi" or category == "omahahilo" else "stud"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user