-
Notifications
You must be signed in to change notification settings - Fork 42
/
panda-comment.py
70 lines (63 loc) · 2.45 KB
/
panda-comment.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
import re
PBC = "PANDABEGINCOMMENT"
PEC = "PANDAENDCOMMENT"
repltxt = " * \n"
repltxt += " * Authors:\n"
repltxt += " * Tim Leek [email protected]\n"
repltxt += " * Ryan Whelan [email protected]\n"
repltxt += " * Joshua Hodosh [email protected]\n"
repltxt += " * Michael Zhivich [email protected]\n"
repltxt += " * Brendan Dolan-Gavitt [email protected]\n"
repltxt += " * \n"
repltxt += " * This work is licensed under the terms of the GNU GPL, version 2. \n"
repltxt += " * See the COPYING file in the top-level directory. \n"
repltxt += " * \n"
# populate foo...
# cd hg/panda
# find . -exec grep -H PANDABEGIN '{}' \; > list_of_files_containing_panda_comments
x = open("list_of_files_containing_panda_comments")
for line in x:
foo = re.search("(.*):", line)
if foo:
fn = foo.groups()[0]
foo1 = re.search("panda-comment", fn)
foo2 = re.search("list_of_files_containing_panda_comments", fn)
if foo1 or foo2:
# bogon
continue
print fn
new_lines = ""
state = 0
for line in open(fn):
if state == 0:
# looking for begin comment
foo = re.search("(.*)%s(.*)" % PBC, line)
if foo:
# found begin comment
(before_stuff, after_stuff) = foo.groups()
new_lines += "%s%s\n" % (before_stuff, PBC)
new_lines += repltxt
# treat everything after begin comment as if its a new line
line = after_stuff
# now looking for end comment
state = 1
else:
# did not find
new_lines += line
if state == 1:
# looking for end comment
foo = re.search("(.*)%s(.*)" % PEC, line)
if foo:
# found end comment
(before_stuff, after_stuff) = foo.groups()
# discard before stuff
new_lines += "%s%s\n" % (PEC, after_stuff)
# just copy the rest
state = 2
continue
else:
# still haven't found end comment -- discard line
pass
if state == 2:
new_lines += line
open(fn, "w").write(new_lines)