~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lock.py

  • Committer: Martin Pool
  • Date: 2005-06-10 07:32:36 UTC
  • Revision ID: mbp@sourcefrog.net-20050610073236-c432e2cefe65df58
- create branch lock files if they don't exist

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
"""
36
36
 
37
37
 
38
 
import sys, os
 
38
import sys
 
39
import os
39
40
 
40
 
from trace import mutter, note, warning
41
 
from errors import LockError
 
41
from bzrlib.trace import mutter, note, warning
 
42
from bzrlib.errors import LockError
42
43
 
43
44
class _base_Lock(object):
44
45
    def _open(self, filename, filemode):
45
 
        self.f = open(filename, filemode)
46
 
        return self.f
47
 
    
 
46
        import errno
 
47
        try:
 
48
            self.f = open(filename, filemode)
 
49
            return self.f
 
50
        except IOError, e:
 
51
            if e.errno != errno.ENOENT:
 
52
                raise
 
53
 
 
54
            # maybe this is an old branch (before may 2005)
 
55
            mutter("trying to create missing branch lock %r" % filename)
 
56
            
 
57
            self.f = open(filename, 'wb')
 
58
            return self.f
 
59
 
48
60
 
49
61
    def __del__(self):
50
62
        if self.f:
51
63
            from warnings import warn
52
64
            warn("lock on %r not released" % self.f)
53
65
            self.unlock()
 
66
            
54
67
 
55
68
    def unlock(self):
56
69
        raise NotImplementedError()