From 3381527afc14f6a1fbfac49078f99bd41f294323 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Thu, 28 Jan 2010 05:56:17 -0500 Subject: [PATCH] raise FpdbHandDuplicate error on duplicate insert attempt, catch it in import_file_dict, increment duplicates count --- pyfpdb/Hand.py | 12 +++++------- pyfpdb/fpdb_import.py | 15 +++++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 7023d50c..4fdc555e 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -229,8 +229,7 @@ db: a connected Database object""" # TourneysPlayers else: log.info("Hand.insert(): hid #: %s is a duplicate" % hh['siteHandNo']) - #Raise Duplicate exception? - pass + raise FpdbHandDuplicate(hh['siteHandNo']) def updateHudCache(self, db): db.storeHudCache(self.dbid_gt, self.dbid_pids, self.starttime, self.stats.getHandsPlayers()) @@ -618,7 +617,7 @@ class HoldemOmahaHand(Hand): if builtFrom == "HHC": hhc.readHandInfo(self) if self.gametype['type'] == 'tour': - self.tablename = "%s %s" % (self.tourNo, self.tablename) + self.tablename = "%s %s" % (self.tourNo, self.tablename) hhc.readPlayerStacks(self) hhc.compilePlayerRegexs(self) hhc.markStreets(self) @@ -914,7 +913,7 @@ class DrawHand(Hand): if builtFrom == "HHC": hhc.readHandInfo(self) if self.gametype['type'] == 'tour': - self.tablename = "%s %s" % (self.tourNo, self.tablename) + self.tablename = "%s %s" % (self.tourNo, self.tablename) hhc.readPlayerStacks(self) hhc.compilePlayerRegexs(self) hhc.markStreets(self) @@ -1110,7 +1109,7 @@ class StudHand(Hand): if builtFrom == "HHC": hhc.readHandInfo(self) if self.gametype['type'] == 'tour': - self.tablename = "%s %s" % (self.tourNo, self.tablename) + self.tablename = "%s %s" % (self.tourNo, self.tablename) hhc.readPlayerStacks(self) hhc.compilePlayerRegexs(self) hhc.markStreets(self) @@ -1202,7 +1201,7 @@ Add a complete on [street] by [player] to [amountTo] # showdownPot INT, /* pot size at sd/street7 */ return (0,0,0,0,0) - + def writeHand(self, fh=sys.__stdout__): # PokerStars format. @@ -1597,4 +1596,3 @@ ORDER BY return h - diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 1df0ad7a..859a6bc0 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -437,13 +437,15 @@ class Importer: for hand in handlist: if hand is not None: - #try, except duplicates here? hand.prepInsert(self.database) - hand.insert(self.database) - - if self.callHud and hand.dbid_hands != 0: - to_hud.append(hand.dbid_hands) - else: + try: + hand.insert(self.database) + except Exceptions.FpdbHandDuplicate: + duplicates += 1 + else: + if self.callHud and hand.dbid_hands != 0: + to_hud.append(hand.dbid_hands) + else: # TODO: Treat empty as an error, or just ignore? log.error("Hand processed but empty") self.database.commit() # Call hudcache update if not in bulk import mode @@ -461,6 +463,7 @@ class Importer: errors = getattr(hhc, 'numErrors') stored = getattr(hhc, 'numHands') + stored -= duplicates else: # conversion didn't work # TODO: appropriate response?