sqlmap/extra/shutils/pylint.py

51 lines
1.4 KiB
Python
Raw Normal View History

2011-01-25 15:48:50 +03:00
#! /usr/bin/env python
# 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
2011-01-25 15:54:49 +03:00
pout = os.popen('pylint --rcfile=/dev/null %s'% module, 'r')
2011-01-25 15:48:50 +03:00
for line in pout:
if re.match("E....:.", line):
print line
2011-01-27 15:38:39 +03:00
if __RATING__ and "Your code has been rated at" in line:
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
print "%d modules found"% count
print "AVERAGE SCORE = %.02f"% (total / count)