mercurial/appendfile.py
author Vadim Gelfer <vadim.gelfer@gmail.com>
Wed, 29 Mar 2006 10:27:16 -0800
changeset 2019 ced2d3620f95
parent 2010 db1eb0de286a
child 2027 94d3170399e1
permissions -rw-r--r--
add merge command. means same thing as "update -m". repo.addchangegroup method now returns number of heads modified and added, so command line can tell whether update or merge needed. this makes tiny change to ssh wire protocol, but change is backwards compatible. pull command now returns 0 if no changes to pull.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     1
# appendfile.py - special classes to make repo updates atomic
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     2
#
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     3
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     4
#
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     6
# of the GNU General Public License, incorporated herein by reference.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     7
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     8
from demandload import *
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     9
demandload(globals(), "cStringIO changelog manifest os tempfile")
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    10
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    11
# writes to metadata files are ordered.  reads: changelog, manifest,
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    12
# normal files.  writes: normal files, manifest, changelog.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    13
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    14
# manifest contains pointers to offsets in normal files.  changelog
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    15
# contains pointers to offsets in manifest.  if reader reads old
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    16
# changelog while manifest or normal files are written, it has no
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    17
# pointers into new parts of those files that are maybe not consistent
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    18
# yet, so will not read them.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    19
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    20
# localrepo.addchangegroup thinks it writes changelog first, then
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    21
# manifest, then normal files (this is order they are available, and
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    22
# needed for computing linkrev fields), but uses appendfile to hide
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    23
# updates from readers.  data not written to manifest or changelog
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    24
# until all normal files updated.  write manifest first, then
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    25
# changelog.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    26
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    27
# with this write ordering, readers cannot see inconsistent view of
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    28
# repo during update.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    29
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    30
class appendfile(object):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    31
    '''implement enough of file protocol to append to revlog file.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    32
    appended data is written to temp file.  reads and seeks span real
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    33
    file and temp file.  readers cannot see appended data until
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    34
    writedata called.'''
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    35
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    36
    def __init__(self, fp):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    37
        fd, self.tmpname = tempfile.mkstemp()
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    38
        self.tmpfp = os.fdopen(fd, 'ab+')
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    39
        self.realfp = fp
2010
db1eb0de286a fix appendfile problem on macos.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1999
diff changeset
    40
        self.offset = fp.tell()
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    41
        # real file is not written by anyone else. cache its size so
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    42
        # seek and read can be fast.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    43
        self.fpsize = os.fstat(fp.fileno()).st_size
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    44
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    45
    def seek(self, offset):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    46
        '''virtual file offset spans real file and temp file.'''
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    47
        self.offset = offset
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    48
        if self.offset < self.fpsize:
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    49
            self.realfp.seek(self.offset)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    50
        else:
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    51
            self.tmpfp.seek(self.offset - self.fpsize)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    52
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    53
    def read(self, count=-1):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    54
        '''only trick here is reads that span real file and temp file.'''
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    55
        fp = cStringIO.StringIO()
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    56
        old_offset = self.offset
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    57
        if self.offset < self.fpsize:
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    58
            s = self.realfp.read(count)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    59
            fp.write(s)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    60
            self.offset += len(s)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    61
            if count > 0:
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    62
                count -= len(s)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    63
        if count != 0:
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    64
            if old_offset != self.offset:
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    65
                self.tmpfp.seek(self.offset - self.fpsize)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    66
            s = self.tmpfp.read(count)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    67
            fp.write(s)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    68
            self.offset += len(s)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    69
        return fp.getvalue()
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    70
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    71
    def write(self, s):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    72
        '''append to temp file.'''
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    73
        self.tmpfp.write(s)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    74
        # all writes are appends, so offset must go to end of file.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    75
        self.offset = self.fpsize + self.tmpfp.tell()
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    76
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    77
    def writedata(self):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    78
        '''copy data from temp file to real file.'''
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    79
        self.tmpfp.seek(0)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    80
        s = self.tmpfp.read()
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    81
        self.tmpfp.close()
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    82
        self.realfp.seek(0, 2)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    83
        # small race here.  we write all new data in one call, but
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    84
        # reader can see partial update due to python or os. file
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    85
        # locking no help: slow, not portable, not reliable over nfs.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    86
        # only safe thing is write to temp file every time and rename,
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    87
        # but performance bad when manifest or changelog gets big.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    88
        self.realfp.write(s)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    89
        self.realfp.close()
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    90
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    91
    def __del__(self):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    92
        '''delete temp file even if exception raised.'''
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    93
        try: os.unlink(self.tmpname)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    94
        except: pass
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    95
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    96
class sharedfile(object):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    97
    '''let file objects share a single appendfile safely.  each
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    98
    sharedfile has own offset, syncs up with appendfile offset before
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    99
    read and after read and write.'''
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   100
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   101
    def __init__(self, fp):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   102
        self.fp = fp
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   103
        self.offset = 0
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   104
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   105
    def seek(self, offset):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   106
        self.offset = offset
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   107
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   108
    def read(self, count=-1):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   109
        try:
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   110
            if self.offset != self.fp.offset:
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   111
                self.fp.seek(self.offset)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   112
            return self.fp.read(count)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   113
        finally:
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   114
            self.offset = self.fp.offset
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   115
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   116
    def write(self, s):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   117
        try:
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   118
            return self.fp.write(s)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   119
        finally:
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   120
            self.offset = self.fp.offset
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   121
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   122
    def close(self):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   123
        # revlog wants this.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   124
        pass
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   125
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   126
    def flush(self):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   127
        # revlog wants this.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   128
        pass
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   129
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   130
    def writedata(self):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   131
        self.fp.writedata()
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   132
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   133
class appendopener(object):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   134
    '''special opener for files that only read or append.'''
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   135
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   136
    def __init__(self, opener):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   137
        self.realopener = opener
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   138
        # key: file name, value: appendfile object
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   139
        self.fps = {}
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   140
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   141
    def __call__(self, name, mode='r'):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   142
        '''open file.  return same cached appendfile object for every
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   143
        later call.'''
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   144
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   145
        assert mode in 'ra'
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   146
        fp = self.fps.get(name)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   147
        if fp is None:
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   148
            fp = appendfile(self.realopener(name, 'a+'))
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   149
            self.fps[name] = fp
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   150
        return sharedfile(fp)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   151
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   152
    def writedata(self):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   153
        '''copy data from temp files to real files.'''
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   154
        # write .d file before .i file.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   155
        fps = self.fps.items()
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   156
        fps.sort()
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   157
        for name, fp in fps:
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   158
            fp.writedata()
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   159
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   160
# files for changelog and manifest are in different appendopeners, so
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   161
# not mixed up together.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   162
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   163
class appendchangelog(changelog.changelog, appendopener):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   164
    def __init__(self, opener):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   165
        appendopener.__init__(self, opener)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   166
        changelog.changelog.__init__(self, self)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   167
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   168
class appendmanifest(manifest.manifest, appendopener):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   169
    def __init__(self, opener):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   170
        appendopener.__init__(self, opener)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   171
        manifest.manifest.__init__(self, self)