sqlmap/extra/shutils/pylint.py

53 lines
1.4 KiB
Python
Raw Normal View History

2019-03-21 16:00:09 +03:00
#! /usr/bin/env python2
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
2019-01-22 03:20:27 +03:00
from __future__ import print_function
2011-01-25 15:48:50 +03:00
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":
2019-01-22 03:20:27 +03:00
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:
2017-10-31 13:38:09 +03:00
if re.match(r"\AE:", line):
2019-01-22 03:20:27 +03:00
print(line.strip())
2011-01-27 15:38:39 +03:00
if __RATING__ and "Your code has been rated at" in line:
2019-01-22 03:20:27 +03:00
print(line)
2017-10-31 13:38:09 +03:00
score = re.findall(r"\d.\d\d", line)[0]
2013-01-10 16:18:44 +04:00
total += float(score)
count += 1
2011-01-25 15:48:50 +03:00
if __name__ == "__main__":
try:
2019-01-22 03:20:27 +03:00
print(sys.argv)
2011-01-25 15:48:50 +03:00
BASE_DIRECTORY = sys.argv[1]
except IndexError:
2019-01-22 03:20:27 +03:00
print("no directory specified, defaulting to current working directory")
2011-01-25 15:48:50 +03:00
BASE_DIRECTORY = os.getcwd()
2019-01-22 03:20:27 +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__:
2019-01-22 03:20:27 +03:00
print("==" * 50)
print("%d modules found" % count)
print("AVERAGE SCORE = %.02f" % (total / count))