-
Notifications
You must be signed in to change notification settings - Fork 6
/
encopyright.py
107 lines (93 loc) · 3.45 KB
/
encopyright.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/local/bin/python
# Copyright 2000-2003 Michael Hudson mwh@python.net
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import os, time, sys
header = """\
# Copyright 2000-%s Michael Hudson mwh@python.net
#
# All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\
"""%(time.localtime()[0])
header_lines = header.split("\n")
def process(thing):
if os.path.isdir(thing):
for subthing in os.listdir(thing):
process(os.path.join(thing, subthing))
elif os.path.isfile(thing):
if thing[-3:] == '.py':
process_file(thing)
else:
print "W `%s' not file or directory"%(thing,)
def process_file(file):
ilines = open(file).readlines()
prelines = []
old_copyright = []
if not ilines:
print "W ignoring empty file `%s'"%(file,)
return
i = 0
diff = 0
if ilines[0][:2] == '#!':
prelines.append(ilines[0])
i += 1
while i < len(ilines) and not ilines[i].strip():
prelines.append(ilines[i])
i += 1
while i < len(ilines) and ilines[i][:1] == '#':
old_copyright.append(ilines[i])
i += 1
if abs(len(old_copyright) - len(header_lines)) < 2:
for x, y in zip(old_copyright, header_lines):
if x[:-1] != y:
print "C change needed in", file
ofile = open(file, "w")
for l in prelines:
ofile.write(l)
ofile.write(header + "\n")
for l in ilines[i:]:
ofile.write(l)
ofile.close()
break
else:
print "M no change needed in", file
else:
print "A no (c) in", file
ofile = open(file, "w")
for l in prelines:
ofile.write(l)
ofile.write(header + "\n\n")
for l in ilines[len(prelines):]:
ofile.write(l)
ofile.close()
for thing in sys.argv[1:]:
process(thing)