def delete_log(cls, nodename, grpc_uri, auto_pw_request=False, user=None, pw=None):
        '''
        Deletes the log file associated with the given node.

        :param  str nodename: the name of the node (with name space)
        :param str grpc_uri: uri of the node manager daemon where to delete log
        :raise Exception: on errors while resolving host
        :see: :meth:`fkie_node_manager.is_local()`
        '''
        try:
            nm.nmd().screen.delete_log(grpc_uri, [nodename])
        except Exception as err:
            rospy.logwarn("delete log using SSH because of error: %s" % utf8(err))
            host = get_hostname(grpc_uri)
            if nm.is_local(host):
                screenLog = screen.get_logfile(node=nodename)
                pidFile = screen.get_pidfile(node=nodename)
                roslog = screen.get_ros_logfile(nodename)
                if os.path.isfile(screenLog):
                    os.remove(screenLog)
                if os.path.isfile(pidFile):
                    os.remove(pidFile)
                if os.path.isfile(roslog):
                    os.remove(roslog)
            else:
                try:
                    # output ignored: output, error, ok
                    _, stdout, _, ok = nm.ssh().ssh_exec(host, [nm.settings().start_remote_script, '--delete_logs', nodename], user, pw, auto_pw_request, close_stdin=True, close_stdout=False, close_stderr=True)
                    if ok:
                        stdout.readlines()
                        stdout.close()
                except nm.AuthenticationRequest as e:
                    raise nm.InteractionNeededError(e, cls.delete_log, {'nodename': nodename, 'grpc_uri': host, 'auto_pw_request': auto_pw_request, 'user': user, 'pw': pw})
Ejemplo n.º 2
0
def main(argv=sys.argv):
    try:
        options, args = parse_options(argv)
        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()
        if options['tail_screen_log']:
            logfile = screen.get_logfile(node=options['tail_screen_log'])
            p = subprocess.Popen(
                shlex.split(' '.join(['tail', '-f', '-n', '25',
                                      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 as e:
        sys.stderr.write("%s\n" % e)