raj-abhilash1's branch to ensure we block release on Falcon 0.3. I moved and
[mailman.git] / copybump.py
bloba4eea59a35dbd657812060e8570adfc296be8461
1 #! /usr/bin/env python3
3 import os
4 import re
5 import sys
6 import stat
7 import datetime
10 FSF = 'by the Free Software Foundation, Inc.'
11 this_year = datetime.date.today().year
12 pyre = re.compile(r'# Copyright \(C\) ((?P<start>\d{4})-)?(?P<end>\d{4})')
14 MODE = (stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
17 def do_file(path, owner):
18 permissions = os.stat(path).st_mode & MODE
19 with open(path) as in_file, open(path + '.out', 'w') as out_file:
20 try:
21 for line in in_file:
22 mo = pyre.match(line)
23 if mo is None:
24 out_file.write(line)
25 continue
26 start = (mo.group('end')
27 if mo.group('start') is None
28 else mo.group('start'))
29 if int(start) == this_year:
30 out_file.write(line)
31 continue
32 print('# Copyright (C) {}-{} {}'.format(
33 start, this_year, owner), file=out_file)
34 print('=>', path)
35 for line in in_file:
36 out_file.write(line)
37 except UnicodeDecodeError:
38 print('Cannot convert path:', path)
39 os.remove(path + '.out')
40 return
41 os.rename(path + '.out', path)
42 os.chmod(path, permissions)
45 def remove(dirs, path):
46 try:
47 dirs.remove(path)
48 except ValueError:
49 pass
52 def do_walk():
53 try:
54 owner = sys.argv[1]
55 except IndexError:
56 owner = FSF
57 for root, dirs, files in os.walk('.'):
58 if root == '.':
59 remove(dirs, '.bzr')
60 remove(dirs, '.git')
61 remove(dirs, 'bin')
62 remove(dirs, 'contrib')
63 remove(dirs, 'develop-eggs')
64 remove(dirs, 'eggs')
65 remove(dirs, 'parts')
66 remove(dirs, 'gnu-COPYING-GPL')
67 remove(dirs, '.installed.cfg')
68 remove(dirs, '.bzrignore')
69 remove(dirs, 'distribute_setup.py')
70 if root == './src':
71 remove(dirs, 'mailman.egg-info')
72 if root == './src/mailman':
73 remove(dirs, 'messages')
74 for file_name in files:
75 if os.path.splitext(file_name)[1] in ('.pyc', '.gz', '.egg'):
76 continue
77 path = os.path.join(root, file_name)
78 if os.path.isfile(path):
79 do_file(path, owner)
82 if __name__ == '__main__':
83 do_walk()