1 #! /usr/bin/env python3
10 FSF
= 'by the Free Software Foundation, Inc.'
11 this_year
= datetime
.date
.today().year
12 pyre_c
= re
.compile(r
'# Copyright \(C\) ((?P<start>\d{4})-)?(?P<end>\d{4})')
13 pyre_n
= re
.compile(r
'# Copyright ((?P<start>\d{4})-)?(?P<end>\d{4})')
14 new_c
= '# Copyright (C) {}-{} {}'
15 new_n
= '# Copyright {}-{} {}'
17 MODE
= (stat
.S_IRWXU | stat
.S_IRWXG | stat
.S_IRWXO
)
20 if '--noc' in sys
.argv
:
23 sys
.argv
.remove('--noc')
29 def do_file(path
, owner
):
30 permissions
= os
.stat(path
).st_mode
& MODE
31 with
open(path
) as in_file
, open(path
+ '.out', 'w') as out_file
:
34 mo_c
= pyre_c
.match(line
)
35 mo_n
= pyre_n
.match(line
)
36 if mo_c
is None and mo_n
is None:
39 mo
= (mo_n
if mo_c
is None else mo_c
)
40 start
= (mo
.group('end')
41 if mo
.group('start') is None
42 else mo
.group('start'))
43 if int(start
) == this_year
:
46 print(new
.format(start
, this_year
, owner
), file=out_file
)
50 except UnicodeDecodeError:
51 print('Cannot convert path:', path
)
52 os
.remove(path
+ '.out')
54 os
.rename(path
+ '.out', path
)
55 os
.chmod(path
, permissions
)
58 def remove(dirs
, path
):
70 for root
, dirs
, files
in os
.walk('.'):
75 remove(dirs
, 'contrib')
76 remove(dirs
, 'develop-eggs')
79 remove(dirs
, 'gnu-COPYING-GPL')
80 remove(dirs
, '.installed.cfg')
81 remove(dirs
, '.bzrignore')
82 remove(dirs
, 'distribute_setup.py')
84 remove(dirs
, 'mailman.egg-info')
85 if root
== './src/mailman':
86 remove(dirs
, 'messages')
87 for file_name
in files
:
88 if os
.path
.splitext(file_name
)[1] in ('.pyc', '.gz', '.egg'):
90 path
= os
.path
.join(root
, file_name
)
91 if os
.path
.isfile(path
):
95 if __name__
== '__main__':