diff options
Diffstat (limited to 'copybump.py')
| -rwxr-xr-x | copybump.py | 34 |
1 files changed, 22 insertions, 12 deletions
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<start>\d{4}-)?(?P<end>\d{4})') +pyre = re.compile(r'# Copyright \(C\) ((?P<start>\d{4})-)?(?P<end>\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(): |
