From ee864033ee09dfeda69c9ffe7256116f9650bca8 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Fri, 9 Oct 2009 07:31:25 -0400 Subject: [PATCH 1/2] Add exception for not being able to connect to MySQL, make use of it to pop up an error box --- pyfpdb/Exceptions.py | 3 +++ pyfpdb/fpdb.py | 9 +++++++-- pyfpdb/fpdb_db.py | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pyfpdb/Exceptions.py b/pyfpdb/Exceptions.py index f3d75e89..eaf5d798 100644 --- a/pyfpdb/Exceptions.py +++ b/pyfpdb/Exceptions.py @@ -17,5 +17,8 @@ class FpdbParseError(FpdbError): class FpdbDatabaseError(FpdbError): pass +class FpdbMySQLFailedError(FpdbDatabaseError): + pass + class DuplicateError(FpdbError): pass diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 4703d96d..5d8d7191 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -76,7 +76,7 @@ import SQL import Database import FpdbSQLQueries import Configuration -from Exceptions import * +import Exceptions VERSION = "0.11" @@ -453,7 +453,12 @@ class fpdb: self.db.disconnect() self.sql = SQL.Sql(type = self.settings['db-type'], db_server = self.settings['db-server']) - self.db = Database.Database(self.config, sql = self.sql) + try: + self.db = Database.Database(self.config, sql = self.sql) + except Exceptions.FpdbMySQLFailedError: + self.warning_box("Unable to connect to MySQL! Is the MySQL server running?!", "FPDB ERROR") + exit() + if self.db.fdb.wrongDbVersion: diaDbVersionWarning = gtk.Dialog(title="Strong Warning - Invalid database version", parent=None, flags=0, buttons=(gtk.STOCK_OK,gtk.RESPONSE_OK)) diff --git a/pyfpdb/fpdb_db.py b/pyfpdb/fpdb_db.py index 428aa173..17fecc2c 100644 --- a/pyfpdb/fpdb_db.py +++ b/pyfpdb/fpdb_db.py @@ -80,7 +80,7 @@ class fpdb_db: try: self.db = MySQLdb.connect(host = host, user = user, passwd = password, db = database, use_unicode=True) except: - raise FpdbError("MySQL connection failed") + raise FpdbMySQLFailedError("MySQL connection failed") elif backend==fpdb_db.PGSQL: import psycopg2 import psycopg2.extensions From d4cbed121ddc135538615f24b4613701855fd197 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Fri, 9 Oct 2009 07:39:05 -0400 Subject: [PATCH 2/2] fix indentation errors --- pyfpdb/DerivedStats.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyfpdb/DerivedStats.py b/pyfpdb/DerivedStats.py index a4fb630b..7d428be9 100644 --- a/pyfpdb/DerivedStats.py +++ b/pyfpdb/DerivedStats.py @@ -107,7 +107,7 @@ class DerivedStats(): self.hands['playersVpi'] = len(vpipers) def playersAtStreetX(self, hand): - """playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4/draw1 */""" + """ playersAtStreet1 SMALLINT NOT NULL, /* num of players seeing flop/street4/draw1 */""" # self.actions[street] is a list of all actions in a tuple, contining the player name first # [ (player, action, ....), (player2, action, ...) ] # The number of unique players in the list per street gives the value for playersAtStreetXXX @@ -145,7 +145,7 @@ class DerivedStats(): # [ (player, action, ....), (player2, action, ...) ] # No idea what this value is actually supposed to be # In theory its "num small bets paid to see flop/street4, including blind" which makes sense for limit. Not so useful for nl - + pass def aggr(self, hand, i): aggrers = set()