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