From 6b00311756e7c4d54205ccc1b2d55b00550755c4 Mon Sep 17 00:00:00 2001 From: Worros Date: Fri, 4 Jun 2010 14:37:46 +0800 Subject: [PATCH 1/5] Make sqlite index deletion and creation work. Also updated the coding style and logging in that area. --- pyfpdb/Database.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 8939d4b3..23fb02fb 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -1162,7 +1162,8 @@ class Database: self.connection.set_isolation_level(0) # allow table/index operations to work for idx in self.indexes[self.backend]: if self.backend == self.MYSQL_INNODB: - print "creating mysql index ", idx['tab'], idx['col'] + print "Creating mysql index %s %s" %(idx['tab'], idx['col']) + log.debug("Creating sqlite index %s %s" %(idx['tab'], idx['col'])) try: s = "create index %s on %s(%s)" % (idx['col'],idx['tab'],idx['col']) self.get_cursor().execute(s) @@ -1170,21 +1171,23 @@ class Database: print " create idx failed: " + str(sys.exc_info()) elif self.backend == self.PGSQL: # mod to use tab_col for index name? - print "creating pg index ", idx['tab'], idx['col'] + print "Creating pg index %s %s" %(idx['tab'], idx['col']) + log.debug("Creating sqlite index %s %s" %(idx['tab'], idx['col'])) try: s = "create index %s_%s_idx on %s(%s)" % (idx['tab'], idx['col'], idx['tab'], idx['col']) self.get_cursor().execute(s) except: print " create idx failed: " + str(sys.exc_info()) elif self.backend == self.SQLITE: - log.debug("Creating sqlite index %s %s" % (idx['tab'], idx['col'])) + print "Creating sqlite index %s %s" %(idx['tab'], idx['col']) + log.debug("Creating sqlite index %s %s" %(idx['tab'], idx['col'])) try: s = "create index %s_%s_idx on %s(%s)" % (idx['tab'], idx['col'], idx['tab'], idx['col']) self.get_cursor().execute(s) except: log.debug("Create idx failed: " + str(sys.exc_info())) else: - print "Only MySQL, Postgres and SQLite supported so far" + print "Unknown database: MySQL, Postgres and SQLite supported" return -1 if self.backend == self.PGSQL: self.connection.set_isolation_level(1) # go back to normal isolation level @@ -1215,8 +1218,15 @@ class Database: % (idx['tab'],idx['col']) ) except: print " drop idx failed: " + str(sys.exc_info()) + elif self.backend == self.SQLITE: + print "Dropping sqlite index ", idx['tab'], idx['col'] + try: + self.get_cursor().execute( "drop index %s_%s_idx" + % (idx['tab'],idx['col']) ) + except: + print " drop idx failed: " + str(sys.exc_info()) else: - print "Only MySQL and Postgres supported so far" + print "Only MySQL, Postgres and SQLITE supported, what are you trying to use?" return -1 if self.backend == self.PGSQL: self.connection.set_isolation_level(1) # go back to normal isolation level From 212438a0c60fe78f2cc7dd539ca4b4b296844c50 Mon Sep 17 00:00:00 2001 From: Worros Date: Fri, 4 Jun 2010 15:25:56 +0800 Subject: [PATCH 2/5] Database.py - Additional logging and comments --- pyfpdb/Database.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 23fb02fb..ce4e3f6f 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -193,7 +193,7 @@ class Database: # alter table t add constraint c foreign key (fkcol) references tab(rcol) # (fkcol is used for foreigh key name) - # mysql to list indexes: + # mysql to list indexes: (CG - "LIST INDEXES" should work too) # SELECT table_name, index_name, non_unique, column_name # FROM INFORMATION_SCHEMA.STATISTICS # WHERE table_name = 'tbl_name' @@ -223,6 +223,7 @@ class Database: # Note: index names must be unique across a schema # CREATE INDEX idx ON tab(col) # DROP INDEX idx + # SELECT * FROM PG_INDEXES # SQLite notes: @@ -1075,7 +1076,7 @@ class Database: c = self.get_cursor() c.execute(self.sql.query['createSettingsTable']) - log.debug(self.sql.query['createSitesTable']) + log.debug("Creating tables") c.execute(self.sql.query['createSitesTable']) c.execute(self.sql.query['createGametypesTable']) c.execute(self.sql.query['createPlayersTable']) @@ -1088,7 +1089,8 @@ class Database: c.execute(self.sql.query['createHandsActionsTable']) c.execute(self.sql.query['createHudCacheTable']) - # create unique indexes: + # Create unique indexes: + log.debug("Creating unique indexes") c.execute(self.sql.query['addTourneyIndex']) c.execute(self.sql.query['addHandsIndex']) c.execute(self.sql.query['addPlayersIndex']) From 12ad272f91f6300d1ed1c875cd5dea78ed6f8d85 Mon Sep 17 00:00:00 2001 From: Worros Date: Fri, 4 Jun 2010 15:26:50 +0800 Subject: [PATCH 3/5] SQL.py - Add functions for listing indexes. Not used anywhere - may be a good reference at some point --- pyfpdb/SQL.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index deb9d527..37d214ff 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -51,6 +51,18 @@ class Sql: WHERE type='table' ORDER BY name;""" + ################################ + # List indexes + ################################ + if db_server == 'mysql': + self.query['list_tables'] = """SHOW INDEXES""" + elif db_server == 'postgresql': + self.query['list_tables'] = """SELECT tablename, indexname FROM PG_INDEXES""" + elif db_server == 'sqlite': + self.query['list_tables'] = """SELECT name FROM sqlite_master + WHERE type='index' + ORDER BY name;""" + ################################################################## # Drop Tables - MySQL, PostgreSQL and SQLite all share same syntax ################################################################## From 0c3cdb12f8f6ea9f56c4ba29e94b1c8cd751d5c7 Mon Sep 17 00:00:00 2001 From: Worros Date: Fri, 4 Jun 2010 15:59:47 +0800 Subject: [PATCH 4/5] General cleanup - Exception messages and improved logging. Stars HHC, HHC itself and Hand. Should not get the first 100 characters of an failing hand in the log, which contains the handid for later reference. Played around with the number of characters a while ago - 100 chars is about the sweet spot. --- pyfpdb/Hand.py | 11 ++++++----- pyfpdb/HandHistoryConverter.py | 6 ++---- pyfpdb/PokerStarsToFpdb.py | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index adb7d3f6..71fc6ced 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -274,15 +274,16 @@ If a player has None chips he won't be added.""" self.streets.update(match.groupdict()) log.debug("markStreets:\n"+ str(self.streets)) else: + tmp = self.handText[0:100] log.error("markstreets didn't match") log.error(" - Assuming hand cancelled") self.cancelled = True - raise FpdbParseError + raise FpdbParseError("FpdbParseError: markStreets appeared to fail: First 100 chars: '%s'" % tmp) def checkPlayerExists(self,player): if player not in [p[1] for p in self.players]: - print "checkPlayerExists", player, "fail" - raise FpdbParseError + print "DEBUG: checkPlayerExists %s fail" % player + raise FpdbParseError("checkPlayerExists: '%s' failed." % player) @@ -1487,9 +1488,9 @@ class Pot(object): if self.sym is None: self.sym = "C" if self.total is None: - print "call Pot.end() before printing pot total" + print "DEBUG: call Pot.end() before printing pot total" # NB if I'm sure end() is idempotent, call it here. - raise FpdbParseError + raise FpdbParseError("FpdbError in printing Hand object") ret = "Total pot %s%.2f" % (self.sym, self.total) if len(self.pots) < 2: diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 5b65b955..3b858f10 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -137,8 +137,7 @@ Otherwise, finish at EOF. self.numHands += 1 except FpdbParseError, e: self.numErrors += 1 - log.warning("Failed to convert hand %s" % e.hid) - log.warning("Exception msg: '%s'" % str(e)) + log.warning("HHC.start(follow): processHand failed: Exception msg: '%s'" % e) log.debug(handText) else: handsList = self.allHandsAsList() @@ -152,8 +151,7 @@ Otherwise, finish at EOF. self.processedHands.append(self.processHand(handText)) except FpdbParseError, e: self.numErrors += 1 - log.warning("Failed to convert hand %s" % e.hid) - log.warning("Exception msg: '%s'" % str(e)) + log.warning("HHC.start(): processHand failed: Exception msg: '%s'" % e) log.debug(handText) self.numHands = len(handsList) endtime = time.time() diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index 79bef1ea..17a9b15c 100644 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -140,7 +140,7 @@ class PokerStars(HandHistoryConverter): tmp = handText[0:100] log.error("determineGameType: Unable to recognise gametype from: '%s'" % tmp) log.error("determineGameType: Raising FpdbParseError") - raise FpdbParseError + raise FpdbParseError("Unable to recognise gametype from: '%s'" % tmp) mg = m.groupdict() # translations from captured groups to fpdb info strings @@ -194,7 +194,7 @@ class PokerStars(HandHistoryConverter): except KeyError: log.error("determineGameType: Lim_Blinds has no lookup for '%s'" % mg['BB']) log.error("determineGameType: Raising FpdbParseError") - raise FpdbParseError + raise FpdbParseError("Lim_Blinds has no lookup for '%s'" % mg['BB']) # NB: SB, BB must be interpreted as blinds or bets depending on limit type. return info From 3b823574ab8ceeb4022b7272fbca3bf495f15e37 Mon Sep 17 00:00:00 2001 From: Worros Date: Sat, 5 Jun 2010 00:44:40 +0800 Subject: [PATCH 5/5] Bump version to 0.20 --- pyfpdb/fpdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 768795ab..3d9db3d7 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -110,7 +110,7 @@ import Database import Configuration import Exceptions -VERSION = "0.12" +VERSION = "0.20" class fpdb: