File size: 2,134 Bytes
f65fe85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# grand-replace.py
#
# This file is part of LilyPond, the GNU music typesetter.
#
# Copyright (C) 2009--2020 Jan Nieuwenhuizen <[email protected]>
#
# LilyPond 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.
#
# LilyPond 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 LilyPond.  If not, see <http://www.gnu.org/licenses/>.

import datetime
import os
import re
import sys
#
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 [x for x in lst if not p(x)]


copied_files = [
    'help2man.pl',
    'mf2pt1.mp',
    'mf2pt1.pl',
    'texinfo.tex',
    'txi-ca.tex',
    'txi-de.tex',
    'txi-en.tex',
    'txi-es.tex',
    'txi-fr.tex',
    'txi-hu.tex',
    'txi-it.tex',
    'txi-ja.tex',
    'txi-nl.tex',
    'txi-pt.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('git ls-files').split())
    year = datetime.datetime.now().year
    last_year = year - 1
    last_year_1d = last_year % 10
    for f in files:
        pytt.pytt(r'(Copyright|\(c\)|\(C\)|@copyright\{\})\s*%(last_year)s(?=[^-]|$)' % locals(),
                  r'\1 %(last_year)s--%(year)s' % locals(),
                  f)
        pytt.pytt(r'(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()