gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / pylint / pyreverse / main.py @ 745
History | View | Annotate | Download (6.07 KB)
1 |
# # Copyright (c) 2000-2013 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 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
16 |
"""
|
17 |
%prog [options] <packages>
|
18 |
|
19 |
create UML diagrams for classes and modules in <packages>
|
20 |
"""
|
21 |
from __future__ import print_function |
22 |
|
23 |
import os |
24 |
import subprocess |
25 |
import sys |
26 |
|
27 |
from pylint.config import ConfigurationMixIn |
28 |
from pylint.pyreverse.inspector import Linker, project_from_files |
29 |
from pylint.pyreverse.diadefslib import DiadefsHandler |
30 |
from pylint.pyreverse import writer |
31 |
from pylint.pyreverse.utils import insert_default_options |
32 |
|
33 |
OPTIONS = ( |
34 |
("filter-mode",
|
35 |
dict(short='f', default='PUB_ONLY', dest='mode', type='string', |
36 |
action='store', metavar='<mode>', |
37 |
help="""filter attributes and functions according to
|
38 |
<mode>. Correct modes are :
|
39 |
'PUB_ONLY' filter all non public attributes
|
40 |
[DEFAULT], equivalent to PRIVATE+SPECIAL_A
|
41 |
'ALL' no filter
|
42 |
'SPECIAL' filter Python special functions
|
43 |
except constructor
|
44 |
'OTHER' filter protected and private
|
45 |
attributes""")),
|
46 |
|
47 |
("class",
|
48 |
dict(short='c', action="append", metavar="<class>", dest="classes", default=[], |
49 |
help="create a class diagram with all classes related to <class>;\
|
50 |
this uses by default the options -ASmy")),
|
51 |
|
52 |
("show-ancestors",
|
53 |
dict(short="a", action="store", metavar='<ancestor>', type='int', |
54 |
help='show <ancestor> generations of ancestor classes not in <projects>')),
|
55 |
("all-ancestors",
|
56 |
dict(short="A", default=None, |
57 |
help="show all ancestors off all classes in <projects>")),
|
58 |
("show-associated",
|
59 |
dict(short='s', action="store", metavar='<ass_level>', type='int', |
60 |
help='show <ass_level> levels of associated classes not in <projects>')),
|
61 |
("all-associated",
|
62 |
dict(short='S', default=None, |
63 |
help='show recursively all associated off all associated classes')),
|
64 |
("show-builtin",
|
65 |
dict(short="b", action="store_true", default=False, |
66 |
help='include builtin objects in representation of classes')),
|
67 |
|
68 |
("module-names",
|
69 |
dict(short="m", default=None, type='yn', metavar='[yn]', |
70 |
help='include module name in representation of classes')),
|
71 |
# TODO : generate dependencies like in pylint
|
72 |
# ("package-dependencies",
|
73 |
# dict(short="M", action="store", metavar='<package_depth>', type='int',
|
74 |
# help='show <package_depth> module dependencies beyond modules in \
|
75 |
# <projects> (for the package diagram)')),
|
76 |
("only-classnames",
|
77 |
dict(short='k', action="store_true", default=False, |
78 |
help="don't show attributes and methods in the class boxes; \
|
79 |
this disables -f values")),
|
80 |
("output", dict(short="o", dest="output_format", action="store", |
81 |
default="dot", metavar="<format>", |
82 |
help="create a *.<format> output file if format available.")),
|
83 |
("ignore", {'type' : "csv", 'metavar' : "<file>", |
84 |
'dest' : "black_list", "default" : ('CVS',), |
85 |
'help' : "add <file> (may be a directory) to the black list. " |
86 |
"It should be a base name, not a path. You may set "
|
87 |
"this option multiple times."}),
|
88 |
("project", {'default': "No Name", 'type' : 'string', 'short': 'p', |
89 |
'metavar': '<project name>', 'help': 'set the project name.'}), |
90 |
) |
91 |
# FIXME : quiet mode
|
92 |
#( ('quiet',
|
93 |
#dict(help='run quietly', action='store_true', short='q')), )
|
94 |
|
95 |
def _check_graphviz_available(output_format): |
96 |
"""check if we need graphviz for different output format"""
|
97 |
try:
|
98 |
subprocess.call(['dot', '-V'], stdout=subprocess.PIPE, |
99 |
stderr=subprocess.PIPE) |
100 |
except OSError: |
101 |
print("The output format '%s' is currently not available.\n"
|
102 |
"Please install 'Graphviz' to have other output formats "
|
103 |
"than 'dot' or 'vcg'." % output_format)
|
104 |
sys.exit(32)
|
105 |
|
106 |
|
107 |
|
108 |
class Run(ConfigurationMixIn): |
109 |
"""base class providing common behaviour for pyreverse commands"""
|
110 |
|
111 |
options = OPTIONS |
112 |
|
113 |
def __init__(self, args): |
114 |
ConfigurationMixIn.__init__(self, usage=__doc__)
|
115 |
insert_default_options() |
116 |
args = self.load_command_line_configuration()
|
117 |
if self.config.output_format not in ('dot', 'vcg'): |
118 |
_check_graphviz_available(self.config.output_format)
|
119 |
|
120 |
sys.exit(self.run(args))
|
121 |
|
122 |
def run(self, args): |
123 |
"""checking arguments and run project"""
|
124 |
if not args: |
125 |
print(self.help())
|
126 |
return 1 |
127 |
# insert current working directory to the python path to recognize
|
128 |
# dependencies to local modules even if cwd is not in the PYTHONPATH
|
129 |
sys.path.insert(0, os.getcwd())
|
130 |
try:
|
131 |
project = project_from_files(args, project_name=self.config.project,
|
132 |
black_list=self.config.black_list)
|
133 |
linker = Linker(project, tag=True)
|
134 |
handler = DiadefsHandler(self.config)
|
135 |
diadefs = handler.get_diadefs(project, linker) |
136 |
finally:
|
137 |
sys.path.pop(0)
|
138 |
|
139 |
if self.config.output_format == "vcg": |
140 |
writer.VCGWriter(self.config).write(diadefs)
|
141 |
else:
|
142 |
writer.DotWriter(self.config).write(diadefs)
|
143 |
return 0 |
144 |
|
145 |
|
146 |
if __name__ == '__main__': |
147 |
Run(sys.argv[1:])
|