From 0938afb8829d45cea7d3b0dca0fdc8957c8b287a Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Tue, 15 Sep 2009 23:32:23 -0500 Subject: [PATCH 1/3] FTtoFPDB: readBlinds: cleanup exception handler also deal with finishPositions not being accurate, by printing a message to that effect, instead of crashing an import --- pyfpdb/FulltiltToFpdb.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pyfpdb/FulltiltToFpdb.py b/pyfpdb/FulltiltToFpdb.py index d24c7bdd..ea17c21a 100755 --- a/pyfpdb/FulltiltToFpdb.py +++ b/pyfpdb/FulltiltToFpdb.py @@ -289,11 +289,12 @@ class Fulltilt(HandHistoryConverter): def readBlinds(self, hand): + m = self.re_PostBB.search(hand.handText) try: - m = self.re_PostSB.search(hand.handText) hand.addBlind(m.group('PNAME'), 'small blind', m.group('SB')) - except: # no small blind + except IndexError: # no small blind found hand.addBlind(None, None, None) + for a in self.re_PostBB.finditer(hand.handText): hand.addBlind(a.group('PNAME'), 'big blind', a.group('BB')) for a in self.re_PostBoth.finditer(hand.handText): @@ -656,7 +657,9 @@ class Fulltilt(HandHistoryConverter): heroName = n.group('HERO_NAME') tourney.hero = heroName # Is this really useful ? - if (tourney.finishPositions[heroName] != Decimal(n.group('HERO_FINISHING_POS'))): + if heroName not in tourney.finishPositions: + print heroName, "not found in tourney.finishPositions ..." + elif (tourney.finishPositions[heroName] != Decimal(n.group('HERO_FINISHING_POS'))): print "Bad parsing : finish position incoherent : %s / %s" % (tourney.finishPositions[heroName], n.group('HERO_FINISHING_POS')) return True From 2095f3c89908e1c4072564344f778a18b413b9e5 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Wed, 16 Sep 2009 00:13:42 -0500 Subject: [PATCH 2/3] use with..as for file reading/writing, as we don't need 2.4 compat anyway right? --- pyfpdb/Configuration.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 1b2f47b4..61308641 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -24,6 +24,7 @@ Handles HUD configuration files. ######################################################################## # Standard Library modules +from __future__ import with_statement import os import sys import inspect @@ -444,12 +445,11 @@ class Config: def read_default_conf(self, file): parms = {} - fh = open(file, "r") - for line in fh: - line = string.strip(line) - (key, value) = line.split('=') - parms[key] = value - fh.close + with open(file, "r") as fh: + for line in fh: + line = string.strip(line) + (key, value) = line.split('=') + parms[key] = value return parms def find_example_config(self): @@ -498,14 +498,12 @@ class Config: def save(self, file = None): if file != None: - f = open(file, 'w') - self.doc.writexml(f) - f.close() + with open(file, 'w') as f: + self.doc.writexml(f) else: shutil.move(self.file, self.file+".backup") - f = open(self.file, 'w') - self.doc.writexml(f) - f.close + with open(self.file, 'w'): + self.doc.writexml(f) def edit_layout(self, site_name, max, width = None, height = None, fav_seat = None, locations = None): From ded05cb290bf7a0c4da71240e5a840c13a7941e8 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Wed, 16 Sep 2009 00:54:29 -0500 Subject: [PATCH 3/3] put the regex search back into the try: in FT readBlinds() because it broke FL games somehow --- pyfpdb/FulltiltToFpdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/FulltiltToFpdb.py b/pyfpdb/FulltiltToFpdb.py index ea17c21a..e9c07e20 100755 --- a/pyfpdb/FulltiltToFpdb.py +++ b/pyfpdb/FulltiltToFpdb.py @@ -289,8 +289,8 @@ class Fulltilt(HandHistoryConverter): def readBlinds(self, hand): - m = self.re_PostBB.search(hand.handText) try: + m = self.re_PostBB.search(hand.handText) hand.addBlind(m.group('PNAME'), 'small blind', m.group('SB')) except IndexError: # no small blind found hand.addBlind(None, None, None)