7
def transform_path(module_name):
8
return module_name.replace(os.sep,'.')
10
def getImportArgs(module_name):
11
dotted_path = transform_path(module_name)
12
exploded_path = dotted_path.split(".")
13
module_name = exploded_path[-1]
14
from_list = exploded_path[:-1]
15
return {"name":dotted_path,"fromlist":from_list}
17
def get_module(file_name):
18
module_name = file_name.split(".py")[0]
19
kwargs = getImportArgs(module_name)
20
#print "__import__(name = \"%(name)s\", fromlist = %(fromlist)s)" % (kwargs)
21
return __import__(kwargs["name"],fromlist=kwargs["fromlist"])
24
modules_names = [modulename.split(".py")[0] for modulename in sys.argv[1:]]
26
print "usage : %s source1.py [source2.py] ... " % sys.argv[0]
28
modules = [get_module(file_name) for file_name in sys.argv[1:]]
29
functions = map(lambda x:x[1],reduce(lambda x,y:x+y,[inspect.getmembers(module,inspect.isfunction) for module in modules]))
30
classes = map(lambda x:x[1],reduce(lambda x,y:x+y,[inspect.getmembers(module,inspect.isclass) for module in modules],[]))
31
methods = map(lambda x:x[1],reduce(lambda x,y:x+y,[inspect.getmembers(klass,inspect.ismethod) for klass in classes],[]))
32
print "your app has %s functions and methods in %s classes across %s modules" % (len(methods)+len(functions),len(classes),len(modules))
34
padding = max([len(function.func_name) for function in methods+functions])
35
for method in methods+functions :
36
lines = inspect.getsourcelines(method)
37
code_length = len(filter(lambda line:line.strip() and line.strip()[0] not in "#",inspect.getsourcelines(method)[0]))
38
if code_length > MAX_LENGTH :
39
print "warning : method %s has %s lines" % (method.func_name, code_length)
42
print method.func_name.ljust(padding),":",code_length
44
print "All your code should be readable. -max length configured is %s-" % MAX_LENGTH
45
if __name__ == "__main__":