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

70 lines
1.9 KiB
Python
Raw Normal View History

2020-09-26 16:19:37 +02:00
# -*- mode: python -*-
# -*- coding: utf-8 -*-
"""List Zope published methods (helps redesign ScoDoc's API).
2021-01-10 11:43:17 +01:00
Usage:
scotests/scointeractive.sh RT misc/zopelistmethods.py
2020-09-26 16:19:37 +02:00
2021-01-10 11:43:17 +01:00
(replace RT by an existing departement id)
2020-09-26 16:19:37 +02:00
E. Viennet 2020-01-26
"""
from __future__ import print_function
from types import FunctionType, MethodType
from pprint import pprint as pp
import inspect
from ZScoDoc import ZScoDoc
from ZScolar import ZScolar
from ZNotes import ZNotes
from ZAbsences import ZAbsences
from ZScoUsers import ZScoUsers
from ZEntreprises import ZEntreprises
2021-01-10 11:43:17 +01:00
RESFILENAME = "publishedmethods.csv"
2020-09-26 16:19:37 +02:00
def get_methods_description(klass):
D = klass.__dict__
M = []
for method_name in D:
o = D[method_name]
if method_name[0] != "_" and type(o) == FunctionType and o.__doc__:
argspec = inspect.getargspec(D[method_name])
defaults = argspec.defaults or []
if defaults:
args = argspec.args[: -len(defaults)]
else:
args = argspec.args
for a in defaults:
args.append("%s=%s" % (argspec.args[len(args)], repr(a)))
M.append((method_name, ", ".join(args)))
M.sort()
return M
published_by_module = {}
lines = []
for klass in ZScoDoc, ZScolar, ZNotes, ZAbsences, ZEntreprises, ZScoUsers:
module_name = klass.__name__
published_by_module[module_name] = []
M = get_methods_description(klass)
for m in M:
published_by_module[module_name].append(m)
lines.append((module_name, m[0], m[1]))
print("%s = %d published methods" % (module_name, len(M)))
print("---\nModule \t #methods")
N = 0
for module_name in published_by_module:
n = len(published_by_module[module_name])
print(module_name, "\t", n)
N += n
print("Total: \t ", N)
2021-01-10 11:43:17 +01:00
print("Writing %s" % RESFILENAME)
with open(RESFILENAME, "w") as f:
f.write("\n".join(["\t".join(l) for l in lines]))