]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/grand-replace.py
Rewrite grand-replace.
[lilypond.git] / scripts / build / grand-replace.py
1 #! @PYTHON@
2
3 '''
4     Copyright (c) 2009--210    Jan Nieuwenhuizen <janneke@gnu.org>
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2, or (at your option)
9     any later version.
10
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.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 '''
20
21 import datetime
22 import os
23 import re
24 import sys
25 #
26 sys.path.insert (0, '@top-src-dir@/scripts/build')
27 import pytt
28
29 dry_run = False
30
31 def read_pipe (cmd, ignore_errors=False):
32     pipe = os.popen (cmd)
33     val = pipe.read ()
34     if pipe.close () and not ignore_errors:
35         raise SystemFailed ('Pipe failed: %(cmd)s' % locals ())
36     return val
37
38 def filter_out (p, lst):
39     return filter (lambda x: not p (x), lst)
40
41 copied_files = [
42     'help2man.pl',
43     'mf2pt1.mp',
44     'mf2pt1.pl',
45     'texinfo.tex',
46     'txi-de.tex',
47     'txi-en.tex',
48     'txi-fr.tex',
49     'txi-sf.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 ()