70 lines
1.9 KiB
Python
70 lines
1.9 KiB
Python
# -*- mode: python -*-
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""List Zope published methods (helps redesign ScoDoc's API).
|
|
|
|
Usage:
|
|
scotests/scointeractive.sh RT misc/zopelistmethods.py
|
|
|
|
(replace RT by an existing departement id)
|
|
|
|
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
|
|
|
|
RESFILENAME = "publishedmethods.csv"
|
|
|
|
|
|
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)
|
|
|
|
print("Writing %s" % RESFILENAME)
|
|
with open(RESFILENAME, "w") as f:
|
|
f.write("\n".join(["\t".join(l) for l in lines]))
|