-
Notifications
You must be signed in to change notification settings - Fork 0
/
codelog.py
32 lines (32 loc) · 840 Bytes
/
codelog.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
import sys,os,os.path
sig="#pyperflog"
if sys.argv[1]=="clean":
files=[i for i in sys.argv[2:] if os.path.isfile(i)]
if not files:
files=[i for i in os.listdir("./") if os.path.isfile(i)]
for fn in files:
fh=open(fn,"rb")
l=fh.read().split("\n")
fh.close()
if [i for i in l if sig in i]:
fh=open(fn,"wb")
fh.write("\n".join([i for i in l if sig not in i]))
fh.close()
sys.exit(0)
files=[i for i in sys.argv[1:] if os.path.isfile(i)]
for fn in files:
fh=open(fn,"rb")
fc=fh.read()
fh.close()
lines=fc.split("\n")
i=len(lines)
while i>0:
i-=1
l=lines[i].strip()
if l.split(" ",1)[0]=="def" and l.split("(",1)[0].strip().rsplit(" ",1)[1]!="__getattr__":
spaces=lines[i].find("def ")
lines.insert(i,(" "*spaces)+"@profile %s" % (sig,))
out="\n".join(lines)
fh=open(fn,"wb")
fh.write(out)
fh.close()