]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/grand-replace.py
Run grand-replace (issue 3765)
[lilypond.git] / scripts / build / grand-replace.py
1 #! @PYTHON@
2
3 # This file is part of LilyPond, the GNU music typesetter.
4 #
5 # Copyright (C) 2009--2014 Jan Nieuwenhuizen <janneke@gnu.org>
6 #
7 # LilyPond 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 3 of the License, or
10 # (at your option) any later version.
11 #
12 # LilyPond 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.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19
20 import datetime
21 import os
22 import re
23 import sys
24 #
25 sys.path.insert (0, '@top-src-dir@/scripts/build')
26 import pytt
27
28 dry_run = False
29
30 def read_pipe (cmd, ignore_errors=False):
31     pipe = os.popen (cmd)
32     val = pipe.read ()
33     if pipe.close () and not ignore_errors:
34         raise SystemFailed ('Pipe failed: %(cmd)s' % locals ())
35     return val
36
37 def filter_out (p, lst):
38     return filter (lambda x: not p (x), lst)
39
40 copied_files = [
41     'help2man.pl',
42     'mf2pt1.mp',
43     'mf2pt1.pl',
44     'texinfo.tex',
45     'txi-de.tex',
46     'txi-en.tex',
47     'txi-fr.tex',
48     'txi-es.tex',
49     'txi-it.tex',
50     ]
51
52 def main ():
53     files = filter_out (lambda x: (os.path.basename (x) in copied_files
54                                    or 'CHANGES' in x or 'ChangeLog' in x),
55                         read_pipe ('cd @top-src-dir@ && git ls-files').split ())
56     os.chdir ('@top-src-dir@')
57     year = datetime.datetime.now ().year
58     last_year = year - 1
59     last_year_1d = last_year % 10
60     for f in files:
61         pytt.pytt ('(Copyright|\(c\)|\(C\)|@copyright\{\})\s*%(last_year)s(?=[^-]|$)' % locals (),
62                    r'\1 %(last_year)s--%(year)s' % locals (),
63                    f)
64         pytt.pytt ('(Copyright|\(c\)|\(C\)|@copyright\{\})\s*([^-]*)--(20[0-9][0-%(last_year_1d)s])' % locals (),
65                    r'\1 \2--%(year)s' % locals (),
66                    f)
67
68 if __name__ == '__main__':
69     main ()