File: pylint.py

package info (click to toggle)
sqlmap 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 12,544 kB
  • sloc: python: 50,308; xml: 15,575; ansic: 989; sh: 284; makefile: 60; sql: 57; perl: 30; cpp: 27; asm: 7
file content (52 lines) | stat: -rwxr-xr-x 1,476 bytes parent folder | download
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
#! /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

from __future__ import print_function

import os
import re
import sys

total = 0.0
count = 0

__RATING__ = False

def check(module):
    global total, count

    if module[-3:] == ".py":

        print("CHECKING ", module)
        pout = os.popen("pylint --rcfile=/dev/null %s" % module, 'r')
        for line in pout:
            if re.match(r"\AE:", line):
                print(line.strip())
            if __RATING__ and "Your code has been rated at" in line:
                print(line)
                score = re.findall(r"\d.\d\d", line)[0]
                total += float(score)
                count += 1

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):
        if any(_ in root for _ in ("extra", "thirdparty")):
            continue
        for name in files:
            filepath = os.path.join(root, name)
            check(filepath)

    if __RATING__:
        print("==" * 50)
        print("%d modules found" % count)
        print("AVERAGE SCORE = %.02f" % (total / count))