Package roswtf
[frames] | no frames]

Source Code for Package roswtf

  1  # Software License Agreement (BSD License) 
  2  # 
  3  # Copyright (c) 2009, Willow Garage, Inc. 
  4  # All rights reserved. 
  5  # 
  6  # Redistribution and use in source and binary forms, with or without 
  7  # modification, are permitted provided that the following conditions 
  8  # are met: 
  9  # 
 10  #  * Redistributions of source code must retain the above copyright 
 11  #    notice, this list of conditions and the following disclaimer. 
 12  #  * Redistributions in binary form must reproduce the above 
 13  #    copyright notice, this list of conditions and the following 
 14  #    disclaimer in the documentation and/or other materials provided 
 15  #    with the distribution. 
 16  #  * Neither the name of Willow Garage, Inc. nor the names of its 
 17  #    contributors may be used to endorse or promote products derived 
 18  #    from this software without specific prior written permission. 
 19  # 
 20  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 21  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 22  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 23  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 24  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 25  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 26  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 27  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 28  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 29  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 30  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  # POSSIBILITY OF SUCH DAMAGE. 
 32  # 
 33  # Revision $Id$ 
 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       
47 -def yaml_results(ctx):
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 75 #print "ERROR:", e.msg 76
77 -def roswtf_main():
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
91 -def _roswtf_main():
92 launch_files = names = None 93 # performance optimization 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 # #2268 100 parser.add_option("--all", 101 dest="all_packages", default=False, 102 action="store_true", 103 help="run roswtf against all packages") 104 # #2270 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 #TODO: --all-pkgs option 116 options, args = parser.parse_args() 117 if args: 118 launch_files = args 119 if 0: 120 # disable names for now as don't have any rules yet 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 # - do a ros_root check first and abort if it fails as rest of tests are useless after that 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 #TODO: allow specifying multiple roslaunch files 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 #TODO: load all .launch files in package 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 # static checks 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 # Save static results and start afresh for online checks 185 all_warnings.extend(ctx.warnings) 186 all_errors.extend(ctx.errors) 187 del ctx.warnings[:] 188 del ctx.errors[:] 189 190 # test online 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 # online checks 204 wtf_check_graph(ctx, names=names) 205 elif names: 206 # TODO: need to rework this logic 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 # spin up a roswtf node so we can subscribe to messages 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 # done 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 #TODO: print results in YAML if run remotely 240 #yaml_results(ctx) 241