6860
by Barry Warsaw
Add REST API for subscription services. |
1 |
#! /usr/bin/env python3
|
2 |
||
3 |
import os |
|
4 |
import re |
|
7027
by Barry Warsaw
Make this script more generally useful even outside of the Mailman source tree. |
5 |
import sys |
6869
by Barry Warsaw
Happy New Year. |
6 |
import stat |
6860
by Barry Warsaw
Add REST API for subscription services. |
7 |
import datetime |
8 |
||
9 |
||
10 |
FSF = 'by the Free Software Foundation, Inc.' |
|
11 |
this_year = datetime.date.today().year |
|
6869
by Barry Warsaw
Happy New Year. |
12 |
pyre = re.compile(r'# Copyright \(C\) ((?P<start>\d{4})-)?(?P<end>\d{4})') |
13 |
||
14 |
MODE = (stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) |
|
6860
by Barry Warsaw
Add REST API for subscription services. |
15 |
|
16 |
||
7027
by Barry Warsaw
Make this script more generally useful even outside of the Mailman source tree. |
17 |
def do_file(path, owner): |
6868
by Barry Warsaw
intermediate |
18 |
print('=>', path) |
6869
by Barry Warsaw
Happy New Year. |
19 |
permissions = os.stat(path).st_mode & MODE |
6860
by Barry Warsaw
Add REST API for subscription services. |
20 |
with open(path) as in_file, open(path + '.out', 'w') as out_file: |
6869
by Barry Warsaw
Happy New Year. |
21 |
try: |
6860
by Barry Warsaw
Add REST API for subscription services. |
22 |
for line in in_file: |
6869
by Barry Warsaw
Happy New Year. |
23 |
mo = pyre.match(line) |
24 |
if mo is None: |
|
25 |
out_file.write(line) |
|
26 |
continue
|
|
27 |
start = (mo.group('end') |
|
28 |
if mo.group('start') is None |
|
29 |
else mo.group('start')) |
|
7037.1.1
by Barry Warsaw
In copybump, if the start year is this year, just write out the line. This |
30 |
if int(start) == this_year: |
31 |
out_file.write(line) |
|
32 |
continue
|
|
6869
by Barry Warsaw
Happy New Year. |
33 |
print('# Copyright (C) {}-{} {}'.format( |
7027
by Barry Warsaw
Make this script more generally useful even outside of the Mailman source tree. |
34 |
start, this_year, owner), file=out_file) |
6869
by Barry Warsaw
Happy New Year. |
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
|
|
6860
by Barry Warsaw
Add REST API for subscription services. |
41 |
os.rename(path + '.out', path) |
6869
by Barry Warsaw
Happy New Year. |
42 |
os.chmod(path, permissions) |
6868
by Barry Warsaw
intermediate |
43 |
|
44 |
||
7027
by Barry Warsaw
Make this script more generally useful even outside of the Mailman source tree. |
45 |
def remove(dirs, path): |
46 |
try: |
|
47 |
dirs.remove(path) |
|
48 |
except ValueError: |
|
49 |
pass
|
|
50 |
||
51 |
||
6868
by Barry Warsaw
intermediate |
52 |
def do_walk(): |
7027
by Barry Warsaw
Make this script more generally useful even outside of the Mailman source tree. |
53 |
try: |
54 |
owner = sys.argv[1] |
|
55 |
except IndexError: |
|
56 |
owner = FSF |
|
6868
by Barry Warsaw
intermediate |
57 |
for root, dirs, files in os.walk('.'): |
58 |
if root == '.': |
|
7027
by Barry Warsaw
Make this script more generally useful even outside of the Mailman source tree. |
59 |
remove(dirs, '.bzr') |
60 |
remove(dirs, 'bin') |
|
61 |
remove(dirs, 'contrib') |
|
62 |
remove(dirs, 'develop-eggs') |
|
63 |
remove(dirs, 'eggs') |
|
64 |
remove(dirs, 'parts') |
|
65 |
remove(dirs, 'gnu-COPYING-GPL') |
|
66 |
remove(dirs, '.installed.cfg') |
|
67 |
remove(dirs, '.bzrignore') |
|
68 |
remove(dirs, 'distribute_setup.py') |
|
6868
by Barry Warsaw
intermediate |
69 |
if root == './src': |
7027
by Barry Warsaw
Make this script more generally useful even outside of the Mailman source tree. |
70 |
remove(dirs, 'mailman.egg-info') |
6868
by Barry Warsaw
intermediate |
71 |
if root == './src/mailman': |
7027
by Barry Warsaw
Make this script more generally useful even outside of the Mailman source tree. |
72 |
remove(dirs, 'messages') |
6868
by Barry Warsaw
intermediate |
73 |
for file_name in files: |
74 |
if os.path.splitext(file_name)[1] in ('.pyc', '.gz', '.egg'): |
|
75 |
continue
|
|
76 |
path = os.path.join(root, file_name) |
|
77 |
if os.path.isfile(path): |
|
7027
by Barry Warsaw
Make this script more generally useful even outside of the Mailman source tree. |
78 |
do_file(path, owner) |
6868
by Barry Warsaw
intermediate |
79 |
|
80 |
||
81 |
if __name__ == '__main__': |
|
82 |
do_walk() |