No longer mess with sys.argv (messing with system variables is a bad thing, right), use argv to determine pathname of executeable as sys.path[0] is just the first component of the path. also all database errors except MySQL reporting "Access Denied" should now crash FPDB, so someone can fill those into Exceptions, and into the fpdb_db and the fpdb files.
Process: get crash info, add exception info to Exceptions.py, catch generic database exception in fpdb_db.py (around the connect line), throw correct Fpdb exception, then catch it in fpdb.py and do the appropriate thing on the GUI end.
This commit is contained in:
+18
-18
@@ -5,17 +5,17 @@
|
||||
Main for FreePokerTools HUD.
|
||||
"""
|
||||
# Copyright 2008, 2009, Ray E. Barker
|
||||
#
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
@@ -33,7 +33,7 @@ import os
|
||||
import Options
|
||||
import traceback
|
||||
|
||||
(options, sys.argv) = Options.fpdb_options()
|
||||
(options, argv) = Options.fpdb_options()
|
||||
|
||||
if not options.errorsToConsole:
|
||||
print "Note: error output is being diverted to fpdb-error-log.txt and HUD-error.txt. Any major error will be reported there _only_."
|
||||
@@ -101,20 +101,20 @@ class HUD_main(object):
|
||||
|
||||
def create_HUD(self, new_hand_id, table, table_name, max, poker_game, type, stat_dict, cards):
|
||||
"""type is "ring" or "tour" used to set hud_params"""
|
||||
|
||||
|
||||
def idle_func():
|
||||
|
||||
|
||||
gtk.gdk.threads_enter()
|
||||
try: # TODO: seriously need to decrease the scope of this block.. what are we expecting to error?
|
||||
# TODO: The purpose of this try/finally block is to make darn sure that threads_leave()
|
||||
# TODO: gets called. If there is an exception and threads_leave() doesn't get called we
|
||||
# TODO: gets called. If there is an exception and threads_leave() doesn't get called we
|
||||
# TODO: lock up. REB
|
||||
table.gdkhandle = gtk.gdk.window_foreign_new(table.number)
|
||||
newlabel = gtk.Label("%s - %s" % (table.site, table_name))
|
||||
self.vb.add(newlabel)
|
||||
newlabel.show()
|
||||
self.main_window.resize_children()
|
||||
|
||||
|
||||
self.hud_dict[table_name].tablehudlabel = newlabel
|
||||
self.hud_dict[table_name].create(new_hand_id, self.config, stat_dict, cards)
|
||||
for m in self.hud_dict[table_name].aux_windows:
|
||||
@@ -151,23 +151,23 @@ class HUD_main(object):
|
||||
|
||||
[aw.update_data(new_hand_id, self.db_connection) for aw in self.hud_dict[table_name].aux_windows]
|
||||
gobject.idle_add(idle_func)
|
||||
|
||||
|
||||
def update_HUD(self, new_hand_id, table_name, config):
|
||||
"""Update a HUD gui from inside the non-gui read_stdin thread."""
|
||||
# This is written so that only 1 thread can touch the gui--mainly
|
||||
# for compatibility with Windows. This method dispatches the
|
||||
# for compatibility with Windows. This method dispatches the
|
||||
# function idle_func() to be run by the gui thread, at its leisure.
|
||||
def idle_func():
|
||||
gtk.gdk.threads_enter()
|
||||
# try:
|
||||
# try:
|
||||
self.hud_dict[table_name].update(new_hand_id, config)
|
||||
[aw.update_gui(new_hand_id) for aw in self.hud_dict[table_name].aux_windows]
|
||||
# finally:
|
||||
gtk.gdk.threads_leave()
|
||||
return False
|
||||
|
||||
|
||||
gobject.idle_add(idle_func)
|
||||
|
||||
|
||||
def read_stdin(self): # This is the thread function
|
||||
"""Do all the non-gui heavy lifting for the HUD program."""
|
||||
|
||||
@@ -176,7 +176,7 @@ class HUD_main(object):
|
||||
# need their own access to the database, but should open their own
|
||||
# if it is required.
|
||||
self.db_connection = Database.Database(self.config)
|
||||
|
||||
|
||||
# get hero's screen names and player ids
|
||||
self.hero, self.hero_ids = {}, {}
|
||||
for site in self.config.get_supported_sites():
|
||||
@@ -185,7 +185,7 @@ class HUD_main(object):
|
||||
site_id = result[0][0]
|
||||
self.hero[site_id] = self.config.supported_sites[site].screen_name
|
||||
self.hero_ids[site_id] = self.db_connection.get_player_id(self.config, site, self.hero[site_id])
|
||||
|
||||
|
||||
while 1: # wait for a new hand number on stdin
|
||||
new_hand_id = sys.stdin.readline()
|
||||
new_hand_id = string.rstrip(new_hand_id)
|
||||
@@ -199,7 +199,7 @@ class HUD_main(object):
|
||||
(table_name, max, poker_game, type, site_id, site_name, tour_number, tab_number) = \
|
||||
self.db_connection.get_table_info(new_hand_id)
|
||||
except Exception, err:
|
||||
print "db error: skipping %s" % new_hand_id
|
||||
print "db error: skipping %s" % new_hand_id
|
||||
sys.stderr.write("Database error: could not find hand %s.\n" % new_hand_id)
|
||||
continue
|
||||
|
||||
@@ -210,7 +210,7 @@ class HUD_main(object):
|
||||
|
||||
# Update an existing HUD
|
||||
if temp_key in self.hud_dict:
|
||||
# get stats using hud's specific params and get cards
|
||||
# get stats using hud's specific params and get cards
|
||||
self.db_connection.init_hud_stat_vars( self.hud_dict[temp_key].hud_params['hud_days']
|
||||
, self.hud_dict[temp_key].hud_params['h_hud_days'])
|
||||
stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_dict[temp_key].hud_params, self.hero_ids[site_id])
|
||||
@@ -222,7 +222,7 @@ class HUD_main(object):
|
||||
self.hud_dict[temp_key].cards = cards
|
||||
[aw.update_data(new_hand_id, self.db_connection) for aw in self.hud_dict[temp_key].aux_windows]
|
||||
self.update_HUD(new_hand_id, temp_key, self.config)
|
||||
|
||||
|
||||
# Or create a new HUD
|
||||
else:
|
||||
# get stats using default params--also get cards
|
||||
|
||||
Reference in New Issue
Block a user