]> git.donarmstrong.com Git - lilypond.git/commitdiff
Rewrite grand-replace.
authorJan Nieuwenhuizen <janneke@gnu.org>
Thu, 8 Jan 2009 13:21:05 +0000 (14:21 +0100)
committerJan Nieuwenhuizen <janneke@gnu.org>
Thu, 8 Jan 2009 13:49:25 +0000 (14:49 +0100)
make/substitute.make
scripts/build/grand-replace.py [new file with mode: 0644]
scripts/build/grand-replace.sh [deleted file]
scripts/build/pytt.py [changed mode: 0644->0755]

index fc175ece72f684ee9ed462e76f0b93dfb91b24a2..74ba9f67d9455afba614e8652d7f4e00f36cb62d 100644 (file)
@@ -36,3 +36,5 @@ ATVARIABLES = \
   program_prefix\
   program_suffix\
   sharedstatedir\
+  src-dir\
+  top-src-dir\
diff --git a/scripts/build/grand-replace.py b/scripts/build/grand-replace.py
new file mode 100644 (file)
index 0000000..dc0697d
--- /dev/null
@@ -0,0 +1,69 @@
+#! @PYTHON@
+
+'''
+    Copyright (c) 2009--210    Jan Nieuwenhuizen <janneke@gnu.org>
+
+    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 2, 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, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+'''
+
+import datetime
+import os
+import re
+import sys
+#
+sys.path.insert (0, '@top-src-dir@/scripts/build')
+import pytt
+
+dry_run = False
+
+def read_pipe (cmd, ignore_errors=False):
+    pipe = os.popen (cmd)
+    val = pipe.read ()
+    if pipe.close () and not ignore_errors:
+        raise SystemFailed ('Pipe failed: %(cmd)s' % locals ())
+    return val
+
+def filter_out (p, lst):
+    return filter (lambda x: not p (x), lst)
+
+copied_files = [
+    'help2man.pl',
+    'mf2pt1.mp',
+    'mf2pt1.pl',
+    'texinfo.tex',
+    'txi-de.tex',
+    'txi-en.tex',
+    'txi-fr.tex',
+    'txi-sf.tex',
+    ]
+
+def main ():
+    files = filter_out (lambda x: (os.path.basename (x) in copied_files
+                                   or 'CHANGES' in x or 'ChangeLog' in x),
+                        read_pipe ('cd @top-src-dir@ && git ls-files').split ())
+    os.chdir ('@top-src-dir@')
+    year = datetime.datetime.now ().year
+    last_year = year - 1
+    last_year_1d = last_year % 10
+    for f in files:
+        pytt.pytt ('(Copyright|\(c\)|\(C\)|@copyright\{\})\s*%(last_year)s([^-]|$)' % locals (),
+                   r'\1 %(last_year)s--%(year)s' % locals (),
+                   f)
+        pytt.pytt ('(Copyright|\(c\)|\(C\)|@copyright\{\})\s*([^-]*)--(20[0-9][0-%(last_year_1d)s])' % locals (),
+                   r'\1 \2--%(year)s' % locals (),
+                   f)
+
+if __name__ == '__main__':
+    main ()
diff --git a/scripts/build/grand-replace.sh b/scripts/build/grand-replace.sh
deleted file mode 100644 (file)
index ce26e51..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#!@BASH@
-# note: dash does not work
-
-pytt '(Copyright|\(c\)|\(C\)|@copyright\{\})\s*2008' '\1 2008--2009' $(find . -mindepth 2 -type f | grep -Ev 'out/|out-scons|out-www/|.git/|.scon|#|~' | grep -iv 'change')
-pytt '(Copyright|\(c\)|\(C\)|@copyright\{\})\s*([^-]*--)(200[0-8])' '\1 \2\062009' $(find . -mindepth 2 -type f | grep -Ev 'out/|out-scons|out-www/|.git/|.scon|#|~' | grep -iv 'change')
old mode 100644 (file)
new mode 100755 (executable)
index 09f5c7b..8aee66b
@@ -1,24 +1,54 @@
-#!@PYTHON@
+#! /usr/bin/python
+
+'''
+    Copyright (c) 2008--2009
+    Jan Nieuwenhuizen <janneke@gnu.org>
+
+    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 2, 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, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+'''
 
 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 ()