X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fbuild%2Fpytt.py;h=72e5825f04842d9587f9bcf6f87d35ebb8df9dcb;hb=8848da24e00c75d7de626b2ecc409fb45e87ce4a;hp=09f5c7b1f61ea4d9ce92438ad989e11282c0d2bd;hpb=6140c6eb657080939fa4aef3d00d717bd85b5028;p=lilypond.git diff --git a/scripts/build/pytt.py b/scripts/build/pytt.py old mode 100644 new mode 100755 index 09f5c7b1f6..72e5825f04 --- a/scripts/build/pytt.py +++ b/scripts/build/pytt.py @@ -1,24 +1,52 @@ -#!@PYTHON@ +#! /usr/bin/python + +''' + Copyright (C) 2008--2012 Jan Nieuwenhuizen + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +''' import os import re +import stat import sys -frm = re.compile (sys.argv[1], re.MULTILINE) -to = sys.argv[2] - -if not sys.argv[3:] or sys.argv[3] == '-': - sys.stdout.write (re.sub (frm, to, sys.stdin.read ())) -for file in sys.argv[3:]: - s = open (file).read () - name = os.path.basename (file) - base, ext = os.path.splitext (name) - t = re.sub (frm, to % locals (), s) - if s != t: - if 1: - os.system ('mv %(file)s %(file)s~~' % locals ()) - h = open (file, "w") - h.write (t) - h.close () - else: - sys.stdout.write (t) +dry_run = False + +def pytt (from_re, to, file_name): + s = file (file_name).read () + name = os.path.basename (file_name) + base, ext = os.path.splitext (name) + t = re.sub (from_re, to % locals (), s) + if s != t: + if dry_run: + sys.stdout.write (t) + else: + stat_info = os.stat (file_name) + mode = stat.S_IMODE (stat_info[stat.ST_MODE]) + os.system ('mv --backup=t %(file_name)s %(file_name)s~' % locals ()) + file (file_name, 'w').write (t) + os.chmod (file_name, mode) + +def main (): + from_re = re.compile (sys.argv[1], re.MULTILINE) + to = sys.argv[2] + if not sys.argv[3:] or sys.argv[3] == '-': + sys.stdout.write (re.sub (from_re, to, sys.stdin.read ())) + else: + for f in sys.argv[3:]: + pytt (from_re, to, f) + +if __name__ == '__main__': + main ()