2013-02-14 15:32:17 +04:00
|
|
|
#! /usr/bin/env python
|
2011-01-25 15:48:50 +03:00
|
|
|
|
|
|
|
# Runs pylint on all python scripts found in a directory tree
|
|
|
|
# Reference: http://rowinggolfer.blogspot.com/2009/08/pylint-recursively.html
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
total = 0.0
|
|
|
|
count = 0
|
|
|
|
|
2011-01-27 15:38:39 +03:00
|
|
|
__RATING__ = False
|
|
|
|
|
2011-01-25 15:48:50 +03:00
|
|
|
def check(module):
|
|
|
|
global total, count
|
|
|
|
|
|
|
|
if module[-3:] == ".py":
|
|
|
|
|
|
|
|
print "CHECKING ", module
|
2013-01-10 16:18:44 +04:00
|
|
|
pout = os.popen("pylint --rcfile=/dev/null %s" % module, 'r')
|
2011-01-25 15:48:50 +03:00
|
|
|
for line in pout:
|
2016-11-09 14:18:15 +03:00
|
|
|
if re.match("\AE:", line):
|
|
|
|
print line.strip()
|
2011-01-27 15:38:39 +03:00
|
|
|
if __RATING__ and "Your code has been rated at" in line:
|
2013-01-10 16:18:44 +04:00
|
|
|
print line
|
|
|
|
score = re.findall("\d.\d\d", line)[0]
|
|
|
|
total += float(score)
|
|
|
|
count += 1
|
2011-01-25 15:48:50 +03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try:
|
2011-01-27 15:38:39 +03:00
|
|
|
print sys.argv
|
2011-01-25 15:48:50 +03:00
|
|
|
BASE_DIRECTORY = sys.argv[1]
|
|
|
|
except IndexError:
|
|
|
|
print "no directory specified, defaulting to current working directory"
|
|
|
|
BASE_DIRECTORY = os.getcwd()
|
|
|
|
|
2011-01-25 15:54:49 +03:00
|
|
|
print "looking for *.py scripts in subdirectories of ", BASE_DIRECTORY
|
2011-01-25 15:48:50 +03:00
|
|
|
for root, dirs, files in os.walk(BASE_DIRECTORY):
|
2012-12-03 20:43:39 +04:00
|
|
|
if any(_ in root for _ in ("extra", "thirdparty")):
|
|
|
|
continue
|
2011-01-25 15:48:50 +03:00
|
|
|
for name in files:
|
|
|
|
filepath = os.path.join(root, name)
|
|
|
|
check(filepath)
|
|
|
|
|
2011-01-27 15:38:39 +03:00
|
|
|
if __RATING__:
|
|
|
|
print "==" * 50
|
2013-01-10 16:18:44 +04:00
|
|
|
print "%d modules found" % count
|
|
|
|
print "AVERAGE SCORE = %.02f" % (total / count)
|