def call_service_set_level(cls, serviceuri, servicename, loggername,
                            level):
     _req, _resp = nm.starter().callService(
         serviceuri,
         servicename,
         SetLoggerLevel,
         service_args=[loggername, level])
Exemple #2
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(
                 utf8(uuid.uuid4()), 'start %s on %s' % (binary, hostname),
                 nm.starter().runNodeWithoutConfig,
                 (utf8(hostname), pkg, utf8(binary), utf8(binary), args,
                  master.masteruri, False, 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)))
 def _update_loggers(self):
     try:
         service_name = '%s/get_loggers' % self.nodename
         master = xmlrpcclient.ServerProxy(self.masteruri)
         code, _, serviceuri = master.lookupService(rospy.get_name(), service_name)
         if code == 1:
             _req, resp = nm.starter().callService(serviceuri, service_name, GetLoggers, service_args=[])
             self.loggers_signal.emit(resp.loggers)
     except (rospy.ServiceException, nm.StartException) as e:
         rospy.logwarn("Get loggers for %s failed: %s" % (self.nodename, e))
     except IOError as err:
         rospy.logwarn("Get loggers for %s failed; cannot get service URI from %s: %s" % (self.nodename, self.masteruri, err))
     self._thread_update = None
 def open_screen(cls,
                 node,
                 grpc_url,
                 auto_item_request=False,
                 use_log_widget=False,
                 user=None,
                 pw=None,
                 items=[],
                 use_nmd=True):
     '''
     Searches for the screen associated with the given node and open the screen
     output in a new terminal.
     :param str node: the name of the node those screen output to show
     :param str grpc_url: the url of node manager daemon where the screen is running
     :raise Exception: on errors while resolving host
     :see: L{open_screen_terminal()}
     '''
     if node is None or len(node) == 0:
         return False
     try:
         host = get_hostname(grpc_url)
         try:
             muri = url.masteruri(grpc_url)
         except ValueError:
             muri = host
         if items:
             for item in items:
                 # open the selected screen
                 cls.open_screen_terminal(muri, item, node, use_log_widget,
                                          user)
         else:
             # get the available screens
             screens = {}
             try:
                 if use_nmd:
                     screens = nm.nmd().screen.get_screens(grpc_url, node)
                 else:
                     screens = cls._bc_get_active_screens(host,
                                                          node,
                                                          False,
                                                          user=user,
                                                          pwd=pw)
             except grpc.RpcError as e:
                 rospy.logwarn(
                     "can not connect to node manager daemon, detect screens using ssh..."
                 )
                 screens = cls._bc_get_active_screens(host,
                                                      node,
                                                      False,
                                                      user=user,
                                                      pwd=pw)
             if len(screens) == 1:
                 cls.open_screen_terminal(muri,
                                          list(screens.keys())[0], node,
                                          use_log_widget, user)
             else:
                 # create a list to let the user make a choice, which screen must be open
                 choices = {}
                 for sname, _nname in screens.items():
                     pid, session_name = screen.split_session_name(sname)
                     choices['%s [%d]' % (session_name, pid)] = sname
                 # Open selection
                 if len(choices) > 0:
                     if len(choices) == 1:
                         cls.open_screen_terminal(muri,
                                                  choices[0],
                                                  node,
                                                  use_log_widget=False,
                                                  user=user)
                     elif auto_item_request:
                         from select_dialog import SelectDialog
                         items, _ = SelectDialog.getValue(
                             'Show screen',
                             '',
                             list(choices.keys()),
                             False,
                             store_geometry='show_screens')
                         for item in items:
                             # open the selected screen
                             cls.open_screen_terminal(muri,
                                                      choices[item],
                                                      node,
                                                      use_log_widget=False,
                                                      user=user)
                     else:
                         raise ScreenSelectionRequest(
                             choices, 'Show screen')
                 else:
                     if use_log_widget:
                         nm._MAIN_FORM.open_screen_dock(
                             muri, '', node, user)
                     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.open_screen,
             (node, grpc_url, auto_item_request, use_log_widget))
     except ScreenSelectionRequest as e:
         # set use_log_widget to False on multiple screens for same node
         raise nm.InteractionNeededError(
             e, cls.open_screen,
             (node, grpc_url, auto_item_request, False, user, pw))