diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index f652d9a7..2cade5de 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -39,7 +39,8 @@ import SQL import Card 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.do_connect(c) self.connection = self.fdb.db @@ -48,7 +49,12 @@ class Database: self.import_options = c.get_import_parameters() self.type = db_params['db-type'] self.backend = db_params['db-backend'] - self.sql = SQL.Sql(type = self.type, db_server = db_params['db-server']) + 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']) + else: + self.sql = sql self.connection.rollback() # To add to config: diff --git a/pyfpdb/Tables.py b/pyfpdb/Tables.py index ead3beba..dcd145f4 100755 --- a/pyfpdb/Tables.py +++ b/pyfpdb/Tables.py @@ -231,7 +231,7 @@ def discover_nt_by_name(c, tablename): titles = {} win32gui.EnumWindows(win_enum_handler, titles) for hwnd in titles: - print "Tbales.py: tablename =", tablename, "title =", titles[hwnd] + #print "Tables.py: tablename =", tablename, "title =", titles[hwnd] try: # 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 diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index b36c62bb..6c982002 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -41,6 +41,7 @@ import GuiTableViewer import GuiAutoImport import GuiGraphViewer import GuiSessionViewer +import SQL import Database import FpdbSQLQueries import Configuration @@ -179,20 +180,21 @@ class fpdb: def dia_load_profile(self, widget, data=None): """Dialogue to select a file to load a profile from""" if self.obtain_global_lock() == 0: # returns 0 if successful - try: - chooser = gtk.FileChooserDialog(title="Please select a profile file to load", - action=gtk.FILE_CHOOSER_ACTION_OPEN, - buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)) - chooser.set_filename(self.profile) + #try: + # chooser = gtk.FileChooserDialog(title="Please select a profile file to load", + # action=gtk.FILE_CHOOSER_ACTION_OPEN, + # buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)) + # chooser.set_filename(self.profile) - response = chooser.run() - chooser.destroy() - if response == gtk.RESPONSE_OK: - self.load_profile(chooser.get_filename()) - elif response == gtk.RESPONSE_CANCEL: - print 'User cancelled loading profile' - except: - pass + # response = chooser.run() + # chooser.destroy() + # if response == gtk.RESPONSE_OK: + # self.load_profile(chooser.get_filename()) + # elif response == gtk.RESPONSE_CANCEL: + # print 'User cancelled loading profile' + #except: + # pass + self.load_profile() self.release_global_lock() #end def dia_load_profile @@ -347,6 +349,7 @@ class fpdb: def load_profile(self): """Loads profile from the provided path name.""" + self.config = Configuration.Config(file=options.config, dbname=options.dbname) self.settings = {} if (os.sep=="/"): self.settings['os']="linuxmac" @@ -383,10 +386,18 @@ class fpdb: response = diaDbVersionWarning.run() 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 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 - # can rename later if required + 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 self.db.db.rollback() #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 def __init__(self): - self.threads=[] - self.db=None - self.config = Configuration.Config(file=options.config, dbname=options.dbname) - self.load_profile() + self.threads = [] + self.db = None + self.status_bar = None self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) 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.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.load_profile() sys.stderr.write("fpdb starting ...") #end def __init__ diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 455c1e27..2468fecf 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -31,6 +31,7 @@ import re import fpdb_simple import fpdb_db +import Database import fpdb_parse_logic import Configuration @@ -57,7 +58,8 @@ class Importer: self.settings = settings self.caller = caller 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.filelist = {} self.dirlist = {} @@ -75,6 +77,7 @@ class Importer: self.settings.setdefault("minPrint", 30) 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.do_connect(self.config) self.fdb.db.rollback() @@ -392,8 +395,9 @@ class Importer: self.hand=hand try: - handsId = fpdb_parse_logic.mainParser(self.settings, self.fdb - , self.siteIds[site], category, hand, self.config) + handsId = fpdb_parse_logic.mainParser( self.settings, self.fdb + , self.siteIds[site], category, hand + , self.config, self.database ) self.fdb.db.commit() stored += 1 diff --git a/pyfpdb/fpdb_parse_logic.py b/pyfpdb/fpdb_parse_logic.py index eff8179f..bb361f63 100644 --- a/pyfpdb/fpdb_parse_logic.py +++ b/pyfpdb/fpdb_parse_logic.py @@ -21,10 +21,13 @@ import fpdb_simple import Database #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'] - #This is redundant - hopefully fdb will be a Database object in an interation soon - db = Database.Database(config, 'fpdb', '') + if db == None: + #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]) base = "hold" if category == "holdem" or category == "omahahi" or category == "omahahilo" else "stud"