Permalink
Browse files

Fixed the pysqlite bw compatibility stub to handle version numbers co…

…rrectly. Plus fixed some other minor issues.
  • Loading branch information...
1 parent 98a0ec1 commit 6f3e7ecd8841d9f7da74719c2c629e2dee4d891f Jim Carroll committed Apr 20, 2011
Showing with 10 additions and 2 deletions.
  1. +10 −2 addons/script.module.pysqlite/lib/pysqlite2/__init__.py
@@ -3,18 +3,26 @@
# this will only be allowed if the script is greater that version 1.0
import warnings
+import re
+
+# Credit gnud on stackoverflow:
+# see http://stackoverflow.com/questions/1714027/version-number-comparison/1714190#1714190
+def xbmcVerCmp(version1, version2):
+ def normalize(v):
+ return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")]
+ return cmp(normalize(version1), normalize(version2))
# Not sure why this might fail but ....
try:
import __main__
xbmcapiversion = __main__.__xbmcapiversion__
except:
xbmcapiversion = "1.0"
- warnings.warn("For some reason the module'" + std(__name__) + "' couldn't get access to '__main__'. This may prevent certain backward compatility modes from operating correctly.")
+ warnings.warn("For some reason the module '" + str(__name__) + "' couldn't get access to '__main__'. This may prevent certain backward compatility modes from operating correctly.")
# if the xbmcapiversion is either not set (because trying to get it failed or
# the script was invoked in an odd manner from xbmc) ...
-if (float(xbmcapiversion) <= 1.0):
+if (xbmcVerCmp(xbmcapiversion,"1.0") <= 0):
# then import sqlite3 in place of dbapi2
try:
import sqlite3 as dbapi2

0 comments on commit 6f3e7ec

Please sign in to comment.