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