Ejemplo n.º 1
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)
Ejemplo n.º 2
0
 def _connect(self, masteruri, screen_name, nodename, user=None):
     self._masteruri = masteruri
     if self.qfile is not None and self.qfile.isOpen():
         self.qfile.close()
         self.clear_signal.emit()
     host = get_hostname(masteruri)
     if nm.is_local(host):
         self._nodename = nodename
         if screen_name:
             screen_log = screen.get_logfile(node=nodename)
         else:
             screen_log = screen.get_ros_logfile(node=nodename)
         self.qfile = QFile(screen_log)
         self.setWindowTitle(nodename)
         if self.qfile.open(QIODevice.ReadOnly):
             self._first_fill = True
             self.qfile.seek(self.qfile.size() - 1)
             # self.lread()
             self._info = "END"
             self.thread = threading.Thread(target=self._read_log,
                                            kwargs={"filename": screen_log})
             self.thread.setDaemon(True)
             self.thread.start()
         else:
             self._valid = False
     else:
         self._connect_ssh(host, nodename, user)
     self.logger_handler = LoggerHandler(
         nodename,
         masteruri=masteruri,
         layout=self.scrollAreaWidgetContents.layout())
     self.logger_handler.update()
     return False
    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.º 4
0
    def openLog(cls, nodename, host, user=None, only_screen=False):
        '''
        Opens the log file associated with the given node in a new terminal.

        :param str nodename: the name of the node (with name space)
        :param str host: the host name or ip where the log file are
        :return: True, if a log file was found
        :rtype: bool
        :raise Exception: on errors while resolving host
        :see: :meth:`fkie_node_manager.is_local()`
        '''
        rospy.loginfo("show log for '%s' on '%s'", utf8(nodename), utf8(host))
        title_opt = 'LOG %s on %s' % (nodename, host)
        if nm.is_local(host):
            found = False
            screenLog = screen.get_logfile(node=nodename)
            if os.path.isfile(screenLog):
                cmd = nm.settings().terminal_cmd(
                    [nm.settings().log_viewer, screenLog], title_opt)
                rospy.loginfo("open log: %s", cmd)
                SupervisedPopen(shlex.split(cmd),
                                object_id="Open log",
                                description="Open log for '%s' on '%s'" %
                                (utf8(nodename), utf8(host)))
                found = True
            # open roslog file
            roslog = screen.get_ros_logfile(nodename)
            if os.path.isfile(roslog) and not only_screen:
                title_opt = title_opt.replace('LOG', 'ROSLOG')
                cmd = nm.settings().terminal_cmd(
                    [nm.settings().log_viewer, roslog], title_opt)
                rospy.loginfo("open ROS log: %s", cmd)
                SupervisedPopen(shlex.split(cmd),
                                object_id="Open log",
                                description="Open log for '%s' on '%s'" %
                                (utf8(nodename), utf8(host)))
                found = True
            return found
        else:
            _ps = nm.ssh().ssh_x11_exec(host, [
                nm.settings().start_remote_script, '--show_screen_log',
                nodename
            ], title_opt, user)
            if not only_screen:
                _ps = nm.ssh().ssh_x11_exec(host, [
                    nm.settings().start_remote_script, '--show_ros_log',
                    nodename
                ], title_opt.replace('LOG', 'ROSLOG'), user)
        return False