def killScreens(cls, host, node, user=None, parent=None):
   '''
   Searches for the screen associated with the given node and kill this screens. 
   @param host: the host name or ip where the screen is running
   @type host: C{str}
   @param node: the name of the node those screen output to show
   @type node: C{str}
   @param parent: the parent widget to show a message box, if a user 
   input is required.
   @type parent: L{PySide.QtGui.QWidget}
   '''
   if node is None or len(node) == 0:
     return False
   # get the available screens
   screens = cls.getActiveScreens(host, cls.createSessionName(node), user=user) #user=user, pwd=pwd
   if screens:
     from PySide import QtGui
     result = QtGui.QMessageBox.question(parent, "Kill SCREENs?", '\n'.join(screens), QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Ok)
     if result & QtGui.QMessageBox.Ok:
       for s in screens:
         pid, sep, name = s.partition('.')
         if pid:
           try:
             nm.starter().kill(host, int(pid))
           except:
             import traceback
             rospy.logwarn("Error while kill screen (PID: %s) on host '%s': %s", str(pid), str(host), str(traceback.format_exc()))
       if nm.is_local(host):
         ps = subprocess.Popen([cls.SCREEN, '-wipe'])
         # wait for process to avoid 'defunct' processes
         thread = threading.Thread(target=ps.wait)
         thread.setDaemon(True)
         thread.start()
       else:
         nm.ssh().ssh_exec(host, [cls.SCREEN, '-wipe'])
 def killScreens(cls, node, host, auto_ok_request=True, user=None, pw=None):
     '''
     Searches for the screen associated with the given node and kill this screens.
     @param node: the name of the node those screen output to show
     @type node: C{str}
     @param host: the host name or ip where the screen is running
     @type host: C{str}
     '''
     if node is None or len(node) == 0:
         return False
     try:
         # get the available screens
         screens = cls._getActiveScreens(host, cls.createSessionName(node), auto_ok_request, user=user, pwd=pw)  # user=user, pwd=pwd
         if screens:
             do_kill = True
             if auto_ok_request:
                 from node_manager_fkie.detailed_msg_box import MessageBox
                 result = MessageBox.question(None, "Kill SCREENs?", '\n'.join(screens), buttons=MessageBox.Ok | MessageBox.Cancel)
                 if result == MessageBox.Ok:
                     do_kill = True
             if do_kill:
                 for s in screens:
                     pid, _, _ = s.partition('.')
                     if pid:
                         try:
                             nm.starter()._kill_wo(host, int(pid), auto_ok_request, user, pw)
                         except:
                             import traceback
                             rospy.logwarn("Error while kill screen (PID: %s) on host '%s': %s", utf8(pid), utf8(host), traceback.format_exc(1))
                 if nm.is_local(host):
                     SupervisedPopen([cls.SCREEN, '-wipe'], object_id='screen -wipe', description="screen: clean up the socket with -wipe")
                 else:
                     nm.ssh().ssh_exec(host, [cls.SCREEN, '-wipe'], close_stdin=True, close_stdout=True, close_stderr=True)
     except nm.AuthenticationRequest as e:
         raise nm.InteractionNeededError(e, cls.killScreens, (node, host, auto_ok_request))
Esempio n. 3
0
 def runSelected(self):
   '''
   Runs the selected node, or do nothing. 
   '''
   self.binary = self.binary_field.currentText()
   if self.package and self.binary:
     nm.starter().runNodeWithoutConfig(self.host, self.package, self.binary, str(self.name_field.text()), str(''.join(['__ns:=', self.ns_field.text(), ' ', self.args_field.text()])).split(' '))
 def killScreens(cls, node, host, auto_ok_request=True, user=None, pw=None):
     '''
     Searches for the screen associated with the given node and kill this screens.
     @param node: the name of the node those screen output to show
     @type node: C{str}
     @param host: the host name or ip where the screen is running
     @type host: C{str}
     '''
     if node is None or len(node) == 0:
         return False
     try:
         # get the available screens
         screens = cls._getActiveScreens(host,
                                         cls.createSessionName(node),
                                         auto_ok_request,
                                         user=user,
                                         pwd=pw)  # user=user, pwd=pwd
         if screens:
             do_kill = True
             if auto_ok_request:
                 try:
                     from python_qt_binding.QtGui import QMessageBox
                 except:
                     from python_qt_binding.QtWidgets import QMessageBox
                 result = QMessageBox.question(
                     None, "Kill SCREENs?", '\n'.join(screens),
                     QMessageBox.Ok | QMessageBox.Cancel, QMessageBox.Ok)
                 if result & QMessageBox.Ok:
                     do_kill = True
             if do_kill:
                 for s in screens:
                     pid, _, _ = s.partition('.')
                     if pid:
                         try:
                             nm.starter()._kill_wo(host, int(pid),
                                                   auto_ok_request, user,
                                                   pw)
                         except:
                             import traceback
                             rospy.logwarn(
                                 "Error while kill screen (PID: %s) on host '%s': %s",
                                 str(pid), str(host),
                                 traceback.format_exc(1))
                 if nm.is_local(host):
                     SupervisedPopen(
                         [cls.SCREEN, '-wipe'],
                         object_id='screen -wipe',
                         description="screen: clean up the socket with -wipe"
                     )
                 else:
                     nm.ssh().ssh_exec(host, [cls.SCREEN, '-wipe'],
                                       close_stdin=True,
                                       close_stdout=True,
                                       close_stderr=True)
     except nm.AuthenticationRequest as e:
         raise nm.InteractionNeededError(e, cls.killScreens,
                                         (node, host, auto_ok_request))
Esempio n. 5
0
 def killScreens(cls, node, host, auto_ok_request=True, user=None, pw=None):
     '''
 Searches for the screen associated with the given node and kill this screens. 
 @param node: the name of the node those screen output to show
 @type node: C{str}
 @param host: the host name or ip where the screen is running
 @type host: C{str}
 '''
     if node is None or len(node) == 0:
         return False
     try:
         # get the available screens
         screens = cls.getActiveScreens(host,
                                        cls.createSessionName(node),
                                        user=user)  #user=user, pwd=pwd
         if screens:
             do_kill = True
             if auto_ok_request:
                 from python_qt_binding import QtGui
                 result = QtGui.QMessageBox.question(
                     None, "Kill SCREENs?", '\n'.join(screens),
                     QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel,
                     QtGui.QMessageBox.Ok)
                 if result & QtGui.QMessageBox.Ok:
                     do_kill = True
             if do_kill:
                 for s in screens:
                     pid, _, _ = s.partition('.')
                     if pid:
                         try:
                             nm.starter()._kill_wo(host, int(pid),
                                                   auto_ok_request, user,
                                                   pw)
                         except:
                             import traceback
                             rospy.logwarn(
                                 "Error while kill screen (PID: %s) on host '%s': %s",
                                 str(pid), str(host),
                                 traceback.format_exc())
                 if nm.is_local(host):
                     ps = subprocess.Popen([cls.SCREEN, '-wipe'])
                     # wait for process to avoid 'defunct' processes
                     thread = threading.Thread(target=ps.wait)
                     thread.setDaemon(True)
                     thread.start()
                 else:
                     #            output, error, ok = nm.ssh().ssh_exec(host, [cls.SCREEN, '-wipe'])
                     nm.ssh().ssh_exec(host, [cls.SCREEN, '-wipe'])
     except nm.AuthenticationRequest as e:
         raise nm.InteractionNeededError(e, cls.killScreens,
                                         (node, host, auto_ok_request))
 def _start_node_from_profile(self, master, hostname, pkg, binary, usr, cfg={}):
     try:
         args = []
         restart = False
         # test for start or not
         node = master.getNode("/%s" % binary)
         if node:
             param = get_rosparam(binary, master.masteruri)
             if set(param.keys()) == set(cfg.keys()):
                 for k, v in param.items():
                     if v != cfg[k]:
                         restart = True
                         master.stop_node(node[0], True)
                         break
         else:
             restart = True
         if restart:
             delete_rosparam(binary, master.masteruri)
             for pname, pval in cfg.items():
                 args.append('_%s:=%s' % (pname, pval))
             self._main_window._progress_queue.add2queue(utf8(uuid.uuid4()),
                                            'start %s on %s' % (binary, hostname),
                                            nm.starter().runNodeWithoutConfig,
                                            (utf8(hostname), pkg, utf8(binary), utf8(binary), args, master.masteruri, False, usr))
             self._main_window._progress_queue.start()
     except Exception as me:
         rospy.logwarn("Can not start %s for %s: %s" % (binary, master.masteruri, utf8(me)))
Esempio n. 7
0
 def _start_node_from_profile(self,
                              master,
                              hostname,
                              pkg,
                              binary,
                              usr,
                              cfg={}):
     try:
         args = []
         restart = False
         # test for start or not
         node = master.getNode("/%s" % binary)
         if node:
             param = get_rosparam(binary, master.masteruri)
             if set(param.keys()) == set(cfg.keys()):
                 for k, v in param.items():
                     if v != cfg[k]:
                         restart = True
                         master.stop_node(node[0], True)
                         break
         else:
             restart = True
         if restart:
             delete_rosparam(binary, master.masteruri)
             for pname, pval in cfg.items():
                 args.append('_%s:=%s' % (pname, pval))
             self._main_window._progress_queue.add2queue(
                 str(uuid.uuid4()), 'start %s on %s' % (binary, hostname),
                 nm.starter().runNodeWithoutConfig,
                 (str(hostname), pkg, str(binary), str(binary), args,
                  master.masteruri, False, usr))
             self._main_window._progress_queue.start()
     except Exception as me:
         rospy.logwarn("Can not start %s for %s: %s" %
                       (binary, master.masteruri, me))
Esempio n. 8
0
 def runSelected(self):
   '''
   Runs the selected node, or do nothing. 
   '''
   self.binary = self.binary_field.currentText()
   self.host = self.host_field.currentText() if self.host_field.currentText() else self.host
   self.masteruri = self.master_field.currentText() if self.master_field.currentText() else self.masteruri
   if not self.host in self.host_history and self.host != 'localhost' and self.host != '127.0.0.1':
     nm.history().add2HostHistory(self.host)
   ns = self.ns_field.currentText()
   if ns and ns != '/':
     nm.history().addParamCache('run_dialog/NS', ns)
   args = self.args_field.currentText()
   if args:
     nm.history().addParamCache('run_dialog/Args', args)
   if self.package and self.binary:
     nm.history().addParamCache('/Host', self.host)
     nm.starter().runNodeWithoutConfig(self.host, self.package, self.binary, str(self.name_field.text()), str(''.join(['__ns:=', ns, ' ', args])).split(' '), None if self.masteruri == 'ROS_MASTER_URI' else self.masteruri)
Esempio n. 9
0
 def _callService(self, params={}):
   req = unicode(params) if params else ''
   try:
     req, resp = nm.starter().callService(self.service.uri, self.service.name, self.service.get_service_class(), [params])
     self.service_resp_signal.emit(str(req), str(resp))
   except Exception, e:
     import traceback
     print traceback.format_exc(1)
     rospy.logwarn("Error while call service '%s': %s", str(self.service.name), str(e))
     self.service_resp_signal.emit(unicode(req), unicode(e))
 def run(self):
   '''
   '''
   if self._service:
     try:
       req, resp = nm.starter().callService(self._service_uri, self._service, ListDescription)
     except:
       import traceback
       lines = traceback.format_exc().splitlines()
       rospy.logwarn("Error while retrieve the description from %s: %s", str(self._service), str(lines[-1]))
       self.err_signal.emit(self._service_uri, self._service, lines[-1])
     else:
       self.update_signal.emit(self._service_uri, self._service, [resp])
 def killScreens(cls, node, host, auto_ok_request=True, user=None, pw=None):
   '''
   Searches for the screen associated with the given node and kill this screens. 
   @param node: the name of the node those screen output to show
   @type node: C{str}
   @param host: the host name or ip where the screen is running
   @type host: C{str}
   '''
   if node is None or len(node) == 0:
     return False
   try:
     # get the available screens
     screens = cls.getActiveScreens(host, cls.createSessionName(node), user=user) #user=user, pwd=pwd
     if screens:
       do_kill = True
       if auto_ok_request:
         from python_qt_binding import QtGui
         result = QtGui.QMessageBox.question(None, "Kill SCREENs?", '\n'.join(screens), QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Ok)
         if result & QtGui.QMessageBox.Ok:
           do_kill = True
       if do_kill:
         for s in screens:
           pid, sep, name = s.partition('.')
           if pid:
             try:
               nm.starter()._kill_wo(host, int(pid), auto_ok_request, user, pw)
             except:
               import traceback
               rospy.logwarn("Error while kill screen (PID: %s) on host '%s': %s", str(pid), str(host), str(traceback.format_exc()))
         if nm.is_local(host):
           ps = subprocess.Popen([cls.SCREEN, '-wipe'])
           # wait for process to avoid 'defunct' processes
           thread = threading.Thread(target=ps.wait)
           thread.setDaemon(True)
           thread.start()
         else:
           output, error, ok = nm.ssh().ssh_exec(host, [cls.SCREEN, '-wipe'])
   except nm.AuthenticationRequest as e:
     raise nm.InteractionNeededError(e, cls.killScreens, (node, host, auto_ok_request))
 def run(self):
   '''
   '''
   if self._service and self._service_uri:
     try:
       if self._delay_exec > 0:
         time.sleep(self._delay_exec)
       req, resp = nm.starter().callService(self._service_uri, self._service, ListNodes)
       self.update_signal.emit(self._service_uri, self._service, resp.nodes)
     except:
       import traceback
       lines = traceback.format_exc().splitlines()
       rospy.logwarn("Error while retrieve the node list from %s[%s]: %s", str(self._service), str(self._service_uri), str(lines[-1]))
       self.err_signal.emit(self._service_uri, self._service, lines[-1])
Esempio n. 13
0
 def run(self):
     '''
     '''
     if self._service:
         try:
             if self._delay_exec > 0:
                 time.sleep(self._delay_exec)
             _, resp = nm.starter().callService(self._service_uri, self._service, ListDescription)
             self.update_signal.emit(self._service_uri, self._service, [resp])
         except:
             import traceback
             lines = traceback.format_exc(1).splitlines()
             rospy.logwarn("Error while retrieve the description from %s[%s]: %s", utf8(self._service), utf8(self._service_uri), utf8(lines[-1]))
             self.err_signal.emit(self._service_uri, self._service, lines[-1])
 def run(self):
     '''
 '''
     if self._service:
         try:
             req, resp = nm.starter().callService(self._service_uri,
                                                  self._service, ListNodes)
         except:
             import traceback
             rospy.logwarn(
                 "Error while retrieve the node list from default_cfg: %s",
                 str(traceback.format_exc()))
             lines = traceback.format_exc().splitlines()
             self.err_signal.emit(self._service_uri, self._service,
                                  lines[-1])
         else:
             self.update_signal.emit(self._service_uri, self._service,
                                     resp.nodes)
Esempio n. 15
0
 def run(self):
     '''
 '''
     if self._service and self._service_uri:
         try:
             if self._delay_exec > 0:
                 time.sleep(self._delay_exec)
             _, resp = nm.starter().callService(self._service_uri,
                                                self._service, ListNodes)
             self.update_signal.emit(self._service_uri, self._service,
                                     resp.nodes)
         except:
             import traceback
             lines = traceback.format_exc().splitlines()
             rospy.logwarn(
                 "Error while retrieve the node list from %s[%s]: %s",
                 str(self._service), str(self._service_uri), str(lines[-1]))
             self.err_signal.emit(self._service_uri, self._service,
                                  lines[-1])
 def openScreen(cls, node, host, auto_item_request=False, user=None, pw=None, items=[]):
     '''
     Searches for the screen associated with the given node and open the screen
     output in a new terminal.
     @param node: the name of the node those screen output to show
     @type node: C{str}
     @param host: the host name or ip where the screen is running
     @type host: C{str}
     @raise Exception: on errors while resolving host
     @see: L{openScreenTerminal()} or L{_getActiveScreens()}
     '''
     if node is None or len(node) == 0:
         return False
     try:
         if items:
             for item in items:
                 # open the selected screen
                 cls.openScreenTerminal(host, item, node, user)
         else:
             # get the available screens
             screens = cls._getActiveScreens(host, cls.createSessionName(node), auto_item_request, user, pw)
             if len(screens) == 1:
                 cls.openScreenTerminal(host, screens[0], node, user)
             else:
                 # create a list to let the user make a choice, which screen must be open
                 choices = {}
                 for s in screens:
                     pid, session_name = cls.splitSessionName(s)
                     choices[''.join([session_name, ' [', pid, ']'])] = s
                 # Open selection
                 if len(choices) > 0:
                     if len(choices) == 1:
                         cls.openScreenTerminal(host, choices[0], node, user)
                     elif auto_item_request:
                         from select_dialog import SelectDialog
                         items, _ = SelectDialog.getValue('Show screen', '', choices.keys(), False)
                         for item in items:
                             # open the selected screen
                             cls.openScreenTerminal(host, choices[item], node, user)
                     else:
                         raise ScreenSelectionRequest(choices, 'Show screen')
                 else:
                     raise nm.InteractionNeededError(NoScreenOpenLogRequest(node, host), nm.starter().openLog, (node, host, user))
             return len(screens) > 0
     except nm.AuthenticationRequest as e:
         raise nm.InteractionNeededError(e, cls.openScreen, (node, host, auto_item_request))
     except ScreenSelectionRequest as e:
         raise nm.InteractionNeededError(e, cls.openScreen, (node, host, auto_item_request, user, pw))
 def openScreen(cls,
                node,
                host,
                auto_item_request=False,
                user=None,
                pw=None,
                items=[]):
     '''
     Searches for the screen associated with the given node and open the screen
     output in a new terminal.
     @param node: the name of the node those screen output to show
     @type node: C{str}
     @param host: the host name or ip where the screen is running
     @type host: C{str}
     @raise Exception: on errors while resolving host
     @see: L{openScreenTerminal()} or L{_getActiveScreens()}
     '''
     if node is None or len(node) == 0:
         return False
     try:
         if items:
             for item in items:
                 # open the selected screen
                 cls.openScreenTerminal(host, item, node, user)
         else:
             # get the available screens
             screens = cls._getActiveScreens(host,
                                             cls.createSessionName(node),
                                             auto_item_request, user, pw)
             if len(screens) == 1:
                 cls.openScreenTerminal(host, screens[0], node, user)
             else:
                 # create a list to let the user make a choice, which screen must be open
                 choices = {}
                 for s in screens:
                     pid, session_name = cls.splitSessionName(s)
                     choices[''.join([session_name, ' [', pid, ']'])] = s
                 # Open selection
                 if len(choices) > 0:
                     if len(choices) == 1:
                         cls.openScreenTerminal(host, choices[0], node,
                                                user)
                     elif auto_item_request:
                         from select_dialog import SelectDialog
                         items, _ = SelectDialog.getValue(
                             'Show screen', '', choices.keys(), False)
                         for item in items:
                             # open the selected screen
                             cls.openScreenTerminal(host, choices[item],
                                                    node, user)
                     else:
                         raise ScreenSelectionRequest(
                             choices, 'Show screen')
                 else:
                     raise nm.InteractionNeededError(
                         NoScreenOpenLogRequest(node, host),
                         nm.starter().openLog, (node, host, user))
             return len(screens) > 0
     except nm.AuthenticationRequest as e:
         raise nm.InteractionNeededError(e, cls.openScreen,
                                         (node, host, auto_item_request))
     except ScreenSelectionRequest as e:
         raise nm.InteractionNeededError(
             e, cls.openScreen, (node, host, auto_item_request, user, pw))