1 #! /usr/bin/env python3
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
):
19 permissions
= os
.stat(path
).st_mode
& MODE
20 with
open(path
) as in_file
, open(path
+ '.out', 'w') as out_file
:
27 start
= (mo
.group('end')
28 if mo
.group('start') is None
29 else mo
.group('start'))
30 if int(start
) == this_year
:
33 print('# Copyright (C) {}-{} {}'.format(
34 start
, this_year
, owner
), file=out_file
)
37 except UnicodeDecodeError:
38 print('Cannot convert path:', path
)
39 os
.remove(path
+ '.out')
41 os
.rename(path
+ '.out', path
)
42 os
.chmod(path
, permissions
)
45 def remove(dirs
, path
):
57 for root
, dirs
, files
in os
.walk('.'):
61 remove(dirs
, 'contrib')
62 remove(dirs
, 'develop-eggs')
65 remove(dirs
, 'gnu-COPYING-GPL')
66 remove(dirs
, '.installed.cfg')
67 remove(dirs
, '.bzrignore')
68 remove(dirs
, 'distribute_setup.py')
70 remove(dirs
, 'mailman.egg-info')
71 if root
== './src/mailman':
72 remove(dirs
, 'messages')
73 for file_name
in files
:
74 if os
.path
.splitext(file_name
)[1] in ('.pyc', '.gz', '.egg'):
76 path
= os
.path
.join(root
, file_name
)
77 if os
.path
.isfile(path
):
81 if __name__
== '__main__':