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
42 if mo
.group('start') is None
43 else mo
.group('start')
45 if int(start
) == this_year
:
49 new
.format(start
, this_year
, owner
), file=out_file
54 except UnicodeDecodeError:
55 print('Cannot convert path:', path
)
56 os
.remove(path
+ '.out')
58 os
.rename(path
+ '.out', path
)
59 os
.chmod(path
, permissions
)
62 def remove(dirs
, path
):
74 for root
, dirs
, files
in os
.walk('.'):
79 remove(dirs
, 'contrib')
80 remove(dirs
, 'develop-eggs')
83 remove(dirs
, 'gnu-COPYING-GPL')
84 remove(dirs
, '.installed.cfg')
85 remove(dirs
, '.bzrignore')
86 remove(dirs
, 'distribute_setup.py')
88 remove(dirs
, 'postorius.egg-info')
89 if root
== './src/postorius':
90 remove(dirs
, 'messages')
91 for file_name
in files
:
92 if os
.path
.splitext(file_name
)[1] in ('.pyc', '.gz', '.egg'):
94 path
= os
.path
.join(root
, file_name
)
95 if os
.path
.isfile(path
):
99 if __name__
== '__main__':