~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/atomicfile.py

  • Committer: Martin Pool
  • Date: 2005-05-10 06:54:12 UTC
  • Revision ID: mbp@sourcefrog.net-20050510065412-cd05087d1e4297f7
- Avoid calling Inventory.iter_entries() when finding modified
  files.  Just calculate path for files known to be changed.
- update_cache optionally takes inventory to avoid reading it twice.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    Open this as for a regular file, then use commit() to move into
25
25
    place or abort() to cancel.
26
26
 
27
 
    You may wish to wrap this in a codecs.EncodedFile to do unicode
28
 
    encoding.
 
27
    An encoding can be specified; otherwise the default is ascii.
29
28
    """
30
29
 
31
 
    def __init__(self, filename, mode='wb'):
 
30
    def __init__(self, filename, mode='wb', encoding=None):
32
31
        if mode != 'wb' and mode != 'wt':
33
32
            raise ValueError("invalid AtomicFile mode %r" % mode)
34
33
 
38
37
        self.realfilename = filename
39
38
        
40
39
        self.f = open(self.tmpfilename, mode)
 
40
 
 
41
        if encoding:
 
42
            import codecs
 
43
            self.f = codecs.EncodedFile(self.f, encoding)
 
44
        
41
45
        self.write = self.f.write
 
46
        self.closed = property(self.f.closed)
42
47
 
43
48
    def commit(self):
44
49
        import sys, os
53
58
        self.f.close()
54
59
        os.remove(self.tmpfilename)
55
60
        
 
61