4 Copyright (C) 2008--2011 Jan Nieuwenhuizen <janneke@gnu.org>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 3 of the
9 License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 def pytt (from_re, to, file_name):
28 s = file (file_name).read ()
29 name = os.path.basename (file_name)
30 base, ext = os.path.splitext (name)
31 t = re.sub (from_re, to % locals (), s)
36 stat_info = os.stat (file_name)
37 mode = stat.S_IMODE (stat_info[stat.ST_MODE])
38 os.system ('mv --backup=t %(file_name)s %(file_name)s~' % locals ())
39 file (file_name, 'w').write (t)
40 os.chmod (file_name, mode)
43 from_re = re.compile (sys.argv[1], re.MULTILINE)
45 if not sys.argv[3:] or sys.argv[3] == '-':
46 sys.stdout.write (re.sub (from_re, to, sys.stdin.read ()))
48 for f in sys.argv[3:]:
51 if __name__ == '__main__':