~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weavestore.py

  • Committer: Martin Pool
  • Date: 2005-09-22 12:12:53 UTC
  • Revision ID: mbp@sourcefrog.net-20050922121253-eae2a3240ea5e493
- upgrade can no longer be done in current version branches
  so don't test it

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
    This has some shortcuts for reading and writing them.
36
36
    """
37
 
    def __init__(self, dir, get_file=None):
 
37
    def __init__(self, dir):
38
38
        self._dir = dir
39
39
        self._cache = {}
40
 
        self.enable_cache = False
41
 
        if get_file is not None:
42
 
            self.get_file = get_file
 
40
        self.enable_cache = False
43
41
 
44
 
    def get_file(self, filename):
45
 
        return file(filename, 'rb')
46
42
 
47
43
    def filename(self, file_id):
48
44
        return self._dir + os.sep + file_id + '.weave'
52
48
        if self.enable_cache:
53
49
            if file_id in self._cache:
54
50
                return self._cache[file_id]
55
 
        w = read_weave(self.get_file(self.filename(file_id)))
 
51
        w = read_weave(file(self.filename(file_id), 'rb'))
56
52
        if self.enable_cache:
57
53
            self._cache[file_id] = w
58
54
        return w
69
65
    def get_weave_or_empty(self, file_id):
70
66
        """Return a weave, or an empty one if it doesn't exist.""" 
71
67
        try:
72
 
            inf = self.get_file(self.filename(file_id))
 
68
            inf = file(self.filename(file_id), 'rb')
73
69
        except IOError, e:
74
70
            if e.errno == errno.ENOENT:
75
71
                return Weave(weave_name=file_id)
79
75
            return read_weave(inf)
80
76
    
81
77
 
82
 
    def put_empty_weave(self, file_id):
83
 
        self.put_weave(file_id, Weave())
84
 
 
85
 
 
86
78
    def put_weave(self, file_id, weave):
87
79
        """Write back a modified weave"""
88
80
        if self.enable_cache: