From 9ba20fa21a9b966695199ae4e822d2421dbb4300 Mon Sep 17 00:00:00 2001 From: George Hotz Date: Fri, 24 Apr 2020 09:56:12 -0700 Subject: [PATCH] add code stats --- scripts/code_stats.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 scripts/code_stats.py diff --git a/scripts/code_stats.py b/scripts/code_stats.py new file mode 100755 index 0000000000..0fc3462102 --- /dev/null +++ b/scripts/code_stats.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +import os, glob +import ast +import stat +import subprocess + +fouts = set([x.decode('utf-8') for x in subprocess.check_output(['git', 'ls-files']).strip().split()]) + +pyf = [] +for d in ["cereal", "common", "scripts", "selfdrive", "tools"]: + for root, dirs, files in os.walk(d): + for f in files: + if f.endswith(".py"): + pyf.append(os.path.join(root, f)) + +imps = set() + +class Analyzer(ast.NodeVisitor): + def visit_Import(self, node): + for alias in node.names: + imps.add(alias.name) + self.generic_visit(node) + def visit_ImportFrom(self, node): + imps.add(node.module) + self.generic_visit(node) + +tlns = 0 +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)) + tlns += lns + +print("%d lines of parsed openpilot python" % tlns) +#print(sorted(list(imps))) +