~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/changecache.py

  • Committer: Michael Hudson
  • Date: 2008-06-20 02:24:58 UTC
  • mto: This revision was merged to the branch mainline in revision 164.
  • Revision ID: michael.hudson@canonical.com-20080620022458-qgpah31u1yqz9sfp
reorder imports in start-loggerhead.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
from loggerhead import util
32
32
from loggerhead.lockfile import LockFile
33
33
 
 
34
 
34
35
with_lock = util.with_lock('_lock', 'ChangeCache')
35
36
 
36
 
try:
37
 
    from sqlite3 import dbapi2
38
 
except ImportError:
 
37
SQLITE_INTERFACE = os.environ.get('SQLITE_INTERFACE', 'sqlite')
 
38
 
 
39
if SQLITE_INTERFACE == 'pysqlite2':
39
40
    from pysqlite2 import dbapi2
 
41
    _param_marker = '?'
 
42
elif SQLITE_INTERFACE == 'sqlite':
 
43
    import sqlite as dbapi2
 
44
    _param_marker = '%s'
 
45
else:
 
46
    raise AssertionError("bad sqlite interface %r!?"%SQLITE_INTERFACE)
 
47
 
 
48
_select_stmt = ("select data from revisiondata where revid = ?"
 
49
                ).replace('?', _param_marker)
 
50
_insert_stmt = ("insert into revisiondata (revid, data) "
 
51
                "values (?, ?)").replace('?', _param_marker)
 
52
 
 
53
 
40
54
 
41
55
 
42
56
class FakeShelf(object):
57
71
    def _unserialize(self, data):
58
72
        return cPickle.loads(str(data))
59
73
    def get(self, revid):
60
 
        self.cursor.execute(
61
 
            "select data from revisiondata where revid = ?", (revid,))
 
74
        self.cursor.execute(_select_stmt, (revid,))
62
75
        filechange = self.cursor.fetchone()
63
76
        if filechange is None:
64
77
            return None
66
79
            return self._unserialize(filechange[0])
67
80
    def add(self, revid_obj_pairs):
68
81
        for  (r, d) in revid_obj_pairs:
69
 
            self.cursor.execute(
70
 
                "insert into revisiondata (revid, data) values (?, ?)",
71
 
                (r, self._serialize(d)))
 
82
            self.cursor.execute(_insert_stmt, (r, self._serialize(d)))
72
83
        self.connection.commit()
73
84
 
74
85