Skip to content

Commit

Permalink
Merge branch 'master' of git://git.assembla.com/fpdb-sql.git
Browse files Browse the repository at this point in the history
  • Loading branch information
kangaderoo committed Feb 7, 2010
2 parents 2c07264 + fbeaa55 commit f117b62
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 72 deletions.
32 changes: 13 additions & 19 deletions pyfpdb/Charset.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ def to_utf8(s):
return _out
except UnicodeDecodeError:
sys.stderr.write('Could not convert: "%s"\n' % s)
return s
raise
except UnicodeEncodeError:
sys.stderr.write('Could not convert: "%s"\n' % s)
return s
except TypeError:
sys.stderr.write('Could not convert: "%s"\n' % s)
sys.stderr.write('Could not encode: "%s"\n' % s)
raise
except TypeError: # TypeError is raised when we give unicode() an already encoded string
return s

def to_db_utf8(s):
Expand All @@ -57,27 +56,22 @@ def to_db_utf8(s):
return _out
except UnicodeDecodeError:
sys.stderr.write('Could not convert: "%s"\n' % s)
return s
raise
except UnicodeEncodeError:
sys.stderr.write('Could not convert: "%s"\n' % s)
return s
except TypeError:
sys.stderr.write('Could not convert: "%s"\n' % s)
return s
sys.stderr.write('Could not encode: "%s"\n' % s)
raise

def to_gui(s):
if not_needed3: return s

try:
(_out, _len) = encoder_to_sys.encode(s)
# we usually don't want to use 'replace' but this is only for displaying
# in the gui so it doesn't matter if names are missing an accent or two
(_out, _len) = encoder_to_sys.encode(s, 'replace')
return _out
except UnicodeDecodeError:
sys.stderr.write('Could not convert: "%s"\n' % s)
return s
raise
except UnicodeEncodeError:
sys.stderr.write('Could not convert: "%s"\n' % s)
return s
except TypeError:
sys.stderr.write('Could not convert: "%s"\n' % s)
return s

sys.stderr.write('Could not encode: "%s"\n' % s)
raise
4 changes: 2 additions & 2 deletions pyfpdb/Database.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ def connect(self, backend=None, host=None, database=None,
import sqlite3
if use_pool:
sqlite3 = pool.manage(sqlite3, pool_size=1)
else:
log.warning("SQLite won't work well without 'sqlalchemy' installed.")
#else:
# log.warning("SQLite won't work well without 'sqlalchemy' installed.")

if database != ":memory:":
if not os.path.isdir(self.config.dir_database):
Expand Down
10 changes: 7 additions & 3 deletions pyfpdb/GuiAutoImport.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,11 @@ def startClicked(self, widget, data):
widget.set_label(u' _Stop Autoimport ')
if self.pipe_to_hud is None:
if os.name == 'nt':
path = sys.path[0].replace('\\','\\\\')
command = 'python "'+path+'\\HUD_main.py" ' + self.settings['cl_options']
if sys.argv[0] == 'fpdb.exe':
command = 'HUD_main.exe'
else:
path = sys.path[0].replace('\\','\\\\')
command = 'python "'+path+'\\HUD_main.py" ' + self.settings['cl_options']
bs = 0
else:
command = os.path.join(sys.path[0], 'HUD_main.py')
Expand All @@ -208,7 +211,8 @@ def startClicked(self, widget, data):
universal_newlines=True)
except:
err = traceback.extract_tb(sys.exc_info()[2])[-1]
self.addText( "\n*** GuiAutoImport Error opening pipe: " + err[2] + "(" + str(err[1]) + "): " + str(sys.exc_info()[1]))
#self.addText( "\n*** GuiAutoImport Error opening pipe: " + err[2] + "(" + str(err[1]) + "): " + str(sys.exc_info()[1]))
self.addText( "\n*** GuiAutoImport Error opening pipe: " + traceback.format_exc() )
else:
for site in self.input_settings:
self.importer.addImportDirectory(self.input_settings[site][0], True, site, self.input_settings[site][1])
Expand Down
19 changes: 9 additions & 10 deletions pyfpdb/HUD_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,15 @@ class HUD_main(object):

def __init__(self, db_name = 'fpdb'):
try:
print "HUD_main: starting ..."
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.info("HUD_main starting")
log.info("Using db name = %s" % (db_name))
log.info("HUD_main starting: using db name = %s" % (db_name))

if not options.errorsToConsole:
fileName = os.path.join(self.config.dir_log, 'HUD-errors.txt')
print "Note: error output is being diverted to\n"+fileName \
print "Note: error output is being diverted to:\n"+fileName \
+ "\nAny major error will be reported there _only_.\n"
errorFile = open(fileName, 'w', 0)
sys.stderr = errorFile
Expand Down Expand Up @@ -139,8 +138,8 @@ def idle_func():
self.hud_dict[table_name].update(new_hand_id, self.config)
self.hud_dict[table_name].reposition_windows()
except:
print "*** Exception in HUD_main::idle_func() *** "
traceback.print_stack()
log.error( "*** Exception in HUD_main::idle_func() *** " )
log.error( traceback.format_stack() )
finally:
gtk.gdk.threads_leave()
return False
Expand Down Expand Up @@ -247,8 +246,8 @@ def read_stdin(self): # This is the thread function
try:
self.hud_dict[temp_key].stat_dict = stat_dict
except KeyError: # HUD instance has been killed off, key is stale
sys.stderr.write('hud_dict[%s] was not found\n' % temp_key)
sys.stderr.write('will not send hand\n')
log.error('hud_dict[%s] was not found\n' % temp_key)
log.error('will not send hand\n')
# Unlocks table, copied from end of function
self.db_connection.connection.rollback()
return
Expand Down Expand Up @@ -282,7 +281,7 @@ def read_stdin(self): # This is the thread function
# If no client window is found on the screen, complain and continue
if type == "tour":
table_name = "%s %s" % (tour_number, tab_number)
# sys.stderr.write("HUD create: table name "+table_name+" not found, skipping.\n")
# log.error("HUD create: table name "+table_name+" not found, skipping.\n")
log.error("HUD create: table name %s not found, skipping." % table_name)
else:
tablewindow.max = max
Expand All @@ -291,7 +290,7 @@ def read_stdin(self): # This is the thread function
if hasattr(tablewindow, 'number'):
self.create_HUD(new_hand_id, tablewindow, temp_key, max, poker_game, type, stat_dict, cards)
else:
sys.stderr.write('Table "%s" no longer exists\n' % table_name)
log.error('Table "%s" no longer exists\n' % table_name)

t6 = time.time()
log.info("HUD_main.read_stdin: hand read in %4.3f seconds (%4.3f,%4.3f,%4.3f,%4.3f,%4.3f,%4.3f)"
Expand Down
20 changes: 12 additions & 8 deletions pyfpdb/Hud.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
import os
import sys

import logging
# logging has been set up in fpdb.py or HUD_main.py, use their settings:
log = logging.getLogger("hud")

# pyGTK modules
import pygtk
import gtk
Expand Down Expand Up @@ -365,7 +369,7 @@ def change_max_seats(self, widget):
self.create(*self.creation_attrs)
self.update(self.hand, self.config)
except Exception, e:
print "Exception:",str(e)
log.error("Exception:",str(e))
pass

def set_aggregation(self, widget, val):
Expand All @@ -377,7 +381,7 @@ def set_aggregation(self, widget, val):

if self.hud_params['h_agg_bb_mult'] != num \
and getattr(self, 'h_aggBBmultItem'+str(num)).get_active():
print 'set_player_aggregation', num
log.debug('set_player_aggregation', num)
self.hud_params['h_agg_bb_mult'] = num
for mult in ('1', '2', '3', '10', '10000'):
if mult != str(num):
Expand All @@ -388,7 +392,7 @@ def set_aggregation(self, widget, val):

if self.hud_params['agg_bb_mult'] != num \
and getattr(self, 'aggBBmultItem'+str(num)).get_active():
print 'set_opponent_aggregation', num
log.debug('set_opponent_aggregation', num)
self.hud_params['agg_bb_mult'] = num
for mult in ('1', '2', '3', '10', '10000'):
if mult != str(num):
Expand All @@ -415,7 +419,7 @@ def set_seats_style(self, widget, val):
self.hud_params[param] = 'E'
getattr(self, prefix+'seatsStyleOptionA').set_active(False)
getattr(self, prefix+'seatsStyleOptionC').set_active(False)
print "setting self.hud_params[%s] = %s" % (param, style)
log.debug("setting self.hud_params[%s] = %s" % (param, style))

def set_hud_style(self, widget, val):
(player_opp, style) = val
Expand All @@ -438,7 +442,7 @@ def set_hud_style(self, widget, val):
self.hud_params[param] = 'T'
getattr(self, prefix+'hudStyleOptionA').set_active(False)
getattr(self, prefix+'hudStyleOptionS').set_active(False)
print "setting self.hud_params[%s] = %s" % (param, style)
log.debug("setting self.hud_params[%s] = %s" % (param, style))

def update_table_position(self):
if os.name == 'nt':
Expand Down Expand Up @@ -515,7 +519,7 @@ def save_layout(self, *args):
# ask each aux to save its layout back to the config object
[aux.save_layout() for aux in self.aux_windows]
# save the config object back to the file
print "saving new xml file"
print "Updating config file"
self.config.save()

def adj_seats(self, hand, config):
Expand Down Expand Up @@ -611,8 +615,8 @@ def update(self, hand, config):
try:
statd = self.stat_dict[s]
except KeyError:
print "KeyError at the start of the for loop in update in hud_main. How this can possibly happen is totally beyond my comprehension. Your HUD may be about to get really weird. -Eric"
print "(btw, the key was ", s, " and statd is...", statd
log.error("KeyError at the start of the for loop in update in hud_main. How this can possibly happen is totally beyond my comprehension. Your HUD may be about to get really weird. -Eric")
log.error("(btw, the key was ", s, " and statd is...", statd)
continue
try:
self.stat_windows[statd['seat']].player_id = statd['player_id']
Expand Down
12 changes: 8 additions & 4 deletions pyfpdb/WinTables.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
# Standard Library modules
import re

import logging
# logging has been set up in fpdb.py or HUD_main.py, use their settings:
log = logging.getLogger("hud")

# pyGTK modules
import pygtk
import gtk
Expand Down Expand Up @@ -62,19 +66,19 @@ def find_table_parameters(self, search_string):

try:
if self.window == None:
print "Window %s not found. Skipping." % search_string
log.error( "Window %s not found. Skipping." % search_string )
return None
except AttributeError:
print "self.window doesn't exist? why?"
log.error( "self.window doesn't exist? why?" )
return None

(x, y, width, height) = win32gui.GetWindowRect(hwnd)
print "x = %s y = %s width = %s height = %s" % (x, y, width, height)
log.debug("x = %s y = %s width = %s height = %s" % (x, y, width, height))
self.x = int(x) + b_width
self.y = int(y) + tb_height
self.width = width - x
self.height = height - y
print "x = %s y = %s width = %s height = %s" % (self.x, self.y, self.width, self.height)
log.debug("x = %s y = %s width = %s height = %s" % (self.x, self.y, self.width, self.height))
#self.height = int(height) - b_width - tb_height
#self.width = int(width) - 2*b_width

Expand Down
10 changes: 6 additions & 4 deletions pyfpdb/fpdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,14 +906,16 @@ def __init__(self):

if not options.errorsToConsole:
fileName = os.path.join(self.config.dir_log, 'fpdb-errors.txt')
print "\nNote: error output is being diverted to fpdb-errors.txt and HUD-errors.txt in\n" \
+ self.config.dir_log + "Any major error will be reported there _only_.\n"
print "\nNote: error output is being diverted to fpdb-errors.txt and HUD-errors.txt in:\n" \
+ self.config.dir_log + "\nAny major error will be reported there _only_.\n"
errorFile = open(fileName, 'w', 0)
sys.stderr = errorFile

self.statusIcon = gtk.StatusIcon()
if os.path.exists(os.path.join(sys.path[0], '../gfx/fpdb-cards.png')):
self.statusIcon.set_from_file(os.path.join(sys.path[0], '../gfx/fpdb-cards.png'))
# use getcwd() here instead of sys.path[0] so that py2exe works:
cards = os.path.join(os.getcwd(), '..','gfx','fpdb-cards.png')
if os.path.exists(cards):
self.statusIcon.set_from_file(cards)
elif os.path.exists('/usr/share/pixmaps/fpdb-cards.png'):
self.statusIcon.set_from_file('/usr/share/pixmaps/fpdb-cards.png')
else:
Expand Down
Loading

0 comments on commit f117b62

Please sign in to comment.