~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/changecache.py

  • Committer: Martin Albisetti
  • Date: 2008-10-24 17:54:06 UTC
  • mfrom: (230.1.2 pep8)
  • Revision ID: martin.albisetti@canonical.com-20081024175406-73bpc73m7pshat9c
PEP8 fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
 
42
42
class FakeShelf(object):
 
43
 
43
44
    def __init__(self, filename):
44
45
        create_table = not os.path.exists(filename)
45
46
        self.connection = dbapi2.connect(filename)
46
47
        self.cursor = self.connection.cursor()
47
48
        if create_table:
48
49
            self._create_table()
 
50
 
49
51
    def _create_table(self):
50
52
        self.cursor.execute(
51
53
            "create table RevisionData "
52
54
            "(revid binary primary key, data binary)")
53
55
        self.connection.commit()
 
56
 
54
57
    def _serialize(self, obj):
55
58
        r = dbapi2.Binary(cPickle.dumps(obj, protocol=2))
56
59
        return r
 
60
 
57
61
    def _unserialize(self, data):
58
62
        return cPickle.loads(str(data))
 
63
 
59
64
    def get(self, revid):
60
65
        self.cursor.execute(
61
 
            "select data from revisiondata where revid = ?", (revid,))
 
66
            "select data from revisiondata where revid = ?", (revid, ))
62
67
        filechange = self.cursor.fetchone()
63
68
        if filechange is None:
64
69
            return None
65
70
        else:
66
71
            return self._unserialize(filechange[0])
 
72
 
67
73
    def add(self, revid_obj_pairs):
68
 
        for  (r, d) in revid_obj_pairs:
 
74
        for (r, d) in revid_obj_pairs:
69
75
            self.cursor.execute(
70
76
                "insert into revisiondata (revid, data) values (?, ?)",
71
77
                (r, self._serialize(d)))
73
79
 
74
80
 
75
81
class FileChangeCache(object):
 
82
 
76
83
    def __init__(self, history, cache_path):
77
84
        self.history = history
78
85
 
100
107
                missing_entry_indices.append(len(out))
101
108
                out.append(None)
102
109
        if missing_entries:
103
 
            missing_changes = self.history.get_file_changes_uncached(missing_entries)
 
110
            missing_changes = self.history.get_file_changes_uncached(
 
111
                                  missing_entries)
104
112
            revid_changes_pairs = []
105
113
            for i, entry, changes in zip(
106
114
                missing_entry_indices, missing_entries, missing_changes):