From a13ae41134699d4ef1b8ba68fdc01bbd9a1705d5 Mon Sep 17 00:00:00 2001 From: Worros Date: Fri, 27 Nov 2009 20:19:43 +0800 Subject: [PATCH 1/6] Fix MySQL startup error: 2002 2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)" --- pyfpdb/Exceptions.py | 7 +++++++ pyfpdb/fpdb.py | 4 ++++ pyfpdb/fpdb_db.py | 2 ++ 3 files changed, 13 insertions(+) diff --git a/pyfpdb/Exceptions.py b/pyfpdb/Exceptions.py index 87015e3e..5b4f4391 100644 --- a/pyfpdb/Exceptions.py +++ b/pyfpdb/Exceptions.py @@ -27,5 +27,12 @@ class FpdbMySQLAccessDenied(FpdbDatabaseError): def __str__(self): return repr(self.value +" " + self.errmsg) +class FpdbMySQLNoDatabase(FpdbDatabaseError): + def __init__(self, value='', errmsg=''): + self.value = value + self.errmsg = errmsg + def __str__(self): + return repr(self.value +" " + self.errmsg) + class DuplicateError(FpdbError): pass diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 80d3fb93..9de449c9 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -473,6 +473,10 @@ class fpdb: except Exceptions.FpdbMySQLAccessDenied: self.warning_box("MySQL Server reports: Access denied. Are your permissions set correctly?") exit() + except Exceptions.FpdbMySQLNoDatabase: + msg = "MySQL client reports: 2002 error. Unable to connect - Please check that the MySQL service has been started" + self.warning_box(msg) + exit # except FpdbMySQLFailedError: # self.warning_box("Unable to connect to MySQL! Is the MySQL server running?!", "FPDB ERROR") diff --git a/pyfpdb/fpdb_db.py b/pyfpdb/fpdb_db.py index a58606be..8a0ec54e 100644 --- a/pyfpdb/fpdb_db.py +++ b/pyfpdb/fpdb_db.py @@ -106,6 +106,8 @@ class fpdb_db: except MySQLdb.Error, ex: if ex.args[0] == 1045: raise FpdbMySQLAccessDenied(ex.args[0], ex.args[1]) + elif ex.args[0] == 2002: + raise FpdbMySQLNoDatabase(ex.args[0], ex.args[1]) else: print "*** WARNING UNKNOWN MYSQL ERROR", ex elif backend == fpdb_db.PGSQL: From f5d8f153b5fd09e40f71d6592ffe7e9c406e7f3e Mon Sep 17 00:00:00 2001 From: Worros Date: Sun, 29 Nov 2009 14:40:32 +0800 Subject: [PATCH 2/6] Start of fixes to draw parsing --- pyfpdb/Hand.py | 22 +++++++++++++++------- pyfpdb/PokerStarsToFpdb.py | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index f6fa478e..a906eba4 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -535,7 +535,7 @@ Map the tuple self.gametype onto the pokerstars string describing it elif act[1] == 'bringin': return ("%s: brings in for %s%s%s" %(act[0], self.sym, act[2], ' and is all-in' if act[3] else '')) elif act[1] == 'discards': - return ("%s: discards %s %s%s" %(act[0], act[2], 'card' if act[2] == 1 else 'cards' , " [" + " ".join(self.discards[act[0]]['DRAWONE']) + "]" if self.hero == act[0] else '')) + return ("%s: discards %s %s%s" %(act[0], act[2], 'card' if act[2] == 1 else 'cards' , " [" + " ".join(self.discards['DRAWONE'][act[0]]) + "]" if self.hero == act[0] else '')) elif act[1] == 'stands pat': return ("%s: stands pat" %(act[0])) @@ -953,6 +953,13 @@ class DrawHand(Hand): act = (player, 'discards', num) self.actions[street].append(act) + def holecardsAsSet(self, street, player): + """Return holdcards: (oc, nc) as set()""" + (nc,oc) = self.holecards[street][player] + nc = set(nc) + oc = set(oc) + return (nc, oc) + def getStreetTotals(self): # street1Pot INT, /* pot size at flop/street4 */ # street2Pot INT, /* pot size at turn/street5 */ @@ -979,9 +986,10 @@ class DrawHand(Hand): if 'DEAL' in self.actions: print >>fh, _("*** DEALING HANDS ***") for player in [x[1] for x in self.players if x[1] in players_who_act_ondeal]: - if 'DEAL' in self.holecards[player]: - (nc,oc) = self.holecards[player]['DEAL'] - print >>fh, _("Dealt to %s: [%s]") % (player, " ".join(nc)) + if 'DEAL' in self.holecards: + if self.holecards['DEAL'].has_key(player): + (nc,oc) = self.holecards['DEAL'][player] + print >>fh, _("Dealt to %s: [%s]") % (player, " ".join(nc)) for act in self.actions['DEAL']: print >>fh, self.actionString(act) @@ -990,7 +998,7 @@ class DrawHand(Hand): for act in self.actions['DRAWONE']: print >>fh, self.actionString(act) if act[0] == self.hero and act[1] == 'discards': - (nc,oc) = self.holecards['DRAWONE'][act[0]] + (nc,oc) = self.holecardsAsSet('DRAWONE', act[0]) dc = self.discards['DRAWONE'][act[0]] kc = oc - dc print >>fh, _("Dealt to %s [%s] [%s]" % (act[0], " ".join(kc), " ".join(nc))) @@ -1000,7 +1008,7 @@ class DrawHand(Hand): for act in self.actions['DRAWTWO']: print >>fh, self.actionString(act) if act[0] == self.hero and act[1] == 'discards': - (nc,oc) = self.holecards['DRAWTWO'][act[0]] + (nc,oc) = self.holecardsAsSet('DRAWONE', act[0]) dc = self.discards['DRAWTWO'][act[0]] kc = oc - dc print >>fh, _("Dealt to %s [%s] [%s]" % (act[0], " ".join(kc), " ".join(nc))) @@ -1010,7 +1018,7 @@ class DrawHand(Hand): for act in self.actions['DRAWTHREE']: print >>fh, self.actionString(act) if act[0] == self.hero and act[1] == 'discards': - (nc,oc) = self.holecards['DRAWTHREE'][act[0]] + (nc,oc) = self.holecardsAsSet('DRAWONE', act[0]) dc = self.discards['DRAWTHREE'][act[0]] kc = oc - dc print >>fh, _("Dealt to %s [%s] [%s]" % (act[0], " ".join(kc), " ".join(nc))) diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index 7e63cee6..d16a9a1b 100755 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -101,7 +101,7 @@ class PokerStars(HandHistoryConverter): self.re_HeroCards = re.compile(r"^Dealt to %(PLYR)s(?: \[(?P.+?)\])?( \[(?P.+?)\])" % subst, re.MULTILINE) self.re_Action = re.compile(r""" ^%(PLYR)s:(?P\sbets|\schecks|\sraises|\scalls|\sfolds|\sdiscards|\sstands\spat) - (\s%(CUR)s(?P[.\d]+))?(\sto\s%(CUR)s(?P[.\d]+))? # the number discarded goes in + (\s(%(CUR)s)?(?P[.\d]+))?(\sto\s%(CUR)s(?P[.\d]+))? # the number discarded goes in (\scards?(\s\[(?P.+?)\])?)?""" % subst, re.MULTILINE|re.VERBOSE) self.re_ShowdownAction = re.compile(r"^%s: shows \[(?P.*)\]" % player_re, re.MULTILINE) From 9071640182735c3e00583915d34880202535713e Mon Sep 17 00:00:00 2001 From: Worros Date: Sun, 29 Nov 2009 15:22:46 +0800 Subject: [PATCH 3/6] Fix Draw parsing --- pyfpdb/Hand.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index a906eba4..9468603a 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -872,7 +872,7 @@ class DrawHand(Hand): self.streetList = ['BLINDSANTES', 'DEAL', 'DRAWONE', 'DRAWTWO', 'DRAWTHREE'] self.allStreets = ['BLINDSANTES', 'DEAL', 'DRAWONE', 'DRAWTWO', 'DRAWTHREE'] self.holeStreets = ['DEAL', 'DRAWONE', 'DRAWTWO', 'DRAWTHREE'] - self.actionStreets = ['PREDEAL', 'DEAL', 'DRAWONE', 'DRAWTWO', 'DRAWTHREE'] + self.actionStreets = ['BLINDSANTES', 'DEAL', 'DRAWONE', 'DRAWTWO', 'DRAWTHREE'] self.communityStreets = [] Hand.__init__(self, sitename, gametype, handText) self.sb = gametype['sb'] From 39f27bc78129358becb0ec99a147083c3417a310 Mon Sep 17 00:00:00 2001 From: Worros Date: Sun, 29 Nov 2009 15:28:32 +0800 Subject: [PATCH 4/6] test_PokerStars: Add 2-7 Lowball test --- pyfpdb/test_PokerStars.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pyfpdb/test_PokerStars.py b/pyfpdb/test_PokerStars.py index 8730d98a..f81388c9 100644 --- a/pyfpdb/test_PokerStars.py +++ b/pyfpdb/test_PokerStars.py @@ -95,16 +95,16 @@ def testStudImport(): (stored, dups, partial, errs, ttime) = importer.runImport() importer.clearFileList() -#def testDrawImport(): -# db.recreate_tables() -# importer = fpdb_import.Importer(False, settings, config) -# importer.setDropIndexes("don't drop") -# importer.setFailOnError(True) -# importer.setThreads(-1) -# importer.addBulkImportImportFileOrDir( -# """regression-test-files/cash/Stars/Draw/3-Draw-Limit-USD-0.10-0.20-200911.txt""", site="PokerStars") +def testDrawImport(): + db.recreate_tables() + importer = fpdb_import.Importer(False, settings, config) + importer.setDropIndexes("don't drop") + importer.setFailOnError(True) + importer.setThreads(-1) + importer.addBulkImportImportFileOrDir( + """regression-test-files/cash/Stars/Draw/3-Draw-Limit-USD-0.10-0.20-200911.txt""", site="PokerStars") # importer.addBulkImportImportFileOrDir( # """regression-test-files/cash/Stars/Draw/5-Carddraw-USD-0.10-0.20-200911.txt""", site="PokerStars") -# importer.setCallHud(False) -# (stored, dups, partial, errs, ttime) = importer.runImport() -# importer.clearFileList() + importer.setCallHud(False) + (stored, dups, partial, errs, ttime) = importer.runImport() + importer.clearFileList() From a6a3217bbc935cd6d933b435b5a635c0201d73de Mon Sep 17 00:00:00 2001 From: Worros Date: Sun, 29 Nov 2009 16:54:15 +0800 Subject: [PATCH 5/6] Fix draw parsing finally? --- pyfpdb/Hand.py | 12 ++++++------ pyfpdb/HandHistoryConverter.py | 2 +- pyfpdb/PokerStarsToFpdb.py | 4 +++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 9468603a..6242d866 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -510,7 +510,7 @@ Map the tuple self.gametype onto the pokerstars string describing it def printHand(self): self.writeHand(sys.stdout) - def actionString(self, act): + def actionString(self, act, street=None): if act[1] == 'folds': return ("%s: folds " %(act[0])) elif act[1] == 'checks': @@ -535,7 +535,7 @@ Map the tuple self.gametype onto the pokerstars string describing it elif act[1] == 'bringin': return ("%s: brings in for %s%s%s" %(act[0], self.sym, act[2], ' and is all-in' if act[3] else '')) elif act[1] == 'discards': - return ("%s: discards %s %s%s" %(act[0], act[2], 'card' if act[2] == 1 else 'cards' , " [" + " ".join(self.discards['DRAWONE'][act[0]]) + "]" if self.hero == act[0] else '')) + return ("%s: discards %s %s%s" %(act[0], act[2], 'card' if act[2] == 1 else 'cards' , " [" + " ".join(self.discards[street][act[0]]) + "]" if self.hero == act[0] else '')) elif act[1] == 'stands pat': return ("%s: stands pat" %(act[0])) @@ -991,12 +991,12 @@ class DrawHand(Hand): (nc,oc) = self.holecards['DEAL'][player] print >>fh, _("Dealt to %s: [%s]") % (player, " ".join(nc)) for act in self.actions['DEAL']: - print >>fh, self.actionString(act) + print >>fh, self.actionString(act, 'DEAL') if 'DRAWONE' in self.actions: print >>fh, _("*** FIRST DRAW ***") for act in self.actions['DRAWONE']: - print >>fh, self.actionString(act) + print >>fh, self.actionString(act, 'DRAWONE') if act[0] == self.hero and act[1] == 'discards': (nc,oc) = self.holecardsAsSet('DRAWONE', act[0]) dc = self.discards['DRAWONE'][act[0]] @@ -1006,7 +1006,7 @@ class DrawHand(Hand): if 'DRAWTWO' in self.actions: print >>fh, _("*** SECOND DRAW ***") for act in self.actions['DRAWTWO']: - print >>fh, self.actionString(act) + print >>fh, self.actionString(act, 'DRAWTWO') if act[0] == self.hero and act[1] == 'discards': (nc,oc) = self.holecardsAsSet('DRAWONE', act[0]) dc = self.discards['DRAWTWO'][act[0]] @@ -1016,7 +1016,7 @@ class DrawHand(Hand): if 'DRAWTHREE' in self.actions: print >>fh, _("*** THIRD DRAW ***") for act in self.actions['DRAWTHREE']: - print >>fh, self.actionString(act) + print >>fh, self.actionString(act, 'DRAWTHREE') if act[0] == self.hero and act[1] == 'discards': (nc,oc) = self.holecardsAsSet('DRAWONE', act[0]) dc = self.discards['DRAWTHREE'][act[0]] diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 804b3534..b618df8a 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -261,8 +261,8 @@ which it expects to find at self.re_TailSplitHands -- see for e.g. Everleaf.py. gametype = self.determineGameType(handText) log.debug("gametype %s" % gametype) hand = None + l = None if gametype is None: - l = None gametype = "unmatched" # TODO: not ideal, just trying to not error. # TODO: Need to count failed hands. diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index d16a9a1b..b3463da9 100755 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -50,7 +50,7 @@ class PokerStars(HandHistoryConverter): \s?(?P%(LEGAL_ISO)s)? )\s)? # close paren of tournament info (?PHORSE|8\-Game|HOSE)?\s?\(? - (?PHold\'em|Razz|7\sCard\sStud|7\sCard\sStud\sHi/Lo|Omaha|Omaha\sHi/Lo|Badugi|Triple\sDraw\s2\-7\sLowball)\s + (?PHold\'em|Razz|7\sCard\sStud|7\sCard\sStud\sHi/Lo|Omaha|Omaha\sHi/Lo|Badugi|Triple\sDraw\s2\-7\sLowball|5\sCard\sDraw)\s (?PNo\sLimit|Limit|Pot\sLimit)\)?,?\s (-\sLevel\s(?P[IVXLC]+)\s)? \(? # open paren of the stakes @@ -133,6 +133,7 @@ class PokerStars(HandHistoryConverter): info = {} m = self.re_GameInfo.search(handText) if not m: + print "DEBUG: determineGameType(): did not match" return None mg = m.groupdict() @@ -147,6 +148,7 @@ class PokerStars(HandHistoryConverter): '7 Card Stud Hi/Lo' : ('stud','studhilo'), 'Badugi' : ('draw','badugi'), 'Triple Draw 2-7 Lowball' : ('draw','27_3draw'), + '5 Card Draw' : ('draw','fivedraw') } currencies = { u'€':'EUR', '$':'USD', '':'T$' } # I don't think this is doing what we think. mg will always have all From 8d10cbcd5e89c01582348e78e524f4e2f983f69b Mon Sep 17 00:00:00 2001 From: Worros Date: Sun, 29 Nov 2009 17:10:14 +0800 Subject: [PATCH 6/6] test_PokerStars - Add test for 5 card draw --- pyfpdb/test_PokerStars.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyfpdb/test_PokerStars.py b/pyfpdb/test_PokerStars.py index f81388c9..b58f8a75 100644 --- a/pyfpdb/test_PokerStars.py +++ b/pyfpdb/test_PokerStars.py @@ -103,8 +103,8 @@ def testDrawImport(): importer.setThreads(-1) importer.addBulkImportImportFileOrDir( """regression-test-files/cash/Stars/Draw/3-Draw-Limit-USD-0.10-0.20-200911.txt""", site="PokerStars") -# importer.addBulkImportImportFileOrDir( -# """regression-test-files/cash/Stars/Draw/5-Carddraw-USD-0.10-0.20-200911.txt""", site="PokerStars") + importer.addBulkImportImportFileOrDir( + """regression-test-files/cash/Stars/Draw/5-Carddraw-USD-0.10-0.20-200911.txt""", site="PokerStars") importer.setCallHud(False) (stored, dups, partial, errs, ttime) = importer.runImport() importer.clearFileList()