From 906c9e0bc9b99b97e443eb529bd78b1af4c79140 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Fri, 12 Feb 2010 08:18:42 +0000 Subject: [PATCH 1/2] tighten up logging in hud --- pyfpdb/Configuration.py | 2 +- pyfpdb/HUD_main.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 6c4eecd2..f7694e90 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -65,7 +65,7 @@ def get_exec_path(): def get_config(file_name, fallback = True): """Looks in cwd and in self.default_config_path for a config file.""" exec_dir = get_exec_path() - if file_name == 'logging.conf' and sys.argv[0] != 'fpdb.exe': + if file_name == 'logging.conf' and not hasattr(sys, "frozen"): config_path = os.path.join(exec_dir, 'pyfpdb', file_name) else: config_path = os.path.join(exec_dir, file_name) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 03f6c565..e26fd611 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -60,8 +60,9 @@ elif os.name == 'nt': import Hud -# logger is set up in __init__, create temp logger here -log = Configuration.get_logger("logging.conf", config = 'hud') +# get config and set up logger +c = Configuration.Config(file=options.config) +log = Configuration.get_logger("logging.conf", "hud", log_dir=c.dir_log, log_file='HUD-log.txt') class HUD_main(object): @@ -71,8 +72,7 @@ class HUD_main(object): def __init__(self, db_name = 'fpdb'): print "\nHUD_main: starting ..." self.db_name = db_name - self.config = Configuration.Config(file=options.config, dbname=db_name) - log = Configuration.get_logger("logging.conf", "hud", log_dir=self.config.dir_log, log_file='HUD-log.txt') + self.config = Configuration.Config(file=options.config, dbname = db_name) print "Logfile is " + os.path.join(self.config.dir_log, 'HUD-log.txt') log.info("HUD_main starting: using db name = %s" % (db_name)) @@ -85,6 +85,7 @@ class HUD_main(object): log.info("Any major error will be reported there _only_.") errorFile = open(fileName, 'w', 0) sys.stderr = errorFile + sys.stderr.write("HUD_main: starting ...\n") self.hud_dict = {} self.hud_params = self.config.get_hud_ui_parameters() @@ -142,7 +143,7 @@ class HUD_main(object): self.hud_dict[table_name].update(new_hand_id, self.config) self.hud_dict[table_name].reposition_windows() except: - log.error( "*** Exception in HUD_main::idle_func() *** " ) + log.error( "*** Exception in HUD_main::idle_func() *** " + str(sys.exc_info()) ) for e in traceback.format_tb(sys.exc_info()[2]): log.error(e) finally: From 65a0c367810eacd0eb01393c920766f6640160e1 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Sat, 13 Feb 2010 17:26:47 +0000 Subject: [PATCH 2/2] use original config instance, improve hero_id handling (think this fixes auto-import empty db problem?) --- pyfpdb/HUD_main.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index e26fd611..2ea223f4 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -72,7 +72,7 @@ class HUD_main(object): def __init__(self, db_name = 'fpdb'): print "\nHUD_main: starting ..." self.db_name = db_name - self.config = Configuration.Config(file=options.config, dbname = db_name) + self.config = c print "Logfile is " + os.path.join(self.config.dir_log, 'HUD-log.txt') log.info("HUD_main starting: using db name = %s" % (db_name)) @@ -207,12 +207,7 @@ class HUD_main(object): # get hero's screen names and player ids self.hero, self.hero_ids = {}, {} - for site in self.config.get_supported_sites(): - result = self.db_connection.get_site_id(site) - if result: - 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]) + found = False while 1: # wait for a new hand number on stdin new_hand_id = sys.stdin.readline() @@ -224,6 +219,18 @@ class HUD_main(object): self.destroy() break # this thread is not always killed immediately with gtk.main_quit() + if not found: + for site in self.config.get_supported_sites(): + result = self.db_connection.get_site_id(site) + if result: + 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]) + if self.hero_ids[site_id] is not None: + found = True + else: + self.hero_ids[site_id] = -1 + # get basic info about the new hand from the db # if there is a db error, complain, skip hand, and proceed log.info("HUD_main.read_stdin: hand processing starting ...")