From 85c635d1da2677067f1b0c21a2b93198e40fab87 Mon Sep 17 00:00:00 2001 From: eblade Date: Fri, 31 Jul 2009 00:13:51 -0400 Subject: [PATCH 1/4] remove error handler on Load Profile menu opt (menu opt doesn't work anyway, so it doesn't error) --- pyfpdb/fpdb.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index b3162239..48f0202c 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -204,10 +204,10 @@ class fpdb: # print 'User cancelled loading profile' #except: # pass - try: - self.load_profile() - except: - pass + #try: + self.load_profile() + #except: + # pass self.release_global_lock() #end def dia_load_profile From 21b859f244931770385b62bc9fb204f61ee2a7bc Mon Sep 17 00:00:00 2001 From: eblade Date: Fri, 31 Jul 2009 00:15:25 -0400 Subject: [PATCH 2/4] remove error handler on hudcache rebuild menu, if it errors we should know about it --- pyfpdb/fpdb.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 48f0202c..570143cf 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -246,19 +246,16 @@ class fpdb: def dia_recreate_hudcache(self, widget, data=None): if self.obtain_global_lock(): - try: - dia_confirm = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Confirm recreating HUD cache") - diastring = "Please confirm that you want to re-create the HUD cache." - dia_confirm.format_secondary_text(diastring) - - response = dia_confirm.run() - dia_confirm.destroy() - if response == gtk.RESPONSE_YES: - self.db.rebuild_hudcache() - elif response == gtk.REPSONSE_NO: - print 'User cancelled rebuilding hud cache' - except: - pass + dia_confirm = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Confirm recreating HUD cache") + diastring = "Please confirm that you want to re-create the HUD cache." + dia_confirm.format_secondary_text(diastring) + + response = dia_confirm.run() + dia_confirm.destroy() + if response == gtk.RESPONSE_YES: + self.db.rebuild_hudcache() + elif response == gtk.REPSONSE_NO: + print 'User cancelled rebuilding hud cache' self.release_global_lock() From 047b5d94d98ddb51f4fbf0e87da9f081c02876b1 Mon Sep 17 00:00:00 2001 From: eblade Date: Fri, 31 Jul 2009 00:40:31 -0400 Subject: [PATCH 3/4] move constant dicts/lists from functions to global vars, so they aren't loaded every time the function is run --- pyfpdb/Card.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/pyfpdb/Card.py b/pyfpdb/Card.py index 6ab9b62d..8e99599b 100755 --- a/pyfpdb/Card.py +++ b/pyfpdb/Card.py @@ -94,29 +94,32 @@ def cardFromValueSuit(value, suit): elif suit == 's': return(value+38) else: return(0) -def valueSuitFromCard(card): - """ Function to convert a card stored in the database (int 0-52) into value - and suit like 9s, 4c etc """ - if card < 0 or card > 52 or not card: - return('') - else: - return( ['', '2h', '3h', '4h', '5h', '6h', '7h', '8h', '9h', 'Th', 'Jh', 'Qh', 'Kh', 'Ah' +suitFromCardList = ['', '2h', '3h', '4h', '5h', '6h', '7h', '8h', '9h', 'Th', 'Jh', 'Qh', 'Kh', 'Ah' , '2d', '3d', '4d', '5d', '6d', '7d', '8d', '9d', 'Td', 'Jd', 'Qd', 'Kd', 'Ad' , '2c', '3c', '4c', '5c', '6c', '7c', '8c', '9c', 'Tc', 'Jc', 'Qc', 'Kc', 'Ac' , '2s', '3s', '4s', '5s', '6s', '7s', '8s', '9s', 'Ts', 'Js', 'Qs', 'Ks', 'As' - ][card] ) + ] +def valueSuitFromCard(card): + """ Function to convert a card stored in the database (int 0-52) into value + and suit like 9s, 4c etc """ + global suitFromCardList + if card < 0 or card > 52 or not card: + return('') + else: + return suitFromCardList[card] -def encodeCard(cardString): - """Take a card string (Ah) and convert it to the db card code (1).""" - try: - return {'2h': 1, '3h': 2, '4h': 3, '5h': 4, '6h': 5, '7h': 6, '8h': 7, '9h': 8, 'Th': 9, 'Jh': 10, 'Qh': 11, 'Kh': 12, 'Ah': 13, +encodeCardList = {'2h': 1, '3h': 2, '4h': 3, '5h': 4, '6h': 5, '7h': 6, '8h': 7, '9h': 8, 'Th': 9, 'Jh': 10, 'Qh': 11, 'Kh': 12, 'Ah': 13, '2d': 14, '3d': 15, '4d': 16, '5d': 17, '6d': 18, '7d': 19, '8d': 20, '9d': 21, 'Td': 22, 'Jd': 23, 'Qd': 24, 'Kd': 25, 'Ad': 26, '2c': 27, '3c': 28, '4c': 29, '5c': 30, '6c': 31, '7c': 32, '8c': 33, '9c': 34, 'Tc': 35, 'Jc': 36, 'Qc': 27, 'Kc': 38, 'Ac': 39, '2s': 40, '3s': 41, '4s': 42, '5s': 43, '6s': 44, '7s': 45, '8s': 46, '9s': 47, 'Ts': 48, 'Js': 49, 'Qs': 50, 'Ks': 51, 'As': 52, ' ': 0 - }[cardString] - except: - return 0 # everthing that isn't known is a unknown! + } + +def encodeCard(cardString): + """Take a card string (Ah) and convert it to the db card code (1).""" + global encodeCardList + if cardString not in encodeCardList: return 0 + return encodeCardList[cardString] if __name__ == '__main__': print "fpdb card encoding(same as pokersource)" From 6df03cb2343ec2abc1932c855c84e2441afb016c Mon Sep 17 00:00:00 2001 From: eblade Date: Fri, 31 Jul 2009 01:15:28 -0400 Subject: [PATCH 4/4] HUD_main: if new hand id int is not available, we can't print it, so that generates a second error, double fault fpdb_import: ok, we're keeping two lists now, one with updated st_size and one with m_time. grrr. --- pyfpdb/HUD_main.py | 3 ++- pyfpdb/fpdb_import.py | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 218707bd..7378d6f7 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -163,7 +163,8 @@ class HUD_main(object): cards['common'] = comm_cards['common'] except Exception, err: print "db error: skipping ", new_hand_id, err - sys.stderr.write("Database error %s in hand %d. Skipping.\n" % (err, int(new_hand_id))) + if new_hand_id: # new_hand_id is none if we had an error prior to the store + sys.stderr.write("Database error %s in hand %d. Skipping.\n" % (err, int(new_hand_id))) continue if type == "tour": # hand is from a tournament diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 76b483ba..85526d2c 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -68,7 +68,8 @@ class Importer: self.addToDirList = {} self.removeFromFileList = {} # to remove deleted files self.monitor = False - self.updated = {} #Time last import was run {file:mtime} + self.updatedsize = {} + self.updatedtime = {} self.lines = None self.faobs = None # File as one big string self.pos_in_file = {} # dict to remember how far we have read in the file @@ -268,15 +269,18 @@ class Importer: if os.path.exists(file): stat_info = os.stat(file) #rulog.writelines("path exists ") - if file in self.updated: - if stat_info.st_size > self.updated[file]: + 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]: self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1]) - self.updated[file] = stat_info.st_size + self.updatedsize[file] = stat_info.st_size + self.updatedtime[file] = time() else: if os.path.isdir(file) or (time() - stat_info.st_mtime) < 60: - self.updated[file] = 0 + self.updatedsize[file] = 0 + self.updatedtime[file] = 0 else: - self.updated[file] = stat_info.st_size + self.updatedsize[file] = stat_info.st_size + 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)