4 Copyright (c) 2008--2009
5 Jan Nieuwenhuizen <janneke@gnu.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 def pytt (from_re, to, file_name):
30 s = file (file_name).read ()
31 name = os.path.basename (file_name)
32 base, ext = os.path.splitext (name)
33 t = re.sub (from_re, to % locals (), s)
38 stat_info = os.stat (file_name)
39 mode = stat.S_IMODE (stat_info[stat.ST_MODE])
40 os.system ('mv --backup=t %(file_name)s %(file_name)s~' % locals ())
41 file (file_name, 'w').write (t)
42 os.chmod (file_name, mode)
45 from_re = re.compile (sys.argv[1], re.MULTILINE)
47 if not sys.argv[3:] or sys.argv[3] == '-':
48 sys.stdout.write (re.sub (from_re, to, sys.stdin.read ()))
50 for f in sys.argv[3:]:
53 if __name__ == '__main__':