From e7d43ceacad9397184d724eea2571e2af37e77dd Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Fri, 4 Sep 2009 14:14:38 -0500 Subject: [PATCH 01/13] fix taskbar listing of fpdb hud --- pyfpdb/Hud.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index eac1acf4..3082e489 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -109,6 +109,7 @@ class Hud: win = gtk.Window() win.set_gravity(gtk.gdk.GRAVITY_STATIC) win.set_title("%s FPDBHUD" % (self.table.name)) + win.set_skip_taskbar_hint(True) win.set_decorated(False) win.set_opacity(self.colors["hudopacity"]) @@ -364,17 +365,7 @@ class Hud: if not self.table.gdkhandle: self.table.gdkhandle = gtk.gdk.window_foreign_new(int(self.table.number)) # gtk handle to poker window -# window.window.reparent(self.table.gdkhandle, 0, 0) -# window.map() -# window.window.set_transient_for(self.table.gdkhandle) -# if os.name == "nt": -# print "window.window.handle=",window.window.handle -# oldparent = win32gui.SetParent(window.window.handle, self.table.number) -# print "oldparent=",oldparent -# win32gui.SendMessage(self.table.number, 0x0127) # WM_CHANGEUISTATE -# win32gui.SendMessage(self.table.number, 0x0128) # WM_UPDATEUISTATE -# window.present() - + window.window.set_transient_for(self.table.gdkhandle) class Stat_Window: @@ -496,7 +487,7 @@ class Stat_Window: self.window.move(self.x, self.y) - self.window.realize() # window must be realized before it has a gdkwindow so we can attach it to the table window.. + self.window.realize() # window must be realized before it has a gdkwindow so we can attach it to the table window.. self.topify_window(self.window) self.window.hide() @@ -640,7 +631,7 @@ if __name__== "__main__": c = Configuration.Config() #tables = Tables.discover(c) - t = Tables.discover_table_by_name(c, "Motorway") + t = Tables.discover_table_by_name(c, "Corona") if t is None: print "Table not found." db = Database.Database(c, 'fpdb', 'holdem') From e681fe4958b314cea01e5e6e0eda4987100a518c Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Sun, 6 Sep 2009 23:07:40 -0500 Subject: [PATCH 02/13] little cleanup --- pyfpdb/Hud.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 3082e489..43b8731b 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -336,7 +336,8 @@ class Hud: for s in self.stat_dict: statd = self.stat_dict[s] try: - self.stat_windows[self.stat_dict[s]['seat']].player_id = self.stat_dict[s]['player_id'] + self.stat_windows[statd['seat']].player_id = statd['player_id'] + #self.stat_windows[self.stat_dict[s]['seat']].player_id = self.stat_dict[s]['player_id'] except: # omg, we have more seats than stat windows .. damn poker sites with incorrect max seating info .. let's force 10 here self.max = 10 self.create(hand, config, self.stat_dict, self.cards) From 28450b1b8a2625bc2fa195176c58acbc62dec5a2 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Wed, 9 Sep 2009 05:01:03 -0500 Subject: [PATCH 03/13] remove tons of useless comments from fpdb.py - documentation should say something that isn't blazingly obvious by looking at the code --- pyfpdb/fpdb.py | 50 ++------------------------------------------------ 1 file changed, 2 insertions(+), 48 deletions(-) diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index c4752f16..2b805da8 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -83,23 +83,18 @@ VERSION = "0.11" class fpdb: def tab_clicked(self, widget, tab_name): """called when a tab button is clicked to activate that tab""" - #print "start of tab_clicked" self.display_tab(tab_name) - #end def tab_clicked def add_and_display_tab(self, new_tab, new_tab_name): """just calls the component methods""" self.add_tab(new_tab, new_tab_name) self.display_tab(new_tab_name) - #end def add_and_display_tab def add_tab(self, new_tab, new_tab_name): """adds a tab, namely creates the button and displays it and appends all the relevant arrays""" - #print "start of add_tab" for i in self.tab_names: #todo: check this is valid - if i==new_tab_name: - return # we depend on this to not create duplicate tabs, there's no reason to raise an error here? -# raise FpdbError("duplicate tab_name not permitted") + if i == new_tab_name: + return # if tab already exists, just go to it self.tabs.append(new_tab) self.tab_names.append(new_tab_name) @@ -109,11 +104,9 @@ class fpdb: self.tab_box.add(new_tab_sel_button) new_tab_sel_button.show() self.tab_buttons.append(new_tab_sel_button) - #end def add_tab def display_tab(self, new_tab_name): """displays the indicated tab""" - #print "start of display_tab, len(self.tab_names):",len(self.tab_names) tab_no = -1 for i, name in enumerate(self.tab_names): if name == new_tab_name: @@ -124,42 +117,33 @@ class fpdb: raise FpdbError("invalid tab_no") else: self.main_vbox.remove(self.current_tab) - #self.current_tab.destroy() self.current_tab=self.tabs[tab_no] self.main_vbox.add(self.current_tab) self.tab_buttons[tab_no].set_active(True) self.current_tab.show() - #end def display_tab def delete_event(self, widget, event, data=None): return False - #end def delete_event def destroy(self, widget, data=None): self.quit(widget) - #end def destroy def dia_about(self, widget, data=None): print "todo: implement dia_about", print " version = %s, requires database version %s" % (VERSION, "118") - #end def dia_about def dia_create_del_database(self, widget, data=None): print "todo: implement dia_create_del_database" self.obtain_global_lock() self.release_global_lock() - #end def dia_create_del_database def dia_create_del_user(self, widget, data=None): print "todo: implement dia_create_del_user" self.obtain_global_lock() self.release_global_lock() - #end def dia_create_del_user def dia_database_stats(self, widget, data=None): print "todo: implement dia_database_stats" - #string=fpdb_db.getDbStats(db, cursor) - #end def dia_database_stats def dia_database_sessions(self, widget, data=None): new_sessions_thread=GuiSessionViewer.GuiSessionViewer(self.config, self.sql) @@ -171,19 +155,16 @@ class fpdb: print "todo: implement dia_delete_db_parts" self.obtain_global_lock() self.release_global_lock() - #end def dia_delete_db_parts def dia_edit_profile(self, widget=None, data=None, create_default=False, path=None): print "todo: implement dia_edit_profile" self.obtain_global_lock() self.release_global_lock() - #end def dia_edit_profile def dia_export_db(self, widget, data=None): print "todo: implement dia_export_db" self.obtain_global_lock() self.release_global_lock() - #end def dia_export_db def dia_get_db_root_credentials(self): """obtains db root credentials from user""" @@ -203,17 +184,14 @@ class fpdb: # response=dialog.run() # dialog.destroy() # return (user, pw, response) - #end def dia_get_db_root_credentials def dia_import_db(self, widget, data=None): print "todo: implement dia_import_db" self.obtain_global_lock() self.release_global_lock() - #end def dia_import_db def dia_licensing(self, widget, data=None): print "todo: implement dia_licensing" - #end def dia_licensing def dia_load_profile(self, widget, data=None): """Dialogue to select a file to load a profile from""" @@ -237,7 +215,6 @@ class fpdb: #except: # pass self.release_global_lock() - #end def dia_load_profile def dia_recreate_tables(self, widget, data=None): """Dialogue that asks user to confirm that he wants to delete and recreate the tables""" @@ -267,7 +244,6 @@ class fpdb: print 'User cancelled recreating tables' #if not lock_released: self.release_global_lock() - #end def dia_recreate_tables def dia_recreate_hudcache(self, widget, data=None): if self.obtain_global_lock(): @@ -283,16 +259,13 @@ class fpdb: print 'User cancelled rebuilding hud cache' self.release_global_lock() - def dia_regression_test(self, widget, data=None): print "todo: implement dia_regression_test" self.obtain_global_lock() self.release_global_lock() - #end def dia_regression_test def dia_save_profile(self, widget, data=None): print "todo: implement dia_save_profile" - #end def dia_save_profile def diaSetupWizard(self, path): print "todo: implement setup wizard" @@ -313,7 +286,6 @@ class fpdb: response = diaSetupWizard.run() sys.exit(1) - #end def diaSetupWizard def get_menu(self, window): """returns the menu for this program""" @@ -402,7 +374,6 @@ class fpdb: menubar = uimanager.get_widget('/MenuBar') window.add_accel_group(accel_group) return menubar - #end def get_menu def load_profile(self): """Loads profile from the provided path name.""" @@ -453,11 +424,9 @@ class fpdb: # Database connected to successfully, load queries to pass on to other classes self.db.connection.rollback() - #end def load_profile def not_implemented(self, widget, data=None): print "todo: called unimplemented menu entry (users: pls ignore this)"#remove this once more entries are implemented - #end def not_implemented def obtain_global_lock(self): ret = self.lock.acquire(False) # will return false if lock is already held @@ -469,23 +438,18 @@ class fpdb: # need to release it later: # self.lock.release() - #end def obtain_global_lock - def quit(self, widget, data=None): print "Quitting normally" #check if current settings differ from profile, if so offer to save or abort self.db.disconnect() gtk.main_quit() - #end def quit_cliecked def release_global_lock(self): self.lock.release() print "Global lock released.\n" - #end def release_global_lock def tab_abbreviations(self, widget, data=None): print "todo: implement tab_abbreviations" - #end def tab_abbreviations def tab_auto_import(self, widget, data=None): """opens the auto import tab""" @@ -493,7 +457,6 @@ class fpdb: self.threads.append(new_aimp_thread) aimp_tab=new_aimp_thread.get_vbox() self.add_and_display_tab(aimp_tab, "Auto Import") - #end def tab_auto_import def tab_bulk_import(self, widget, data=None): """opens a tab for bulk importing""" @@ -502,7 +465,6 @@ class fpdb: self.threads.append(new_import_thread) bulk_tab=new_import_thread.get_vbox() self.add_and_display_tab(bulk_tab, "Bulk Import") - #end def tab_bulk_import def tab_player_stats(self, widget, data=None): new_ps_thread=GuiPlayerStats.GuiPlayerStats(self.config, self.sql, self.window) @@ -518,31 +480,25 @@ class fpdb: def tab_main_help(self, widget, data=None): """Displays a tab with the main fpdb help screen""" - #print "start of tab_main_help" mh_tab=gtk.Label("""Welcome to Fpdb! For documentation please visit our website at http://fpdb.sourceforge.net/ or check the docs directory in the fpdb folder. Please note that default.conf is no longer needed nor used, all configuration now happens in HUD_config.xml This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt") self.add_and_display_tab(mh_tab, "Help") - #end def tab_main_help def tab_table_viewer(self, widget, data=None): """opens a table viewer tab""" - #print "start of tab_table_viewer" new_tv_thread = GuiTableViewer.GuiTableViewer(self.db, self.settings, self.config) self.threads.append(new_tv_thread) tv_tab=new_tv_thread.get_vbox() self.add_and_display_tab(tv_tab, "Table Viewer") - #end def tab_table_viewer def tabGraphViewer(self, widget, data=None): """opens a graph viewer tab""" - #print "start of tabGraphViewer" new_gv_thread = GuiGraphViewer.GuiGraphViewer(self.sql, self.config) self.threads.append(new_gv_thread) gv_tab=new_gv_thread.get_vbox() self.add_and_display_tab(gv_tab, "Graphs") - #end def tabGraphViewer def __init__(self): self.threads = [] @@ -587,12 +543,10 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt") self.window.show() self.load_profile() sys.stderr.write("fpdb starting ...") - #end def __init__ def main(self): gtk.main() return 0 - #end def main if __name__ == "__main__": me = fpdb() From 6238e2f896a321454efa3a495a79256b479c46b4 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Wed, 9 Sep 2009 17:41:32 -0500 Subject: [PATCH 04/13] spacing --- pyfpdb/fpdb.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 2b805da8..eaf38627 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -99,7 +99,7 @@ class fpdb: self.tabs.append(new_tab) self.tab_names.append(new_tab_name) - new_tab_sel_button=gtk.ToggleButton(new_tab_name) + new_tab_sel_button = gtk.ToggleButton(new_tab_name) new_tab_sel_button.connect("clicked", self.tab_clicked, new_tab_name) self.tab_box.add(new_tab_sel_button) new_tab_sel_button.show() @@ -146,7 +146,7 @@ class fpdb: print "todo: implement dia_database_stats" def dia_database_sessions(self, widget, data=None): - new_sessions_thread=GuiSessionViewer.GuiSessionViewer(self.config, self.sql) + new_sessions_thread = GuiSessionViewer.GuiSessionViewer(self.config, self.sql) self.threads.append(new_sessions_thread) sessions_tab=new_sessions_thread.get_vbox() self.add_and_display_tab(sessions_tab, "Sessions") @@ -453,7 +453,7 @@ class fpdb: def tab_auto_import(self, widget, data=None): """opens the auto import tab""" - new_aimp_thread=GuiAutoImport.GuiAutoImport(self.settings, self.config, self.sql) + new_aimp_thread = GuiAutoImport.GuiAutoImport(self.settings, self.config, self.sql) self.threads.append(new_aimp_thread) aimp_tab=new_aimp_thread.get_vbox() self.add_and_display_tab(aimp_tab, "Auto Import") @@ -467,7 +467,7 @@ class fpdb: self.add_and_display_tab(bulk_tab, "Bulk Import") def tab_player_stats(self, widget, data=None): - new_ps_thread=GuiPlayerStats.GuiPlayerStats(self.config, self.sql, self.window) + new_ps_thread = GuiPlayerStats.GuiPlayerStats(self.config, self.sql, self.window) self.threads.append(new_ps_thread) ps_tab=new_ps_thread.get_vbox() self.add_and_display_tab(ps_tab, "Player Stats") @@ -490,14 +490,14 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt") """opens a table viewer tab""" new_tv_thread = GuiTableViewer.GuiTableViewer(self.db, self.settings, self.config) self.threads.append(new_tv_thread) - tv_tab=new_tv_thread.get_vbox() + tv_tab = new_tv_thread.get_vbox() self.add_and_display_tab(tv_tab, "Table Viewer") def tabGraphViewer(self, widget, data=None): """opens a graph viewer tab""" new_gv_thread = GuiGraphViewer.GuiGraphViewer(self.sql, self.config) self.threads.append(new_gv_thread) - gv_tab=new_gv_thread.get_vbox() + gv_tab = new_gv_thread.get_vbox() self.add_and_display_tab(gv_tab, "Graphs") def __init__(self): From 2397a59483c9b1de4882b4d7de91bce5a3ac985e Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Wed, 9 Sep 2009 18:20:50 -0500 Subject: [PATCH 05/13] add warning_box func to fpdb, add validate_config func, checks existence of hhArchiveBase, pops up warnings if not present hhc traps errors creating folders, need to learn how to make it fail properly afterwards. --- pyfpdb/HandHistoryConverter.py | 14 +++++++++++--- pyfpdb/fpdb.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 4bae9ed8..47a68deb 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -82,13 +82,21 @@ follow : whether to tail -f the input""" # TODO: out_path should be sanity checked. out_dir = os.path.dirname(self.out_path) if not os.path.isdir(out_dir) and out_dir != '': - log.info("Creating directory '%s'" % out_dir) - os.makedirs(out_dir) + try: + os.makedirs(out_dir) + except: # we get a WindowsError here in Windows.. pretty sure something else for Linux :D + log.error("Unable to create output directory %s for HHC!" % out_dir) + print "*** ERROR: UNABLE TO CREATE OUTPUT DIRECTORY", out_dir + # TODO: pop up a box to allow person to choose output directory? + # TODO: shouldn't that be done when we startup, actually? + else: + log.info("Created directory '%s'" % out_dir) try: self.out_fh = codecs.open(self.out_path, 'w', 'cp1252') - log.debug("out_path %s opened as %s" % (self.out_path, self.out_fh)) except: log.error("out_path %s couldn't be opened" % (self.out_path)) + else: + log.debug("out_path %s opened as %s" % (self.out_path, self.out_fh)) self.follow = follow self.compiledPlayers = set() diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index eaf38627..0bdad88c 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -424,6 +424,8 @@ class fpdb: # Database connected to successfully, load queries to pass on to other classes self.db.connection.rollback() + + self.validate_config() def not_implemented(self, widget, data=None): print "todo: called unimplemented menu entry (users: pls ignore this)"#remove this once more entries are implemented @@ -543,6 +545,36 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt") self.window.show() self.load_profile() sys.stderr.write("fpdb starting ...") + + def warning_box(self, str, diatitle="FPDB WARNING"): + diaWarning = gtk.Dialog(title=diatitle, parent=None, flags=0, buttons=(gtk.STOCK_OK,gtk.RESPONSE_OK)) + + label = gtk.Label(str) + diaWarning.vbox.add(label) + label.show() + + response = diaWarning.run() + diaWarning.destroy() + return response + + def validate_config(self): + hhbase = self.config.get_import_parameters().get("hhArchiveBase") + hhbase = os.path.expanduser(hhbase) + #hhdir = os.path.join(hhbase,site) + hhdir = hhbase + if not os.path.isdir(hhdir): + diapath = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Setup hh dir") + diastring = "WARNING: Unable to find output hh directory %s. Press YES to create this directory, or NO to select a new one." % hhdir + diapath.format_secondary_text(diastring) + response = diapath.run() + diapath.destroy() + if response == gtk.RESPONSE_YES: + try: + os.makedirs(hhdir) + except: + self.warning_box("WARNING: Unable to create hand output directory. Importing is not likely to work until this is fixed.") + elif response == gtk.RESPONSE_NO: + self.warning_box("UNIMPLEMENTED: selection of HH directory not yet implemented, please edit your HUD_config.xml file and set hhArchiveBase to a valid directory") def main(self): gtk.main() From 2bf3aaa1bc7360b8de097aa84e596e1e7b260c66 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Wed, 9 Sep 2009 18:36:55 -0500 Subject: [PATCH 06/13] most of the unimplemented stuff goes to warning_box() instead of to log/stdout. Implemented About (via warning_box, w/e) --- pyfpdb/fpdb.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 0bdad88c..81cc0bdc 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -129,21 +129,20 @@ class fpdb: self.quit(widget) def dia_about(self, widget, data=None): - print "todo: implement dia_about", - print " version = %s, requires database version %s" % (VERSION, "118") + self.warning_box("About FPDB:\n\nFPDB was originally created by a guy named Steffen, sometime in 2008, \nand is mostly worked on these days by people named Eratosthenes, s0rrow, _mt, EricBlade, sqlcoder, and other strange people.\n\n", "ABOUT FPDB") def dia_create_del_database(self, widget, data=None): - print "todo: implement dia_create_del_database" + self.warning_box("Unimplemented: Create/Delete Database") self.obtain_global_lock() self.release_global_lock() def dia_create_del_user(self, widget, data=None): - print "todo: implement dia_create_del_user" + self.warning_box("Unimplemented: Create/Delete user") self.obtain_global_lock() self.release_global_lock() def dia_database_stats(self, widget, data=None): - print "todo: implement dia_database_stats" + self.warning_box("Unimplemented: Database Stats") def dia_database_sessions(self, widget, data=None): new_sessions_thread = GuiSessionViewer.GuiSessionViewer(self.config, self.sql) @@ -152,23 +151,23 @@ class fpdb: self.add_and_display_tab(sessions_tab, "Sessions") def dia_delete_db_parts(self, widget, data=None): - print "todo: implement dia_delete_db_parts" + self.warning_box("Unimplemented: Delete Database Parts") self.obtain_global_lock() self.release_global_lock() def dia_edit_profile(self, widget=None, data=None, create_default=False, path=None): - print "todo: implement dia_edit_profile" + self.warning_box("Unimplemented: Edit Profile") self.obtain_global_lock() self.release_global_lock() def dia_export_db(self, widget, data=None): - print "todo: implement dia_export_db" + self.warning_box("Unimplemented: Export Database") self.obtain_global_lock() self.release_global_lock() def dia_get_db_root_credentials(self): """obtains db root credentials from user""" - print "todo: implement dia_get_db_root_credentials" + self.warning_box("Unimplemented: Get Root Database Credentials") # user, pw=None, None # # dialog=gtk.Dialog(title="DB Credentials needed", parent=None, flags=0, @@ -186,12 +185,12 @@ class fpdb: # return (user, pw, response) def dia_import_db(self, widget, data=None): - print "todo: implement dia_import_db" + self.warning_box("Unimplemented: Import Database") self.obtain_global_lock() self.release_global_lock() def dia_licensing(self, widget, data=None): - print "todo: implement dia_licensing" + self.warning_box("Unimplemented: Licensing") def dia_load_profile(self, widget, data=None): """Dialogue to select a file to load a profile from""" @@ -260,16 +259,14 @@ class fpdb: self.release_global_lock() def dia_regression_test(self, widget, data=None): - print "todo: implement dia_regression_test" + self.warning_box("Unimplemented: Regression Test") self.obtain_global_lock() self.release_global_lock() def dia_save_profile(self, widget, data=None): - print "todo: implement dia_save_profile" - + self.warning_box("Unimplemented: Save Profile (try saving a HUD layout, that should do it)") + def diaSetupWizard(self, path): - print "todo: implement setup wizard" - print "setup wizard not implemented - please create the default configuration file:", path diaSetupWizard = gtk.Dialog(title="Fatal Error - Config File Missing", parent=None, flags=0, buttons=(gtk.STOCK_QUIT,gtk.RESPONSE_OK)) label = gtk.Label("Please copy the config file from the docs folder to:") @@ -428,7 +425,7 @@ class fpdb: self.validate_config() def not_implemented(self, widget, data=None): - print "todo: called unimplemented menu entry (users: pls ignore this)"#remove this once more entries are implemented + self.warning_box("Unimplemented menu entry") def obtain_global_lock(self): ret = self.lock.acquire(False) # will return false if lock is already held @@ -564,7 +561,7 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt") hhdir = hhbase if not os.path.isdir(hhdir): diapath = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Setup hh dir") - diastring = "WARNING: Unable to find output hh directory %s. Press YES to create this directory, or NO to select a new one." % hhdir + diastring = "WARNING: Unable to find output hh directory %s\n\n Press YES to create this directory, or NO to select a new one." % hhdir diapath.format_secondary_text(diastring) response = diapath.run() diapath.destroy() From ae04f5562a8feb475a95e19783a980009bb49f78 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Wed, 9 Sep 2009 20:21:27 -0500 Subject: [PATCH 07/13] Configuration::Import keeps track of it's node, added function to Configuration::Config to set the Import's hhArchiveBase --- pyfpdb/Configuration.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 5430fd02..e6361fb0 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -266,6 +266,7 @@ class Popup: class Import: def __init__(self, node): + self.node = node self.interval = node.getAttribute("interval") self.callFpdbHud = node.getAttribute("callFpdbHud") self.hhArchiveBase = node.getAttribute("hhArchiveBase") @@ -401,7 +402,9 @@ class Config: db_pass = df_parms['db-password']) self.save(file=os.path.join(self.default_config_path, "HUD_config.xml")) - + def set_hhArchiveBase(self, path): + self.imp.node.setAttribute("hhArchiveBase", path) + def find_config(self): """Looks in cwd and in self.default_config_path for a config file.""" if os.path.exists('HUD_config.xml'): # there is a HUD_config in the cwd From 345e328795f9971f148f4598aea68bc0fd2d7b82 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Wed, 9 Sep 2009 20:26:44 -0500 Subject: [PATCH 08/13] Add Set HH Archive Directory option to Import menu on main, call it if user selects "no" on "create hh directory" prompt --- pyfpdb/fpdb.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 81cc0bdc..ee3ac441 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -297,6 +297,7 @@ class fpdb: + @@ -339,6 +340,7 @@ class fpdb: ('EditProf', None, '_Edit Profile (todo)', 'E', 'Edit your profile', self.dia_edit_profile), ('SaveProf', None, '_Save Profile (todo)', 'S', 'Save your profile', self.dia_save_profile), ('import', None, '_Import'), + ('sethharchive', None, '_Set HandHistory Archive Directory', None, 'Set HandHistory Archive Directory', self.select_hhArchiveBase), ('bulkimp', None, '_Bulk Import', 'B', 'Bulk Import', self.tab_bulk_import), ('autorate', None, 'Auto _Rating (todo)', 'R', 'Auto Rating (todo)', self.not_implemented), ('viewers', None, '_Viewers'), @@ -553,7 +555,7 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt") response = diaWarning.run() diaWarning.destroy() return response - + def validate_config(self): hhbase = self.config.get_import_parameters().get("hhArchiveBase") hhbase = os.path.expanduser(hhbase) @@ -571,8 +573,18 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt") except: self.warning_box("WARNING: Unable to create hand output directory. Importing is not likely to work until this is fixed.") elif response == gtk.RESPONSE_NO: - self.warning_box("UNIMPLEMENTED: selection of HH directory not yet implemented, please edit your HUD_config.xml file and set hhArchiveBase to a valid directory") - + self.select_hhArchiveBase() + + def select_hhArchiveBase(self, widget=None): + fc = gtk.FileChooserDialog(title="Select HH Output Directory", parent=None, action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, buttons=(gtk.STOCK_OPEN,gtk.RESPONSE_OK), backend=None) + fc.run() + # TODO: We need to put in a Cancel button, and handle if the user presses that or the "Close" box without selecting anything as a cancel, and return to the prior setting + #self.warning_box("You selected %s" % fc.get_filename()) + self.config.set_hhArchiveBase(fc.get_filename()) + self.config.save() + self.load_profile() # we can't do this at the end of this func because load_profile calls this func + fc.destroy() # TODO: loop this to make sure we get valid data back from it, because the open directory thing in GTK lets you select files and not select things and other stupid bullshit + def main(self): gtk.main() return 0 From 705210a96d04b8ca1b858abad1cfebfc31df73ce Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Wed, 9 Sep 2009 20:57:16 -0500 Subject: [PATCH 09/13] use the "proper" gtk.AboutDialog() for About ... meh --- pyfpdb/fpdb.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index ee3ac441..099c5cb8 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -129,7 +129,18 @@ class fpdb: self.quit(widget) def dia_about(self, widget, data=None): - self.warning_box("About FPDB:\n\nFPDB was originally created by a guy named Steffen, sometime in 2008, \nand is mostly worked on these days by people named Eratosthenes, s0rrow, _mt, EricBlade, sqlcoder, and other strange people.\n\n", "ABOUT FPDB") + #self.warning_box("About FPDB:\n\nFPDB was originally created by a guy named Steffen, sometime in 2008, \nand is mostly worked on these days by people named Eratosthenes, s0rrow, _mt, EricBlade, sqlcoder, and other strange people.\n\n", "ABOUT FPDB") + dia = gtk.AboutDialog() + dia.set_name("FPDB") + dia.set_version(VERSION) + dia.set_copyright("2008-2009, Steffen, Eratosthenes, s0rrow, EricBlade, _mt, and others") + dia.set_comments("GTK AboutDialog comments here") + dia.set_license("GPL v3") + dia.set_website("http://fpdb.sourceforge.net/") + dia.set_authors("Steffen, Eratosthenes, s0rrow, EricBlade, _mt, and others") + dia.set_program_name("FPDB") + dia.run() + dia.destroy() def dia_create_del_database(self, widget, data=None): self.warning_box("Unimplemented: Create/Delete Database") From 993199c0106ce796ed2827f4c5b640f264a9e7bd Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Wed, 9 Sep 2009 21:04:38 -0500 Subject: [PATCH 10/13] add sqlcoder to about --- pyfpdb/fpdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 099c5cb8..fd2feca2 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -133,7 +133,7 @@ class fpdb: dia = gtk.AboutDialog() dia.set_name("FPDB") dia.set_version(VERSION) - dia.set_copyright("2008-2009, Steffen, Eratosthenes, s0rrow, EricBlade, _mt, and others") + dia.set_copyright("2008-2009, Steffen, Eratosthenes, s0rrow, EricBlade, _mt, sqlcoder, and others") dia.set_comments("GTK AboutDialog comments here") dia.set_license("GPL v3") dia.set_website("http://fpdb.sourceforge.net/") From 1f9dd8f8e94bc571c9298247c5775d016ca8b4e3 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Wed, 9 Sep 2009 22:10:55 -0500 Subject: [PATCH 11/13] HHC/fpdb_import: throw in some calls to gtk.main_iteration(False) GuiBulkImport: replace "Importing" label with actual progressbar (does not use percentages, simply an activity bar) --- pyfpdb/GuiBulkImport.py | 39 +++++++++++++++++++++++++++------- pyfpdb/HandHistoryConverter.py | 6 ++++++ pyfpdb/fpdb_import.py | 8 ++++++- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/pyfpdb/GuiBulkImport.py b/pyfpdb/GuiBulkImport.py index ab36aa15..c4f3105f 100755 --- a/pyfpdb/GuiBulkImport.py +++ b/pyfpdb/GuiBulkImport.py @@ -27,11 +27,13 @@ import traceback import pygtk pygtk.require('2.0') import gtk +import gobject # fpdb/FreePokerTools modules import fpdb_simple import fpdb_import import Configuration +import Exceptions class GuiBulkImport(): @@ -53,12 +55,22 @@ class GuiBulkImport(): else: self.importer.RunImportThreaded() + def dopulse(self): + self.progressbar.pulse() + return True + def load_clicked(self, widget, data=None): # Does the lock acquisition need to be more sophisticated for multiple dirs? # (see comment above about what to do if pipe already open) if self.settings['global_lock'].acquire(False): # returns false immediately if lock not acquired try: print "\nGlobal lock taken ..." + self.progressbar.set_text("Importing...") + self.progressbar.pulse() + while gtk.events_pending(): # see http://faq.pygtk.org/index.py?req=index for more hints (3.7) + gtk.main_iteration(False) + self.timer = gobject.timeout_add(100, self.dopulse) + # get the dir to import from the chooser self.inputFile = self.chooser.get_filename() @@ -74,9 +86,7 @@ class GuiBulkImport(): cb_hmodel = self.cb_drophudcache.get_model() cb_hindex = self.cb_drophudcache.get_active() - self.lab_info.set_markup('Importing ...') # uses pango markup! - while gtk.events_pending(): # see http://faq.pygtk.org/index.py?req=index for more hints (3.7) - gtk.main_iteration(False) + #self.lab_info.set_markup('Importing ...') # uses pango markup! if cb_index: self.importer.setDropIndexes(cb_model[cb_index][0]) @@ -91,7 +101,14 @@ class GuiBulkImport(): self.importer.addBulkImportImportFileOrDir(self.inputFile, site = sitename) self.importer.setCallHud(False) starttime = time() - (stored, dups, partial, errs, ttime) = self.importer.runImport() + try: + (stored, dups, partial, errs, ttime) = self.importer.runImport() + except: + print "*** EXCEPTION DURING BULKIMPORT!!!" + raise Exceptions.FpdbError + finally: + gobject.source_remove(self.timer) + ttime = time() - starttime if ttime == 0: ttime = 1 @@ -106,7 +123,8 @@ class GuiBulkImport(): self.cb_drophudcache.set_active(0) self.lab_hdrop.set_sensitive(True) - self.lab_info.set_text("Import finished") + self.progressbar.set_text("Import Complete") + self.progressbar.set_fraction(0) except: err = traceback.extract_tb(sys.exc_info()[2])[-1] print "***Error: "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1]) @@ -251,9 +269,14 @@ class GuiBulkImport(): self.lab_spacer.show() # label - info - self.lab_info = gtk.Label() - self.table.attach(self.lab_info, 3, 5, 4, 5, xpadding = 0, ypadding = 0, yoptions=gtk.SHRINK) - self.lab_info.show() +# self.lab_info = gtk.Label() +# self.table.attach(self.lab_info, 3, 5, 4, 5, xpadding = 0, ypadding = 0, yoptions=gtk.SHRINK) +# self.lab_info.show() + self.progressbar = gtk.ProgressBar() + self.table.attach(self.progressbar, 3, 5, 4, 5, xpadding = 0, ypadding = 0, yoptions = gtk.SHRINK) + self.progressbar.set_text("Waiting...") + self.progressbar.set_fraction(0) + self.progressbar.show() # see how many hands are in the db and adjust accordingly tcursor = self.importer.database.cursor diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 47a68deb..1165dec8 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -40,6 +40,9 @@ import logging, logging.config logging.config.fileConfig(os.path.join(sys.path[0],"logging.conf")) log = logging.getLogger("parser") +import pygtk +import gtk + class HandHistoryConverter(): READ_CHUNK_SIZE = 10000 # bytes to read at a time from file in tail mode @@ -124,6 +127,9 @@ If in follow mode, wait for more data to turn up. Otherwise, finish at EOF. """ + while gtk.events_pending(): + gtk.main_iteration(False) + starttime = time.time() if not self.sanityCheck(): log.warning("Failed sanity check") diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 2c333c2f..97237456 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -30,6 +30,9 @@ import Queue from collections import deque # using Queue for now import threading +import pygtk +import gtk + # fpdb/FreePokerTools modules import fpdb_simple @@ -377,6 +380,7 @@ class Importer: # This is now an internal function that should not be called directly. def import_file_dict(self, db, file, site, filter, q=None): #print "import_file_dict" + if os.path.isdir(file): self.addToDirList[file] = [site] + [filter] return @@ -485,7 +489,9 @@ class Importer: """Import an fpdb hand history held in the list lines, could be one hand or many""" #db.lock_for_insert() # should be ok when using one thread, but doesn't help?? - + while gtk.events_pending(): + gtk.main_iteration(False) + try: # sometimes we seem to be getting an empty self.lines, in which case, we just want to return. firstline = lines[0] except: From 715b14f81a99d2abf74009b9bdcdfde8da2d6057 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Fri, 11 Sep 2009 00:12:46 -0500 Subject: [PATCH 12/13] moved timeout_add that calls do_import outside of the for loop, so it's only created once per autoimport start, not once per site. fix addImportFile to ignore files that don't exist (not sure how they'd get there, but just in case), fixed exception looking for fpdb_simple.DuplicateError to look in it's actual location at Exceptions.DuplicateError --- pyfpdb/GuiAutoImport.py | 6 +++++- pyfpdb/fpdb_import.py | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pyfpdb/GuiAutoImport.py b/pyfpdb/GuiAutoImport.py index 77e7fbdc..9e99908b 100755 --- a/pyfpdb/GuiAutoImport.py +++ b/pyfpdb/GuiAutoImport.py @@ -34,6 +34,7 @@ import string class GuiAutoImport (threading.Thread): def __init__(self, settings, config, sql): """Constructor for GuiAutoImport""" + self.importtimer = 0 self.settings=settings self.config=config self.sql = sql @@ -196,11 +197,14 @@ class GuiAutoImport (threading.Thread): self.do_import() interval = int(self.intervalEntry.get_text()) - gobject.timeout_add(interval*1000, self.do_import) + if self.importtimer != 0: + gobject.source_remove(self.importtimer) + self.importtimer = gobject.timeout_add(interval*1000, self.do_import) else: print "auto-import aborted - global lock not available" else: # toggled off + gobject.source_remove(self.importtimer) self.settings['global_lock'].release() self.doAutoImportBool = False # do_import will return this and stop the gobject callback timer print "Stopping autoimport - global lock released." diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 97237456..2e299c5f 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -40,6 +40,7 @@ import fpdb_db import Database import fpdb_parse_logic import Configuration +import Exceptions import logging, logging.config logging.config.fileConfig(os.path.join(sys.path[0],"logging.conf")) @@ -152,6 +153,8 @@ class Importer: #Add an individual file to filelist def addImportFile(self, filename, site = "default", filter = "passthrough"): #TODO: test it is a valid file -> put that in config!! + if filename in self.filelist or not os.path.exists(filename): + return self.filelist[filename] = [site] + [filter] if site not in self.siteIds: # Get id from Sites table in DB @@ -346,13 +349,14 @@ class Importer: #rulog.writelines("runUpdated ... ") for site in self.dirlist: self.addImportDirectory(self.dirlist[site][0], False, site, self.dirlist[site][1]) - + for file in self.filelist: if os.path.exists(file): stat_info = os.stat(file) #rulog.writelines("path exists ") if file in self.updatedsize: # we should be able to assume that if we're in size, we're in time as well if stat_info.st_size > self.updatedsize[file] or stat_info.st_mtime > self.updatedtime[file]: +# print "file",counter," updated", os.path.basename(file), stat_info.st_size, self.updatedsize[file], stat_info.st_mtime, self.updatedtime[file] self.import_file_dict(self.database, file, self.filelist[file][0], self.filelist[file][1], None) self.updatedsize[file] = stat_info.st_size self.updatedtime[file] = time() @@ -365,6 +369,7 @@ class Importer: self.updatedtime[file] = time() else: self.removeFromFileList[file] = True + self.addToDirList = filter(lambda x: self.addImportDirectory(x, True, self.addToDirList[x][0], self.addToDirList[x][1]), self.addToDirList) for file in self.removeFromFileList: @@ -546,7 +551,7 @@ class Importer: #pipe the Hands.id out to the HUD #print "sending hand to hud", handsId, "pipe =", self.caller.pipe_to_hud self.caller.pipe_to_hud.stdin.write("%s" % (handsId) + os.linesep) - except fpdb_simple.DuplicateError: + except Exceptions.DuplicateError: duplicates += 1 db.rollback() except (ValueError), fe: From 7283d09b4d0431e3d164b1603f75d057001cc8a0 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Fri, 11 Sep 2009 00:38:20 -0500 Subject: [PATCH 13/13] replace "trying *codepage*" message to console with an error message only if none of our specified codepages is successful --- pyfpdb/HandHistoryConverter.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 1165dec8..e40694ea 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -426,10 +426,8 @@ or None if we fail to get the info """ log.debug("Reading stdin with %s" % self.codepage) # is this necessary? or possible? or what? in_fh = codecs.getreader('cp1252')(sys.stdin) else: - success = False for kodec in self.__listof(self.codepage): - if success: break - print "trying", kodec + #print "trying", kodec try: in_fh = codecs.open(self.in_path, 'r', kodec) in_fh.seek(self.index) @@ -437,9 +435,11 @@ or None if we fail to get the info """ self.obs = in_fh.read() self.index = in_fh.tell() in_fh.close() - success = True + break except: pass + else: + print "unable to read file with any codec in list!", self.in_path elif(self.filetype == "xml"): doc = xml.dom.minidom.parse(filename) self.doc = doc