2020-04-25 00:56:12 +08:00
|
|
|
#!/usr/bin/env python3
|
2020-05-03 03:07:34 +08:00
|
|
|
import os
|
2020-04-25 00:56:12 +08:00
|
|
|
import ast
|
|
|
|
import stat
|
|
|
|
import subprocess
|
|
|
|
|
2021-12-04 14:57:19 +08:00
|
|
|
fouts = {x.decode('utf-8') for x in subprocess.check_output(['git', 'ls-files']).strip().split()}
|
2020-04-25 00:56:12 +08:00
|
|
|
|
|
|
|
pyf = []
|
|
|
|
for d in ["cereal", "common", "scripts", "selfdrive", "tools"]:
|
2023-08-12 06:33:49 +08:00
|
|
|
for root, _, files in os.walk(d):
|
2020-04-25 00:56:12 +08:00
|
|
|
for f in files:
|
|
|
|
if f.endswith(".py"):
|
|
|
|
pyf.append(os.path.join(root, f))
|
|
|
|
|
2023-11-19 14:47:11 +08:00
|
|
|
imps: set[str] = set()
|
2020-04-25 00:56:12 +08:00
|
|
|
|
|
|
|
class Analyzer(ast.NodeVisitor):
|
|
|
|
def visit_Import(self, node):
|
|
|
|
for alias in node.names:
|
|
|
|
imps.add(alias.name)
|
|
|
|
self.generic_visit(node)
|
2020-05-31 11:14:58 +08:00
|
|
|
|
2020-04-25 00:56:12 +08:00
|
|
|
def visit_ImportFrom(self, node):
|
|
|
|
imps.add(node.module)
|
|
|
|
self.generic_visit(node)
|
|
|
|
|
|
|
|
tlns = 0
|
2020-08-23 05:48:01 +08:00
|
|
|
carlns = 0
|
|
|
|
scriptlns = 0
|
|
|
|
testlns = 0
|
2020-04-25 00:56:12 +08:00
|
|
|
for f in sorted(pyf):
|
|
|
|
if f not in fouts:
|
|
|
|
continue
|
|
|
|
xbit = bool(os.stat(f)[stat.ST_MODE] & stat.S_IXUSR)
|
|
|
|
src = open(f).read()
|
|
|
|
lns = len(src.split("\n"))
|
|
|
|
tree = ast.parse(src)
|
|
|
|
Analyzer().visit(tree)
|
|
|
|
print("%5d %s %s" % (lns, f, xbit))
|
2020-08-23 05:48:01 +08:00
|
|
|
if 'test' in f:
|
|
|
|
testlns += lns
|
2023-08-11 06:28:51 +08:00
|
|
|
elif f.startswith(('tools/', 'scripts/', 'selfdrive/debug')):
|
2020-08-23 05:48:01 +08:00
|
|
|
scriptlns += lns
|
|
|
|
elif f.startswith('selfdrive/car'):
|
|
|
|
carlns += lns
|
|
|
|
else:
|
|
|
|
tlns += lns
|
2020-04-25 00:56:12 +08:00
|
|
|
|
2020-08-23 05:48:01 +08:00
|
|
|
print("%d lines of openpilot python" % tlns)
|
|
|
|
print("%d lines of car ports" % carlns)
|
|
|
|
print("%d lines of tools/scripts/debug" % scriptlns)
|
|
|
|
print("%d lines of tests" % testlns)
|
2020-04-25 00:56:12 +08:00
|
|
|
#print(sorted(list(imps)))
|