Skip to content

Commit

Permalink
require pysqlite on py-2.5 and lower, use it in buildbot.db
Browse files Browse the repository at this point in the history
This adds a method that determines the appropriate module to use for
sqlite, and special-cases the dbapiName 'sqlite3' to point to this
module name
  • Loading branch information
Dustin J. Mitchell committed Feb 15, 2010
1 parent 950bc5c commit 2bef2d8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
5 changes: 3 additions & 2 deletions README
Expand Up @@ -57,8 +57,9 @@ REQUIREMENTS:

sqlite3: http://pypi.python.org/pypi/pysqlite

sqlite3 is required for python-2.4 and earlier (already included
in python-2.5 and later)
sqlite3 is required for python-2.5 and earlier (already included
in python-2.5 and later, but the version in python-2.5 has nasty
bugs)

simplejson: http://pypi.python.org/pypi/simplejson

Expand Down
21 changes: 21 additions & 0 deletions buildbot/db.py
Expand Up @@ -36,11 +36,13 @@
# ***** END LICENSE BLOCK *****

import sys, time, collections, base64

try:
import simplejson
json = simplejson # this hushes pyflakes
except ImportError:
import json

from twisted.python import log, reflect, threadable
from twisted.internet import defer, reactor
from twisted.enterprise import adbapi
Expand Down Expand Up @@ -247,10 +249,29 @@ class DB:
"""This just records the desired database type and connect() arguments.
It defines the database that should be used."""
def __init__(self, dbapiName, *connargs, **connkw):
# special-case 'sqlite3', replacing it with the available implementation
if dbapiName == 'sqlite3':
dbapiName = get_sqlite_dbapi_name()

self.dbapiName = dbapiName
self.connargs = connargs
self.connkw = connkw

def get_sqlite_dbapi_name():
# see which dbapi we can use, and import it as 'buildbot.db.sqlite3'
sqlite_dbapi_name = None
try:
from pysqlite2 import dbapi2 as sqlite3
sqlite_dbapi_name = "pysqlite2.dbapi2"
except ImportError:
# don't use built-in sqlite3 on 2.5 -- it has *bad* bugs
if sys.version_info >= (2,6):
import sqlite3
sqlite_dbapi_name = "pysqlite2.dbapi2"
else:
raise
return sqlite_dbapi_name

def create_db(spec):
"""This is used by the create-master and upgrade-master subcommands, to
create the database for the very first time. It will refuse to touch an
Expand Down
10 changes: 4 additions & 6 deletions buildbot/test/runs/test_db.py
Expand Up @@ -37,7 +37,7 @@

import os
from twisted.trial import unittest
from twisted.python import failure
from twisted.python import failure, reflect
from twisted.internet import defer, reactor
from twisted.application import service
from buildbot import db, master
Expand All @@ -47,8 +47,7 @@
from buildbot.changes.changes import OldChangeMaster, Change
from buildbot.changes.manager import ChangeManager
from buildbot.test.pollmixin import PollMixin
import sqlite3

from buildbot.test.runutils import RunMixin

class ShouldFailMixin:

Expand Down Expand Up @@ -139,7 +138,8 @@ def test_old_version(self):
os.makedirs(basedir)
fn = self._fn = os.path.join(basedir, "oldversion.sqlite")
spec = db.DB("sqlite3", fn)
conn = sqlite3.connect(fn)
dbapi = reflect.namedModule(db.get_sqlite_dbapi_name())
conn = dbapi.connect(fn)
c = conn.cursor()
c.execute("CREATE TABLE version (version INTEGER);")
c.execute("INSERT INTO version VALUES (0);")
Expand Down Expand Up @@ -443,8 +443,6 @@ def _build_not_sleep(res):

return d

from runutils import RunMixin

config_1 = """
from buildbot.process import factory
from buildbot.steps import dummy
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Expand Up @@ -246,13 +246,14 @@ def finalize_options(self):
'twisted >= 2.0.0',
'Jinja2',
]
# Python-2.5 and up includes sqlite3
if not py_25:
setup_args['install_requires'].append('sqlite3')
# Python-2.6 and up includes json
if not py_26:
setup_args['install_requires'].append('simplejson')

# Python-2.6 and up includes a working A sqlite (py25's is broken)
if not py_26:
setup_args['install_requires'].append('pysqlite')

entry_points={
'console_scripts': [
'buildbot = buildbot.scripts.runner:run'],
Expand Down

0 comments on commit 2bef2d8

Please sign in to comment.