summaryrefslogtreecommitdiff
path: root/copybump.py
diff options
context:
space:
mode:
authorBarry Warsaw2010-01-01 00:53:17 -0500
committerBarry Warsaw2010-01-01 00:53:17 -0500
commit593339ca7550a5dcc42d858ceb39f878af24f6e5 (patch)
treece89251d75bf97d27cbf73cf7e47845f9a3f020b /copybump.py
parent721ea276d6126ab611f52292f7b8646425d7e113 (diff)
downloadmailman-593339ca7550a5dcc42d858ceb39f878af24f6e5.tar.gz
mailman-593339ca7550a5dcc42d858ceb39f878af24f6e5.tar.zst
mailman-593339ca7550a5dcc42d858ceb39f878af24f6e5.zip
Diffstat (limited to 'copybump.py')
-rwxr-xr-xcopybump.py34
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():