comparison contrib/tmplrewrite.py @ 8432:94ef2c8ce683

contrib: add tmplrewrite.py script to help rewrite old templater syntax
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Fri, 15 May 2009 10:47:19 +0200
parents
children
comparison
equal deleted inserted replaced
8431:5c1aabc58004 8432:94ef2c8ce683
1 #!/usr/bin/python
2 import sys, os, re
3
4 IGNORE = ['.css', '.py']
5 oldre = re.compile('#([\w\|%]+)#')
6
7 def rewrite(fn):
8 f = open(fn)
9 new = open(fn + '.new', 'wb')
10 for ln in f:
11 new.write(oldre.sub('{\\1}', ln))
12 new.close()
13 f.close()
14 os.rename(new.name, f.name)
15
16 if __name__ == '__main__':
17 if len(sys.argv) < 2:
18 print 'usage: python tmplrewrite.py [file [file [file]]]'
19 for fn in sys.argv[1:]:
20 if os.path.splitext(fn) in IGNORE:
21 continue
22 print 'rewriting %s...' % fn
23 rewrite(fn)