OLD | NEW |
(Empty) | |
| 1 # # Copyright (c) 2000-2010 LOGILAB S.A. (Paris, FRANCE). |
| 2 # http://www.logilab.fr/ -- mailto:contact@logilab.fr |
| 3 # |
| 4 # This program is free software; you can redistribute it and/or modify it under |
| 5 # the terms of the GNU General Public License as published by the Free Software |
| 6 # Foundation; either version 2 of the License, or (at your option) any later |
| 7 # version. |
| 8 # |
| 9 # This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 12 # |
| 13 # You should have received a copy of the GNU General Public License along with |
| 14 # this program; if not, write to the Free Software Foundation, Inc., |
| 15 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 16 """ |
| 17 %prog [options] <packages> |
| 18 |
| 19 create UML diagrams for classes and modules in <packages> |
| 20 """ |
| 21 |
| 22 import sys, os |
| 23 from logilab.common.configuration import ConfigurationMixIn |
| 24 from logilab.astng.manager import ASTNGManager |
| 25 from logilab.astng.inspector import Linker |
| 26 |
| 27 from pylint.pyreverse.diadefslib import DiadefsHandler |
| 28 from pylint.pyreverse import writer |
| 29 from pylint.pyreverse.utils import insert_default_options |
| 30 |
| 31 OPTIONS = ( |
| 32 ("filter-mode", |
| 33 dict(short='f', default='PUB_ONLY', dest='mode', type='string', |
| 34 action='store', metavar='<mode>', |
| 35 help="""filter attributes and functions according to |
| 36 <mode>. Correct modes are : |
| 37 'PUB_ONLY' filter all non public attributes |
| 38 [DEFAULT], equivalent to PRIVATE+SPECIAL_A |
| 39 'ALL' no filter |
| 40 'SPECIAL' filter Python special functions |
| 41 except constructor |
| 42 'OTHER' filter protected and private |
| 43 attributes""")), |
| 44 |
| 45 ("class", |
| 46 dict(short='c', action="append", metavar="<class>", dest="classes", default=[], |
| 47 help="create a class diagram with all classes related to <class>;\ |
| 48 this uses by default the options -ASmy")), |
| 49 |
| 50 ("show-ancestors", |
| 51 dict(short="a", action="store", metavar='<ancestor>', type='int', |
| 52 help='show <ancestor> generations of ancestor classes not in <projects>')), |
| 53 ("all-ancestors", |
| 54 dict(short="A", default=None, |
| 55 help="show all ancestors off all classes in <projects>") ), |
| 56 ("show-associated", |
| 57 dict(short='s', action="store", metavar='<ass_level>', type='int', |
| 58 help='show <ass_level> levels of associated classes not in <projects>')), |
| 59 ("all-associated", |
| 60 dict(short='S', default=None, |
| 61 help='show recursively all associated off all associated classes')), |
| 62 |
| 63 ("show-builtin", |
| 64 dict(short="b", action="store_true", default=False, |
| 65 help='include builtin objects in representation of classes')), |
| 66 |
| 67 ("module-names", |
| 68 dict(short="m", default=None, type='yn', metavar='[yn]', |
| 69 help='include module name in representation of classes')), |
| 70 # TODO : generate dependencies like in pylint |
| 71 #("package-dependencies", |
| 72 #dict(short="M", action="store", metavar='<package_depth>', type='int', |
| 73 #help='show <package_depth> module dependencies beyond modules in \ |
| 74 #<projects> (for the package diagram)')), |
| 75 ("only-classnames", |
| 76 dict(short='k', action="store_true", default=False, |
| 77 help="don't show attributes and methods in the class boxes; \ |
| 78 this disables -f values")), |
| 79 ("output", dict(short="o", dest="output_format", action="store", |
| 80 default="dot", metavar="<format>", |
| 81 help="create a *.<format> output file if format available.")), |
| 82 ) |
| 83 # FIXME : quiet mode |
| 84 #( ('quiet', |
| 85 #dict(help='run quietly', action='store_true', short='q')), ) |
| 86 |
| 87 class PyreverseCommand(ConfigurationMixIn): |
| 88 """base class providing common behaviour for pyreverse commands""" |
| 89 |
| 90 options = OPTIONS |
| 91 |
| 92 def __init__(self, args): |
| 93 ConfigurationMixIn.__init__(self, usage=__doc__) |
| 94 insert_default_options() |
| 95 self.manager = ASTNGManager() |
| 96 self.register_options_provider(self.manager) |
| 97 args = self.load_command_line_configuration() |
| 98 self.run(args) |
| 99 |
| 100 def run(self, args): |
| 101 """checking arguments and run project""" |
| 102 if not args: |
| 103 print self.help() |
| 104 return |
| 105 # insert current working directory to the python path to recognize |
| 106 # dependencies to local modules even if cwd is not in the PYTHONPATH |
| 107 sys.path.insert(0, os.getcwd()) |
| 108 try: |
| 109 project = self.manager.project_from_files(args) |
| 110 linker = Linker(project, tag=True) |
| 111 handler = DiadefsHandler(self.config) |
| 112 diadefs = handler.get_diadefs(project, linker) |
| 113 finally: |
| 114 sys.path.pop(0) |
| 115 |
| 116 if self.config.output_format == "vcg": |
| 117 writer.VCGWriter(self.config).write(diadefs) |
| 118 else: |
| 119 writer.DotWriter(self.config).write(diadefs) |
| 120 |
| 121 |
| 122 class Run: |
| 123 """pyreverse main class""" |
| 124 def __init__(self, args): |
| 125 """run pyreverse""" |
| 126 PyreverseCommand(args) |
| 127 |
| 128 if __name__ == '__main__': |
| 129 Run(sys.argv[1:]) |
OLD | NEW |