From 593339ca7550a5dcc42d858ceb39f878af24f6e5 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Fri, 1 Jan 2010 00:53:17 -0500 Subject: Happy New Year. --- copybump.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'copybump.py') diff --git a/copybump.py b/copybump.py index 83f0364c0..82b3a81dc 100755 --- a/copybump.py +++ b/copybump.py @@ -2,30 +2,40 @@ import os import re +import stat 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 = re.compile(r'# Copyright \(C\) ((?P\d{4})-)?(?P\d{4})') + +MODE = (stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) def do_file(path): print('=>', path) + permissions = os.stat(path).st_mode & MODE with open(path) as in_file, open(path + '.out', 'w') as out_file: - for line in in_file: - mo = pyre.match(line) - if mo is None: - out_file.write(line) - continue - start = (mo.group('end') - if mo.group('start') is None - else mo.group('start')) - print('# Copyright (C) {}-{} {}'.format( - mo.group('end'), this_year, FSF), file=out_file) + try: for line in in_file: - out_file.write(line) + mo = pyre.match(line) + if mo is None: + out_file.write(line) + continue + start = (mo.group('end') + if mo.group('start') is None + else mo.group('start')) + print('# Copyright (C) {}-{} {}'.format( + start, this_year, FSF), file=out_file) + for line in in_file: + out_file.write(line) + except UnicodeDecodeError: + print('Cannot convert path:', path) + os.remove(path + '.out') + return os.rename(path + '.out', path) + os.chmod(path, permissions) def do_walk(): -- cgit v1.2.3-70-g09d2