-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp_l.py
More file actions
executable file
·66 lines (54 loc) · 1.58 KB
/
php_l.py
File metadata and controls
executable file
·66 lines (54 loc) · 1.58 KB
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
#!/usr/bin/env python
"""
@file php_l.py
@author superli
@date 2017/04/10 16:43:36
"""
import os
import commands
import sys
global count
count = 0
def hilite(string, status, bold):
attr = []
if status:
# green
attr.append('32')
else:
# red
attr.append('31')
if bold:
attr.append('1')
return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), string)
def walk_recursive_dir(path, dirCallback = None, fileCallback = None):
stack = []
ret = []
stack.append(path);
while len(stack) > 0:
tmp = stack.pop(len(stack) - 1)
if(os.path.isdir(tmp)):
# print tmp
for item in os.listdir(tmp):
if not item.startswith('.'):
stack.append(os.path.join(tmp, item))
elif(os.path.isfile(tmp)):
if fileCallback:
fileCallback(tmp)
def php_l(file):
if os.path.splitext(file)[1] == '.php':
code,msg = commands.getstatusoutput('php -l '+file)
if code != 0:
print msg
global count
count += 1
if __name__ == '__main__':
if len(sys.argv) < 2:
print "please input the path you want check"
print "\tfor example: "+sys.argv[0]+" /home/pay"
exit(0);
print hilite('In processing, please wait!', False, True)
walk_recursive_dir(sys.argv[1], None, php_l)
if count == 0:
print hilite('\n\nCongratulations! All passed !', False, True)
else:
print hilite('\n\nSome file not pass, has '+str(count)+' failed files totally, please check!', False, True)