1
0
forked from ScoDoc/ScoDoc
ScoDoc/misc/check_zope_usage.py

60 lines
1.5 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Check usage of (published) ScoDoc methods
Quick method: just grep method name in all constant strings from the source code base.
Usage:
2021-04-26 08:53:12 +02:00
check_zope_usage.py publishedmethods.csv string-constants.txt
2021-04-26 08:53:12 +02:00
publishedmethods.csv : fichier texte, module et un nom de méthode / ligne
ZScoUsers get_user_list
2021-04-26 08:53:12 +02:00
comme extrait par zopelistmethods.py
string-constants.txt : les constantes chaines, extraites par extract_code_strings.py
"scolars.py" "</li><li>"
E. Viennet 2021-01-09
"""
from __future__ import print_function
import sys
2021-04-26 08:53:12 +02:00
import glob
methods_filename = sys.argv[1]
constants_filename = sys.argv[2]
with open(methods_filename) as f:
2021-04-26 08:53:12 +02:00
# module, method_name, signature
methods = [l.strip().split("\t") for l in f]
print("%d methods" % len(methods))
with open(constants_filename) as f:
constants = [l[:-1].split("\t")[1] for l in f]
print("%d constants" % len(constants))
2021-04-26 08:53:12 +02:00
# Add JavaScripts
jss = []
for fn in glob.glob("static/js/*.js"):
jss.append(open(fn).read())
print("%d javascripts" % len(jss))
L = []
for method in methods:
n = 0
for c in constants:
2021-04-26 08:53:12 +02:00
if method[1] in c:
n += 1
2021-04-26 08:53:12 +02:00
nj = 0
for js in jss:
if method[1] in js:
nj += 1
L.append(method + [n, nj])
# Sort by decreasing popularity
L.sort(key=lambda x: (x[-1] + x[-2], x[1]), reverse=True)
print("\n".join(["%s\t%s\t%s\t%d\t%d" % tuple(l) for l in L]))