1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 """
36 roswtf command-line tool.
37 """
38
39 import os
40 import socket
41 import sys
42 import traceback
43
44 import rospkg
45 import rosgraph.names
46
48 cd = ctx.as_dictionary()
49 d = {}
50 d['warnings'] = {}
51 d['errors'] = {}
52 wd = d['warnings']
53 for warn in ctx.warnings:
54 wd[warn.format_msg%cd] = warn.return_val
55 ed = d['warnings']
56 for err in ctx.warnings:
57 ed[err.format_msg%cd] = err.return_val
58 import yaml
59 print yaml.dump(d)
60
62 if not ctx.warnings and not ctx.errors:
63 print "No errors or warnings"
64 else:
65 if ctx.warnings:
66 print "Found %s warning(s).\nWarnings are things that may be just fine, but are sometimes at fault\n"%len(ctx.warnings)
67 for warn in ctx.warnings:
68 print '\033[1mWARNING\033[0m', warn.msg
69 print ''
70
71 if ctx.errors:
72 print "Found %s error(s).\n"%len(ctx.errors)
73 for e in ctx.errors:
74 print '\033[31m\033[1mERROR\033[0m', e.msg
75
76
78 try:
79 import std_msgs.msg
80 import rosgraph_msgs.msg
81 except ImportError:
82 print "ERROR: The core ROS message libraries (std_msgs and rosgraph_msgs) have not been built."
83 sys.exit(1)
84
85 from roswtf.context import WtfException
86 try:
87 _roswtf_main()
88 except WtfException, e:
89 print >> sys.stderr, e
90
92 launch_files = names = None
93
94 rospack = rospkg.RosPack()
95 all_pkgs = rospack.list()
96
97 import optparse
98 parser = optparse.OptionParser(usage="usage: roswtf [launch file]", description="roswtf is a tool for verifying a ROS installation and running system. Checks provided launchfile if provided, else current stack or package.")
99
100 parser.add_option("--all",
101 dest="all_packages", default=False,
102 action="store_true",
103 help="run roswtf against all packages")
104
105 parser.add_option("--no-plugins",
106 dest="disable_plugins", default=False,
107 action="store_true",
108 help="disable roswtf plugins")
109
110 parser.add_option("--offline",
111 dest="offline", default=False,
112 action="store_true",
113 help="only run offline tests")
114
115
116 options, args = parser.parse_args()
117 if args:
118 launch_files = args
119 if 0:
120
121 launch_files = [a for a in args if os.path.isfile(a)]
122 names = [a for a in args if not a in launch_files]
123 names = [rosgraph.names.script_resolve_name('/roswtf', n) for n in names]
124
125 from roswtf.context import WtfContext
126 from roswtf.environment import wtf_check_environment, invalid_url, ros_root_check
127 from roswtf.graph import wtf_check_graph
128 import roswtf.rosdep_db
129 import roswtf.py_pip_deb_checks
130 import roswtf.network
131 import roswtf.packages
132 import roswtf.roslaunchwtf
133 import roswtf.stacks
134 import roswtf.plugins
135 if not options.disable_plugins:
136 static_plugins, online_plugins = roswtf.plugins.load_plugins()
137 else:
138 static_plugins, online_plugins = [], []
139
140
141 error = ros_root_check(None, ros_root=os.environ['ROS_ROOT'])
142 if error:
143 print "ROS_ROOT is invalid: "+str(error)
144 sys.exit(1)
145
146 all_warnings = []
147 all_errors = []
148
149 if launch_files:
150 ctx = WtfContext.from_roslaunch(launch_files)
151
152 else:
153 curr_package = rospkg.get_package_name('.')
154 if curr_package:
155 print "Package:",curr_package
156 ctx = WtfContext.from_package(curr_package)
157
158 elif os.path.isfile('stack.xml'):
159 curr_stack = os.path.basename(os.path.abspath('.'))
160 print "Stack:",curr_stack
161 ctx = WtfContext.from_stack(curr_stack)
162 else:
163 print "No package or stack in context"
164 ctx = WtfContext.from_env()
165 if options.all_packages:
166 print "roswtf will run against all packages"
167 ctx.pkgs = all_pkgs
168
169
170 wtf_check_environment(ctx)
171 roswtf.rosdep_db.wtf_check(ctx)
172 roswtf.py_pip_deb_checks.wtf_check(ctx)
173 roswtf.network.wtf_check(ctx)
174 roswtf.packages.wtf_check(ctx)
175 roswtf.stacks.wtf_check(ctx)
176 roswtf.roslaunchwtf.wtf_check_static(ctx)
177 for p in static_plugins:
178 p(ctx)
179
180 print "="*80
181 print "Static checks summary:\n"
182 print_results(ctx)
183
184
185 all_warnings.extend(ctx.warnings)
186 all_errors.extend(ctx.errors)
187 del ctx.warnings[:]
188 del ctx.errors[:]
189
190
191 print "="*80
192
193 try:
194
195 if options.offline or not ctx.ros_master_uri or invalid_url(ctx.ros_master_uri) or not rosgraph.is_master_online():
196 online_checks = False
197 else:
198 online_checks = True
199 if online_checks:
200 online_checks = True
201 print "Beginning tests of your ROS graph. These may take awhile..."
202
203
204 wtf_check_graph(ctx, names=names)
205 elif names:
206
207 print "\nCannot communicate with master, unable to diagnose [%s]"%(', '.join(names))
208 return
209 else:
210 print "\nROS Master does not appear to be running.\nOnline graph checks will not be run.\nROS_MASTER_URI is [%s]"%(ctx.ros_master_uri)
211 return
212
213
214 import rospy
215 rospy.init_node('roswtf', anonymous=True)
216
217 online_checks = True
218 roswtf.roslaunchwtf.wtf_check_online(ctx)
219
220 for p in online_plugins:
221 online_checks = True
222 p(ctx)
223
224 if online_checks:
225
226 print "\nOnline checks summary:\n"
227 print_results(ctx)
228
229 except roswtf.context.WtfException, e:
230 print >> sys.stderr, str(e)
231 print "\nAborting checks, partial results summary:\n"
232 print_results(ctx)
233 except Exception, e:
234 traceback.print_exc()
235 print >> sys.stderr, str(e)
236 print "\nAborting checks, partial results summary:\n"
237 print_results(ctx)
238
239
240
241