Skip to content

Commit

Permalink
Added a backward compatibility stub for pysqlite2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Carroll committed Apr 18, 2011
1 parent 7c4cb23 commit 9c356e2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 46 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Expand Up @@ -107,7 +107,6 @@ config.log
/addons/visualization.waveform/Waveform_win32.vis
/addons/visualization.itunes/iTunes.mvis
/addons/script.module.pil/
/addons/script.module.pysqlite/

# /xbmc/guilib/
/xbmc/guilib/Makefile
Expand All @@ -129,8 +128,6 @@ config.log
# /lib/addons/
/lib/addons/script.module.pil/
!/lib/addons/script.module.pil/Makefile
/lib/addons/script.module.pysqlite/
!/lib/addons/script.module.pysqlite/Makefile

# /lib/asap/
/lib/asap/Makefile
Expand Down
4 changes: 2 additions & 2 deletions addons/script.module.pysqlite/addon.xml
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.pysqlite"
name="Python SQLite library"
name="Python SQLite library hook"
version="2.5.6"
provider-name="Gerhard Haering">
<requires>
<import addon="xbmc.python" version="1.0"/>
<import addon="xbmc.python" version="2.0"/>
</requires>
<extension point="xbmc.python.module"
library="lib" />
Expand Down
29 changes: 29 additions & 0 deletions addons/script.module.pysqlite/lib/pysqlite2/__init__.py
@@ -0,0 +1,29 @@

# if we got here then someone tried to import pysqlite.dbapi2
# this will only be allowed if the script is greater that version 1.0

import warnings

# 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.")

# 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):
# then import sqlite3 in place of dbapi2
try:
import sqlite3 as dbapi2
except Exception, e:
warnings.warn("Unable to import sqlite3. This probably means you're on a version of python prior to 2.5 and trying to run an old script.")
raise e

# whine like a sissy ...
warnings.warn("DeprecationWarning: the pysqlite2 module is deprecated; stop being lazy and change your script to use sqlite3.")
else:
raise DeprecationWarning("You cannot use pysqlite2 while depending on version " + str(xbmcapiversion) + " of the xbmc.python api. Please use sqlite3 instead.")

41 changes: 0 additions & 41 deletions lib/addons/script.module.pysqlite/Makefile

This file was deleted.

0 comments on commit 9c356e2

Please sign in to comment.