-
Notifications
You must be signed in to change notification settings - Fork 15
/
pylint-recursive.py
60 lines (51 loc) · 1.56 KB
/
pylint-recursive.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
#! /usr/bin/env python
'''
Author: gregorynicholas (github), modified by Jacob Henderson (jacohend, github)
Module that runs pylint on all python scripts found in a directory tree..
'''
import os
#import re
import sys
passed = 0
failed = 0
errors = list()
IGNORED_FILES = ["lcd.py"]
def check(module):
global passed, failed
'''
apply pylint to the file specified if it is a *.py file
'''
module_name = module.rsplit('/', 1)[1]
if module[-3:] == ".py" and module_name not in IGNORED_FILES:
print "CHECKING ", module
pout = os.popen('pylint %s'% module, 'r')
for line in pout:
if "Your code has been rated at" in line:
print "PASSED pylint inspection: " + line
passed += 1
return True
if "-error" in line:
print "FAILED pylint inspection: " + line
failed += 1
errors.append("FILE: " + module)
errors.append("FAILED pylint inspection: " + line)
return False
if __name__ == "__main__":
try:
print sys.argv
BASE_DIRECTORY = sys.argv[1]
except IndexError:
print "no directory specified, defaulting to current working directory"
BASE_DIRECTORY = os.getcwd()
print "looking for *.py scripts in subdirectories of ", BASE_DIRECTORY
for root, dirs, files in os.walk(BASE_DIRECTORY):
for name in files:
filepath = os.path.join(root, name)
check(filepath)
print "Passed: " + str(passed) + " Failed: " + str(failed)
print "\n"
print "Showing errors:"
if failed > 0:
for err in errors:
print err
sys.exit("Pylint failed with errors")