# # Copyright (c) 2000-2008 LOGILAB S.A. (Paris, FRANCE). # http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your option) any later # version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. """ %prog [options] create UML diagrams for classes and modules in """ import sys from logilab.common.configuration import ConfigurationMixIn from logilab.astng.manager import astng_wrapper, ASTNGManager from logilab.astng.inspector import Linker from pylint.pyreverse.diadefslib import DiadefsHandler from pylint.pyreverse import writer from pylint.pyreverse.utils import insert_default_options OPTIONS = ( ("filter-mode", dict(short='f', default='PUB_ONLY', dest='mode', type='string', action='store', metavar='', help="""filter attributes and functions according to . Correct modes are : 'PUB_ONLY' filter all non public attributes [DEFAULT], equivalent to PRIVATE+SPECIAL_A 'ALL' no filter 'SPECIAL' filter Python special functions except constructor 'OTHER' filter protected and private attributes""")), ("class", dict(short='c', action="append", metavar="", dest="classes", default=[], help="create a class diagram with all classes related to ;\ this uses by default the options -ASmy")), ("show-ancestors", dict(short="a", action="store", metavar='', type='int', help='show generations of ancestor classes not in ')), ("all-ancestors", dict(short="A", default=None, help="show all ancestors off all classes in ") ), ("show-associated", dict(short='s', action="store", metavar='', type='int', help='show levels of associated classes not in ')), ("all-associated", dict(short='S', default=None, help='show recursively all associated off all associated classes')), ("show-builtin", dict(short="b", action="store_true", default=False, help='include builtin objects in representation of classes')), ("module-names", dict(short="m", default=None, type='yn', metavar='[yn]', help='include module name in representation of classes')), # TODO : generate dependencies like in pylint #("package-dependencies", #dict(short="M", action="store", metavar='', type='int', #help='show module dependencies beyond modules in \ # (for the package diagram)')), ("only-classnames", dict(short='k', action="store_true", default=False, help="don't show attributes and methods in the class boxes; \ this disables -f values")), ("output", dict(short="o", dest="output_format", action="store", default="dot", metavar="", help="create a *. output file if format available.")), ) # FIXME : quiet mode #( ('quiet', #dict(help='run quietly', action='store_true', short='q')), ) class PyreverseCommand(ConfigurationMixIn): """base class providing common behaviour for pyreverse commands""" options = OPTIONS def __init__(self, args): ConfigurationMixIn.__init__(self, usage=__doc__) insert_default_options() self.manager = ASTNGManager() self.register_options_provider(self.manager) args = self.load_command_line_configuration() self.run(args) def run(self, args): """checking argmuents and run project""" if not args: print self.help() return project = self.manager.project_from_files(args, astng_wrapper) linker = Linker(project, tag=True) handler = DiadefsHandler(self.config) diadefs = handler.get_diadefs(project, linker) if self.config.output_format == "vcg": writer.VCGWriter(self.config).write(diadefs) else: writer.DotWriter(self.config).write(diadefs) class Run: """pyreverse main class""" def __init__(self, args): """run pyreverse""" PyreverseCommand(args) if __name__ == '__main__': Run(sys.argv[1:])