class browser for python ??
Scherer, Bill
Bill.Scherer at VerizonWireless.com
Thu Oct 18 08:44:16 EDT 2001
On Wed, 17 Oct 2001, Markus Jais wrote:
> hello,
> is there a tool out there, which can show me the class
> structure of a python module
> something like a class browser would be needed
> or a tool that can generate UML diagramms from python sources
>
> any hints are welcome
Here's some code that uses GraphViz
(http://www.research.att.com/sw/tools/graphviz) to create a
uml-ish class hierachy diagram of a module. It's a bit weak, but
not so bad for a quick hack.
usage: pyviz <module_name_without_extension>
It will write out the dot file, call dot to create a png, then
launch ee to view the png. This is all set to work on Linux...
Enjoy.
Note also that there is Object Domain, a UML case tool that
supports Python, including reverse engineering.
(http://www.objectdomain.com)
--
Bill.Scherer at Verizon Wireless
RHCE 807101044903581
########## begin pyviz ###########
#! /usr/local/bin/python
import sys, os, types
sys.path.append(os.getcwd())
moduleName = sys.argv[1]
exec "import %s" % moduleName
module = eval(moduleName)
classes = []
for each in dir(module):
thing = eval("module.%s" % each)
if type(thing) == types.ClassType:
classes.append(thing)
sys.stdout = open("./%s.dot" % moduleName, 'w')
def printBases(klass):
if klass.__bases__:
for base in klass.__bases__:
print '\t', klass.__name__, '->',
print base.__name__, ';'
else:
pass
#print klass.__name__
print 'digraph pyviz{'
print 'size = "8,10";'
print 'ratio = fill;'
print 'margin = 1;'
print 'center = 1;'
print 'bgcolor=white;'
print 'edge [color=blue,arrowhead=normal,arrowsize=1.5];'
print 'rankdir=LR;'
for each in classes:
print each.__name__, '[shape=box];'
for each in classes:
printBases(each)
print '}'
sys.stdout.close()
sys.stdout = sys.__stdout__
os.system("dot -Tpng -o%s.png %s.dot" % (moduleName, moduleName))
os.system("ee %s.png" % moduleName)
More information about the Python-list
mailing list