def openLog(cls, nodename, host): ''' Opens the log file associated with the given node in a new terminal. @param nodename: the name of the node (with name space) @type nodename: C{str} @param host: the host name or ip where the log file are @type host: C{str} @return: C{True}, if a log file was found @rtype: C{bool} @raise Exception: on errors while resolving host @see: L{node_manager_fkie.is_local()} ''' title_opt = ' '.join(['"LOG', nodename, 'on', host, '"']) if nm.is_local(host): found = False screenLog = nm.screen().getScreenLogFile(node=nodename) if os.path.isfile(screenLog): cmd = nm.terminal_cmd([nm.LESS, screenLog], title_opt) rospy.loginfo("open log: %s", cmd) subprocess.Popen(shlex.split(cmd)) found = True #open roslog file roslog = nm.screen().getROSLogFile(nodename) if os.path.isfile(roslog): title_opt = title_opt.replace('LOG', 'ROSLOG') cmd = nm.terminal_cmd([nm.LESS, roslog], title_opt) rospy.loginfo("open ROS log: %s", cmd) subprocess.Popen(shlex.split(cmd)) found = True return found else: nm.ssh().ssh_x11_exec(host, [nm.STARTER_SCRIPT, '--show_screen_log', nodename], title_opt) nm.ssh().ssh_x11_exec(host, [nm.STARTER_SCRIPT, '--show_ros_log', nodename], title_opt.replace('LOG', 'ROSLOG')) return False
def openLog(cls, nodename, host): ''' Opens the log file associated with the given node in a new terminal. @param nodename: the name of the node (with name space) @type nodename: C{str} @param host: the host name or ip where the log file are @type host: C{str} @return: C{True}, if a log file was found @rtype: C{bool} @raise Exception: on errors while resolving host @see: L{node_manager_fkie.is_local()} ''' rospy.loginfo("show log for '%s' on '%s'", str(nodename), str(host)) title_opt = ' '.join(['"LOG', nodename, 'on', host, '"']) if nm.is_local(host): found = False screenLog = nm.screen().getScreenLogFile(node=nodename) if os.path.isfile(screenLog): cmd = nm.terminal_cmd([nm.LESS, screenLog], title_opt) rospy.loginfo("open log: %s", cmd) ps = subprocess.Popen(shlex.split(cmd)) # wait for process to avoid 'defunct' processes thread = threading.Thread(target=ps.wait) thread.setDaemon(True) thread.start() found = True #open roslog file roslog = nm.screen().getROSLogFile(nodename) if os.path.isfile(roslog): title_opt = title_opt.replace('LOG', 'ROSLOG') cmd = nm.terminal_cmd([nm.LESS, roslog], title_opt) rospy.loginfo("open ROS log: %s", cmd) ps = subprocess.Popen(shlex.split(cmd)) # wait for process to avoid 'defunct' processes thread = threading.Thread(target=ps.wait) thread.setDaemon(True) thread.start() found = True return found else: ps = nm.ssh().ssh_x11_exec( host, [nm.STARTER_SCRIPT, '--show_screen_log', nodename], title_opt) # wait for process to avoid 'defunct' processes thread = threading.Thread(target=ps.wait) thread.setDaemon(True) thread.start() ps = nm.ssh().ssh_x11_exec( host, [nm.STARTER_SCRIPT, '--show_ros_log', nodename], title_opt.replace('LOG', 'ROSLOG')) # wait for process to avoid 'defunct' processes thread = threading.Thread(target=ps.wait) thread.setDaemon(True) thread.start() return False
def openLog(cls, nodename, host, user=None): ''' Opens the log file associated with the given node in a new terminal. @param nodename: the name of the node (with name space) @type nodename: C{str} @param host: the host name or ip where the log file are @type host: C{str} @return: C{True}, if a log file was found @rtype: C{bool} @raise Exception: on errors while resolving host @see: L{node_manager_fkie.is_local()} ''' rospy.loginfo("show log for '%s' on '%s'", str(nodename), str(host)) title_opt = ' '.join(['"LOG', nodename, 'on', host, '"']) if nm.is_local(host): found = False screenLog = nm.screen().getScreenLogFile(node=nodename) if os.path.isfile(screenLog): cmd = nm.terminal_cmd([nm.LESS, screenLog], title_opt) rospy.loginfo("open log: %s", cmd) ps = subprocess.Popen(shlex.split(cmd)) # wait for process to avoid 'defunct' processes thread = threading.Thread(target=ps.wait) thread.setDaemon(True) thread.start() found = True #open roslog file roslog = nm.screen().getROSLogFile(nodename) if os.path.isfile(roslog): title_opt = title_opt.replace('LOG', 'ROSLOG') cmd = nm.terminal_cmd([nm.LESS, roslog], title_opt) rospy.loginfo("open ROS log: %s", cmd) ps = subprocess.Popen(shlex.split(cmd)) # wait for process to avoid 'defunct' processes thread = threading.Thread(target=ps.wait) thread.setDaemon(True) thread.start() found = True return found else: ps = nm.ssh().ssh_x11_exec(host, [nm.STARTER_SCRIPT, '--show_screen_log', nodename], title_opt, user) # wait for process to avoid 'defunct' processes thread = threading.Thread(target=ps.wait) thread.setDaemon(True) thread.start() ps = nm.ssh().ssh_x11_exec(host, [nm.STARTER_SCRIPT, '--show_ros_log', nodename], title_opt.replace('LOG', 'ROSLOG'), user) # wait for process to avoid 'defunct' processes thread = threading.Thread(target=ps.wait) thread.setDaemon(True) thread.start() return False
def ssh_x11_exec(self, host, cmd, title=None, user=None): ''' Executes a command on remote host using a terminal with X11 forwarding. @todo: establish connection using paramiko SSH library. @param host: the host @type host: C{str} @param cmd: the list with command and arguments @type cmd: C{[str,...]} @param title: the title of the new opened terminal, if it is None, no new terminal will be created @type title: C{str} or C{None} @param user: user name @return: the result of C{subprocess.Popen(command)} @see: U{http://docs.python.org/library/subprocess.html?highlight=subproces#subprocess} ''' with self.mutex: try: # workaround: use ssh in a terminal with X11 forward user = self.USER_DEFAULT if user is None else user if self.SSH_AUTH.has_key(host): user = self.SSH_AUTH[host] # generate string for SSH command ssh_str = ' '.join([ '/usr/bin/ssh', '-aqtx', '-oClearAllForwardings=yes', '-oConnectTimeout=5', '-oStrictHostKeyChecking=no', '-oVerifyHostKeyDNS=no', '-oCheckHostIP=no', ''.join([user, '@', host]) ]) if not title is None: cmd_str = nm.terminal_cmd([ssh_str, ' '.join(cmd)], title) else: cmd_str = str(' '.join([ssh_str, ' '.join(cmd)])) rospy.loginfo("REMOTE x11 execute on %s: %s", host, cmd_str) return subprocess.Popen(shlex.split(cmd_str)) except: pass
def openScreenTerminal(cls, host, screen_name, nodename, user=None): ''' Open the screen output in a new terminal. @param host: the host name or ip where the screen is running. @type host: C{str} @param screen_name: the name of the screen to show @type screen_name: C{str} @param nodename: the name of the node is used for the title of the terminal @type nodename: C{str} @raise Exception: on errors while resolving host @see: L{node_manager_fkie.is_local()} ''' #create a title of the terminal # pid, session_name = cls.splitSessionName(screen_name) title_opt = ' '.join(['"SCREEN', nodename, 'on', host, '"']) if nm.is_local(host): cmd = nm.terminal_cmd([cls.SCREEN, '-x', screen_name], title_opt) rospy.loginfo("Open screen terminal: %s", cmd) ps = subprocess.Popen(shlex.split(cmd)) # wait for process to avoid 'defunct' processes thread = threading.Thread(target=ps.wait) thread.setDaemon(True) thread.start() else: ps = nm.ssh().ssh_x11_exec(host, [cls.SCREEN, '-x', screen_name], title_opt) rospy.loginfo("Open remote screen terminal: %s", ps) # wait for process to avoid 'defunct' processes thread = threading.Thread(target=ps.wait) thread.setDaemon(True) thread.start()
def ssh_x11_exec(self, host, cmd, title=None, user=None): ''' Executes a command on remote host using a terminal with X11 forwarding. @todo: establish connection using paramiko SSH library. @param host: the host @type host: C{str} @param cmd: the list with command and arguments @type cmd: C{[str,...]} @param title: the title of the new opened terminal, if it is None, no new terminal will be created @type title: C{str} or C{None} @param user: user name @return: the result of C{subprocess.Popen(command)} @see: U{http://docs.python.org/library/subprocess.html?highlight=subproces#subprocess} ''' try: self.mutex.acquire() # workaround: use ssh in a terminal with X11 forward user = self.USER_DEFAULT if user is None else user if self.SSH_AUTH.has_key(host): user = self.SSH_AUTH[host] # generate string for SSH command ssh_str = ' '.join(['/usr/bin/ssh', '-aqtx', '-oClearAllForwardings=yes', '-oConnectTimeout=5', '-oStrictHostKeyChecking=no', '-oVerifyHostKeyDNS=no', '-oCheckHostIP=no', ''.join([user, '@', host])]) if not title is None: cmd_str = nm.terminal_cmd([ssh_str, ' '.join(cmd)], title) else: cmd_str = str(' '.join([ssh_str, ' '.join(cmd)])) rospy.loginfo("REMOTE x11 execute on %s: %s", host, cmd_str) return subprocess.Popen(shlex.split(cmd_str)) finally: self.mutex.release()