contrib/tmplrewrite.py
author Mads Kiilerich <mads@kiilerich.com>
Tue, 22 Feb 2011 03:03:39 +0100
branchstable
changeset 13457 e74fe15dc7fd
parent 8432 94ef2c8ce683
permissions -rwxr-xr-x
changegroup: verify all stream reads Mercurial often failed with struct.error or mpatch.mpatchError if incomplete data was received from a server. Now we validate all changegroup reads and aborts with abort: stream ended unexpectedly (got %d bytes, expected %d) if less than requested was read.

#!/usr/bin/python
import sys, os, re

IGNORE = ['.css', '.py']
oldre = re.compile('#([\w\|%]+)#')

def rewrite(fn):
    f = open(fn)
    new = open(fn + '.new', 'wb')
    for ln in f:
        new.write(oldre.sub('{\\1}', ln))
    new.close()
    f.close()
    os.rename(new.name, f.name)

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print 'usage: python tmplrewrite.py [file [file [file]]]'
    for fn in sys.argv[1:]:
        if os.path.splitext(fn) in IGNORE:
            continue
        print 'rewriting %s...' % fn
        rewrite(fn)