From 39e55cff34f2556f5fca7c50fb05196fbec03aa6 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Fri, 31 Jul 2015 17:20:40 -0400 Subject: copybump.py: Allow for no "(C)" in the new copyright statement. --- copybump.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'copybump.py') diff --git a/copybump.py b/copybump.py index a4eea59a3..3c91b7a0d 100755 --- a/copybump.py +++ b/copybump.py @@ -9,28 +9,41 @@ import datetime FSF = 'by the Free Software Foundation, Inc.' this_year = datetime.date.today().year -pyre = re.compile(r'# Copyright \(C\) ((?P\d{4})-)?(?P\d{4})') +pyre_c = re.compile(r'# Copyright \(C\) ((?P\d{4})-)?(?P\d{4})') +pyre_n = re.compile(r'# Copyright ((?P\d{4})-)?(?P\d{4})') +new_c = '# Copyright (C) {}-{} {}' +new_n = '# Copyright {}-{} {}' MODE = (stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) +if '--noc' in sys.argv: + pyre = pyre_n + new = new_n + sys.argv.remove('--noc') +else: + pyre = pyre_c + new = new_c + + def do_file(path, owner): permissions = os.stat(path).st_mode & MODE with open(path) as in_file, open(path + '.out', 'w') as out_file: try: for line in in_file: - mo = pyre.match(line) - if mo is None: + mo_c = pyre_c.match(line) + mo_n = pyre_n.match(line) + if mo_c is None and mo_n is None: out_file.write(line) continue + mo = (mo_n if mo_c is None else mo_c) start = (mo.group('end') if mo.group('start') is None else mo.group('start')) if int(start) == this_year: out_file.write(line) continue - print('# Copyright (C) {}-{} {}'.format( - start, this_year, owner), file=out_file) + print(new.format(start, this_year, owner), file=out_file) print('=>', path) for line in in_file: out_file.write(line) -- cgit v1.2.3-70-g09d2