def main(argv=sys.argv): try: options, args = parse_options(argv) if args: if options['show_screen_log']: logfile = screen.get_logfile(node=options['show_screen_log']) p = subprocess.Popen( shlex.split(' '.join( [nm.Settings.LOG_VIEWER, str(logfile)]))) p.wait() elif options['show_ros_log']: logfile = screen.get_ros_logfile(node=options['show_ros_log']) p = subprocess.Popen( shlex.split(' '.join( [nm.Settings.LOG_VIEWER, str(logfile)]))) p.wait() elif options['ros_log_path']: if options['ros_log_path'] == '[]': print nm.get_ros_home() else: print screen.get_logfile(node=options['ros_log_path']) elif options['delete_logs']: logfile = screen.get_logfile(node=options['delete_logs']) pidfile = screen.get_pidfile(node=options['delete_logs']) roslog = screen.get_ros_logfile(node=options['delete_logs']) if os.path.isfile(logfile): os.remove(logfile) if os.path.isfile(pidfile): os.remove(pidfile) if os.path.isfile(roslog): os.remove(roslog) elif options['node_type'] and options['package'] and options[ 'node_name']: runNode(options['package'], options['node_type'], options['node_name'], args, options['prefix'], options['node_respawn'], options['masteruri'], loglevel=options['loglevel']) elif options['pidkill']: import signal os.kill(int(options['pidkill']), signal.SIGKILL) elif options['package']: print roslib.packages.get_pkg_dir(options['package']) else: parser = _get_optparse() parser.print_help() time.sleep(3) except Exception, e: print >> sys.stderr, e
def runNode(package, executable, name, args, prefix='', repawn=False, masteruri=None, loglevel=''): ''' Runs a ROS node. Starts a roscore if needed. ''' if not masteruri: masteruri = masteruri_from_ros() # start roscore, if needed nm.StartHandler._prepareROSMaster(masteruri) # start node try: cmd = roslib.packages.find_node(package, executable) except roslib.packages.ROSPkgException as e: # multiple nodes, invalid package raise nm.StartException(str(e)) # handle different result types str or array of string (electric / fuerte) if isstring(cmd): cmd = [cmd] if cmd is None or len(cmd) == 0: raise nm.StartException(' '.join([executable, 'in package [', package, '] not found!\n\nThe package was created?\nIs the binary executable?\n'])) # create string for node parameter. Set arguments with spaces into "'". node_params = ' '.join(''.join(["'", a, "'"]) if a.find(' ') > -1 else a for a in args[1:]) cmd_args = [screen.get_cmd(name), RESPAWN_SCRIPT if repawn else '', prefix, cmd[0], node_params] print('run on remote host:', ' '.join(cmd_args)) # determine the current working path arg_cwd = getCwdArg('__cwd', args) cwd = nm.get_ros_home() if not (arg_cwd is None): if arg_cwd == 'ROS_HOME': cwd = nm.get_ros_home() elif arg_cwd == 'node': cwd = os.path.dirname(cmd[0]) # set the masteruri to launch with other one master new_env = dict(os.environ) new_env['ROS_MASTER_URI'] = masteruri ros_hostname = nmdhost.get_ros_hostname(masteruri) if ros_hostname: addr = socket.gethostbyname(ros_hostname) if addr in set(ip for ip in get_local_addresses()): new_env['ROS_HOSTNAME'] = ros_hostname if loglevel: new_env['ROSCONSOLE_CONFIG_FILE'] = rosconsole_cfg_file(package) subprocess.Popen(shlex.split(str(' '.join(cmd_args))), cwd=cwd, env=new_env) if len(cmd) > 1: rospy.logwarn('Multiple executables are found! The first one was started! Exceutables:\n%s', str(cmd))
def main(argv=sys.argv): try: print_help = True options, args = parse_options(argv) if options['show_screen_log']: logfile = screen.get_logfile(node=options['show_screen_log']) if not logfile: raise Exception('screen logfile not found for: %s' % options['show_screen_log']) cmd = ' '.join([nm.Settings.LOG_VIEWER, str(logfile)]) print(cmd) p = subprocess.Popen(shlex.split(cmd)) p.wait() print_help = False if options['tail_screen_log']: logfile = screen.get_logfile(node=options['tail_screen_log']) if not logfile: raise Exception('screen logfile not found for: %s' % options['tail_screen_log']) cmd = ' '.join(['tail', '-f', '-n', '25', str(logfile)]) print(cmd) p = subprocess.Popen(shlex.split(cmd)) p.wait() print_help = False elif options['show_ros_log']: logfile = screen.get_ros_logfile(node=options['show_ros_log']) if not logfile: raise Exception('ros logfile not found for: %s' % options['show_ros_log']) cmd = ' '.join([nm.Settings.LOG_VIEWER, str(logfile)]) print(cmd) p = subprocess.Popen(shlex.split(cmd)) p.wait() print_help = False elif options['ros_log_path']: if options['ros_log_path'] == '[]': print(nm.get_ros_home()) else: print(screen.get_logfile(node=options['ros_log_path'])) print_help = False elif options['delete_logs']: logfile = screen.get_logfile(node=options['delete_logs']) pidfile = screen.get_pidfile(node=options['delete_logs']) roslog = screen.get_ros_logfile(node=options['delete_logs']) if os.path.isfile(logfile): os.remove(logfile) if os.path.isfile(pidfile): os.remove(pidfile) if os.path.isfile(roslog): os.remove(roslog) print_help = False elif options['node_type'] and options['package'] and options[ 'node_name']: runNode(options['package'], options['node_type'], options['node_name'], args, options['prefix'], options['node_respawn'], options['masteruri'], loglevel=options['loglevel']) print_help = False elif options['pidkill']: import signal os.kill(int(options['pidkill']), signal.SIGKILL) print_help = False elif options['package']: print(roslib.packages.get_pkg_dir(options['package'])) print_help = False if print_help: parser = _get_optparse() parser.print_help() time.sleep(3) except Exception as e: sys.stderr.write("%s\n" % e)