-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
65 lines (58 loc) · 1.43 KB
/
logger.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
#!/usr/bin/python
# coding=utf-8
import os
import re
import sys
def commentLog(path):
lines = []
isCommented = False
fout = open(path, "r")
for line in fout.readlines():
if re.match("\s*L\..*(.*);", line) or re.match("import wxc\.android\.logwriter\.L;", line):
line = "// " + line
isCommented = True
lines.append(line)
fout.close()
if isCommented:
fin = open(path, "w")
fin.writelines(lines);
fin.close()
def uncommentLog(path):
lines = []
hasComment = False
fout = open(path, "r")
for line in fout.readlines():
if re.match("\s*//\s*L\..*(.*);", line) or re.match("\s*//\s*import wxc\.android\.logwriter\.L;", line):
index = line.index("// ") + 3
line = line[index:]
hasComment = True
lines.append(line)
fout.close()
if hasComment:
fin = open(path, "w")
fin.writelines(lines);
fin.close()
if __name__ == "__main__":
if len(sys.argv) == 2:
mode = sys.argv[1]
# print mode, type(mode)
# print sys.path[0]
os.chdir(sys.path[0])
try:
if mode == '0':
os.rename("app/libs/llogger.jar", "llogger.jar")
else:
os.rename("llogger.jar", "app/libs/llogger.jar")
except OSError:
pass
for root, dirs, files in os.walk("app/src/main/java"):
if len(files) > 0:
for f in files:
if f.endswith(".java"):
path = root + '/' + f
if mode == '0':
commentLog(path)
else:
uncommentLog(path)
else:
print "Please set mode, 0:coment Log, 1:uncomment Log"