Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Improved handling of database connection errors

  • Loading branch information...
commit 89b566eaef62dd148d223adc71a21d05286955fd 1 parent 60e9431
@twinther authored
View
4 addon.xml
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.moviequiz"
name="Movie Quiz"
- version="0.5.6"
+ version="0.5.7"
provider-name="twinther [tommy@winther.nu]">
<requires>
<import addon="xbmc.python" version="2.0"/>
- <import addon="script.module.buggalo" version="1.0.1"/>
+ <import addon="script.module.buggalo" version="1.1.0"/>
<import addon="script.module.elementtree" version="1.2.7"/>
<import addon="script.module.myconnpy" version="0.3.2"/>
</requires>
View
3  changelog.txt
@@ -1,3 +1,6 @@
+[B]Version 0.5.7 - 2012-07-11[/B]
+- Improved handling of database connection errors
+
[B]Version 0.5.6 - 2012-07-05[/B]
- Changed database connection handling to hopefully avoid some errors
View
92 quizlib/db.py
@@ -88,10 +88,8 @@ def connect():
settings['user'] = doc.findtext('videodatabase/user')
if doc.findtext('videodatabase/pass') is not None:
settings['pass'] = doc.findtext('videodatabase/pass')
- except ExpatError:
- xbmc.log("Unable to parse advancedsettings.xml")
- except SyntaxError:
- xbmc.log("Unable to parse advancedsettings.xml")
+ except (ExpatError, SyntaxError):
+ raise DbException("Unable to parse advancedsettings.xml")
xbmc.log("Successfully loaded DB settings")
@@ -631,34 +629,35 @@ class SQLiteDatabase(Database):
PARAM_REPL = '?'
def __init__(self, settings):
- super(SQLiteDatabase, self).__init__()
- found = True
- db_file = None
-
- # Find newest MyVideos.db and use that
- candidates = glob.glob(settings['host'] + '/MyVideos*.db')
- candidates = natural_sorted(candidates)
- list.reverse(candidates)
- if settings.has_key('name') and settings['name'] is not None:
- candidates.insert(0, settings['name'] + '.db') # defined in settings
-
- for candidate in candidates:
- db_file = os.path.join(settings['host'], candidate)
- if os.path.exists(db_file):
- found = True
- break
-
- if not found:
- xbmc.log("Unable to find any known SQLiteDatabase files!")
- return
-
- #xbmc.log("Connecting to SQLite database file: %s" % db_file)
- self.conn = sqlite3.connect(db_file, check_same_thread = False)
- self.conn.row_factory = _sqlite_dict_factory
- xbmc.log("SQLiteDatabase opened")
-
- super(SQLiteDatabase, self).postInit()
-
+ try:
+ super(SQLiteDatabase, self).__init__()
+ found = True
+ db_file = None
+
+ # Find newest MyVideos.db and use that
+ candidates = glob.glob(settings['host'] + '/MyVideos*.db')
+ candidates = natural_sorted(candidates)
+ list.reverse(candidates)
+ if settings.has_key('name') and settings['name'] is not None:
+ candidates.insert(0, settings['name'] + '.db') # defined in settings
+
+ for candidate in candidates:
+ db_file = os.path.join(settings['host'], candidate)
+ if os.path.exists(db_file):
+ found = True
+ break
+
+ if not found:
+ raise DbException("Unable to find any known SQLiteDatabase files!")
+
+ #xbmc.log("Connecting to SQLite database file: %s" % db_file)
+ self.conn = sqlite3.connect(db_file, check_same_thread = False)
+ self.conn.row_factory = _sqlite_dict_factory
+ xbmc.log("SQLiteDatabase opened")
+
+ super(SQLiteDatabase, self).postInit()
+ except Exception, ex:
+ raise DbException(ex)
def _sqlite_dict_factory(cursor, row):
d = {}
@@ -680,19 +679,22 @@ class MySQLDatabase(Database):
PARAM_REPL = '%s'
def __init__(self, settings):
- super(MySQLDatabase, self).__init__()
- xbmc.log("Connecting to MySQL database...")
- dbName = self._find_newest_database(settings)
-
- self.conn = mysql.connector.connect(
- host = settings['host'],
- user = settings['user'],
- passwd = settings['pass'],
- db = str(dbName)
- )
-
- #xbmc.log("MySQLDatabase %s opened" % dbName)
- super(MySQLDatabase, self).postInit()
+ try:
+ super(MySQLDatabase, self).__init__()
+ xbmc.log("Connecting to MySQL database...")
+ dbName = self._find_newest_database(settings)
+
+ self.conn = mysql.connector.connect(
+ host = settings['host'],
+ user = settings['user'],
+ passwd = settings['pass'],
+ db = str(dbName)
+ )
+
+ #xbmc.log("MySQLDatabase %s opened" % dbName)
+ super(MySQLDatabase, self).postInit()
+ except Exception, ex:
+ raise DbException(ex)
def cursor(self):
return self.conn.cursor(cursor_class = MySQLCursorDict)
View
19 quizlib/gui.py
@@ -120,21 +120,28 @@ def __new__(cls):
def __init__(self):
super(MenuGui, self).__init__()
self.trivia = None
- self.database = db.Database.connect()
+ try:
+ self.database = db.Database.connect()
+ self.databaseError = None
+ except db.DbException, ex:
+ self.databaseError = ex
self.moviesEnabled = True
self.tvShowsEnabled = True
- if self.database is None:
- pass
-
def close(self):
- print "Closing database"
- self.database.close()
+ if hasattr(self, 'database') and self.database is not None:
+ print "Closing database"
+ self.database.close()
super(MenuGui, self).close()
@buggalo.buggalo_try_except()
def onInit(self):
+ if self.databaseError is not None:
+ xbmcgui.Dialog().ok(strings(E_REQUIREMENTS_MISSING), strings(E_DATABASE_ERROR_LINE1), strings(E_DATABASE_ERROR_LINE2), str(self.databaseError))
+ self.close()
+ return
+
if not self.trivia:
loadingGui = LoadingGui(self)
loadingGui.doModal()
View
2  quizlib/strings.py
@@ -126,6 +126,8 @@
E_TVSHOW_RATING_LIMIT_LINE2 = 30068
E_TVSHOW_RATING_LIMIT_LINE3 = 30069
+E_DATABASE_ERROR_LINE1 = 30070
+E_DATABASE_ERROR_LINE2= 30071
SETT_ONLY_WATCHED_MOVIES = 'only.watched.movies'
SETT_MOVIE_RATING_LIMIT_ENABLED = 'movie.rating.limit.enabled'
View
3  resources/language/Danish/strings.xml
@@ -49,6 +49,9 @@
<string id="30068">[I]Begræns udvalget af TV-serier baseret på Content rating[/I]</string>
<string id="30069">indstillingen er slået fra.</string>
+ <string id="30070">Det var ikke muligt at tilgå XBMC's database.</string>
+ <string id="30071">Fejlbeskeden er:</string>
+
<!-- Menu -->
<string id="30100">Spil Film Quiz</string>
<string id="30101">Spil TV Quiz</string>
View
3  resources/language/English/strings.xml
@@ -49,6 +49,9 @@
<string id="30068">[I]Limit TV show selection based on Content rating[/I]</string>
<string id="30069">setting will be disabled.</string>
+ <string id="30070">There was a problem accessing the XBMC database.</string>
+ <string id="30071">The error message is:</string>
+
<!-- Menu -->
<string id="30100">Play Movie Quiz</string>
<string id="30101">Play TV Quiz</string>
Please sign in to comment.
Something went wrong with that request. Please try again.