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 roslib.packages
45 import roslib.scriptutil
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 ROS communication libraries have not been built. To fix:\nrosmake ros_comm"
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 master = roslib.scriptutil.get_master()
93 try:
94 master.getPid('/roswtf')
95 return master
96 except socket.error:
97 pass
98
100 launch_files = names = None
101
102 all_pkgs = roslib.packages.list_pkgs()
103
104 import optparse
105 parser = optparse.OptionParser(usage="usage: roswtf [launch file]")
106
107 parser.add_option("--all",
108 dest="all_packages", default=False,
109 action="store_true",
110 help="run roswtf against all packages")
111
112 parser.add_option("--no-plugins",
113 dest="disable_plugins", default=False,
114 action="store_true",
115 help="disable roswtf plugins")
116
117 parser.add_option("--offline",
118 dest="offline", default=False,
119 action="store_true",
120 help="only run offline tests")
121
122
123 options, args = parser.parse_args()
124 if args:
125 launch_files = args
126 if 0:
127
128 launch_files = [a for a in args if os.path.isfile(a)]
129 names = [a for a in args if not a in launch_files]
130 names = [roslib.scriptutil.script_resolve_name('/roswtf', n) for n in names]
131
132 from roswtf.context import WtfContext
133 from roswtf.environment import wtf_check_environment, invalid_url, ros_root_check
134 from roswtf.graph import wtf_check_graph
135 import roswtf.network
136 import roswtf.packages
137 import roswtf.roslaunchwtf
138 import roswtf.stacks
139 import roswtf.plugins
140 if not options.disable_plugins:
141 static_plugins, online_plugins = roswtf.plugins.load_plugins()
142 else:
143 static_plugins, online_plugins = [], []
144
145
146 error = ros_root_check(None, ros_root=os.environ['ROS_ROOT'])
147 if error:
148 print "ROS_ROOT is invalid: "+str(error)
149 sys.exit(1)
150
151 all_warnings = []
152 all_errors = []
153
154 if launch_files:
155 ctx = WtfContext.from_roslaunch(launch_files)
156
157 else:
158 curr_package_dir, curr_package = roslib.packages.get_dir_pkg('.')
159 if curr_package:
160 print "Package:",curr_package
161 ctx = WtfContext.from_package(curr_package)
162
163 elif os.path.isfile('stack.xml'):
164 curr_stack = os.path.basename(os.path.abspath('.'))
165 print "Stack:",curr_stack
166 ctx = WtfContext.from_stack(curr_stack)
167 else:
168 print "No package or stack in context"
169 ctx = WtfContext.from_env()
170 if options.all_packages:
171 print "roswtf will run against all packages"
172 ctx.pkgs = all_pkgs
173
174
175 wtf_check_environment(ctx)
176 roswtf.network.wtf_check(ctx)
177 roswtf.packages.wtf_check(ctx)
178 roswtf.stacks.wtf_check(ctx)
179 roswtf.roslaunchwtf.wtf_check_static(ctx)
180 for p in static_plugins:
181 p(ctx)
182
183 print "="*80
184 print "Static checks summary:\n"
185 print_results(ctx)
186
187
188 all_warnings.extend(ctx.warnings)
189 all_errors.extend(ctx.errors)
190 del ctx.warnings[:]
191 del ctx.errors[:]
192
193
194 print "="*80
195
196 try:
197 online_checks = False
198 if options.offline or not ctx.ros_master_uri or invalid_url(ctx.ros_master_uri):
199 master = None
200 else:
201 master = roslib.scriptutil.get_master()
202 master = master_online()
203 if master is not None:
204 online_checks = True
205 print "Beginning tests of your ROS graph. These may take awhile..."
206
207
208 wtf_check_graph(ctx, names=names)
209 elif names:
210
211 print "\nCannot communicate with master, unable to diagnose [%s]"%(', '.join(names))
212 return
213 else:
214 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)
215 return
216
217
218 import rospy
219 rospy.init_node('roswtf', anonymous=True)
220
221 online_checks = True
222 roswtf.roslaunchwtf.wtf_check_online(ctx)
223
224 for p in online_plugins:
225 online_checks = True
226 p(ctx)
227
228 if online_checks:
229
230 print "\nOnline checks summary:\n"
231 print_results(ctx)
232
233 except roswtf.context.WtfException, e:
234 print >> sys.stderr, str(e)
235 print "\nAborting checks, partial results summary:\n"
236 print_results(ctx)
237 except Exception, e:
238 traceback.print_exc()
239 print >> sys.stderr, str(e)
240 print "\nAborting checks, partial results summary:\n"
241 print_results(ctx)
242
243
244
245