def _load_interface(self):
     interface_file = resolve_url(rospy.get_param('~interface_url', ''))
     if interface_file:
         rospy.loginfo("interface_url: %s", interface_file)
     try:
         data = read_interface(interface_file) if interface_file else {}
         # set the ignore hosts list
         self._re_ignore_hosts = create_pattern('ignore_hosts', data, interface_file, [])
         # set the sync hosts list
         self._re_sync_hosts = create_pattern('sync_hosts', data, interface_file, [])
         self.__sync_topics_on_demand = False
         if interface_file:
             if 'sync_topics_on_demand' in data:
                 self.__sync_topics_on_demand = data['sync_topics_on_demand']
         elif rospy.has_param('~sync_topics_on_demand'):
             self.__sync_topics_on_demand = rospy.get_param('~sync_topics_on_demand')
         rospy.loginfo("sync_topics_on_demand: %s", self.__sync_topics_on_demand)
         self.__resync_on_reconnect = rospy.get_param('~resync_on_reconnect', True)
         rospy.loginfo("resync_on_reconnect: %s", self.__resync_on_reconnect)
         self.__resync_on_reconnect_timeout = rospy.get_param('~resync_on_reconnect_timeout', 0)
         rospy.loginfo("resync_on_reconnect_timeout: %s", self.__resync_on_reconnect_timeout)
     except:
         import traceback
         # kill the ros node, to notify the user about the error
         rospy.logerr("Error on load interface: %s", traceback.format_exc())
         import os
         import signal
         os.kill(os.getpid(), signal.SIGKILL)
 def interpretPath(self, path):
   '''
   Tries to determine the path of the included file. The statement of 
   C{$(find 'package')} will be resolved.
   @param path: the sting which contains the included path
   @type path: C{str}
   @return: if no leading C{os.sep} is detected, the path setted by L{setCurrentPath()}
   will be prepend. C{$(find 'package')} will be resolved. Otherwise the parameter 
   itself will be returned
   @rtype: C{str} 
   '''
   path = path.strip()
   index = path.find('$')
   if index > -1:
     startIndex = path.find('(', index)
     if startIndex > -1:
       endIndex = path.find(')', startIndex+1)
       script = path[startIndex+1:endIndex].split()
       if len(script) == 2 and (script[0] == 'find'):
         try:
           pkg = roslib.packages.get_pkg_dir(script[1])
           return os.path.normpath(''.join([pkg, '/', path[endIndex+1:]]))
         except Exception as e:
           rospy.logwarn(str(e))
   else:
     try:
       return resolve_url(path)
     except ValueError, e:
       if len(path) > 0 and path[0] != '/':
         return os.path.normpath(''.join([self.path, '/', path]))
Beispiel #3
0
 def interpretPath(cls, path, pwd='.'):
     '''
     Tries to determine the path of the included file. The statement of
     $(find 'package') will be resolved.
     The supported URL begins with `file:///`, `package://` or `pkg://`.
     The package URL will be resolved to a valid file path. If the file is in a
     subdirectory, you can replace the subdirectory by `///`.
     @param path: the sting which contains the included path
     @type path: C{str}
     @param pwd: current working path
     @type pwd: C{str}
     @return: if no leading L{os.sep} is detected, the path set by L{setCurrentPath()}
     will be prepend. C{$(find 'package')} will be resolved. Otherwise the parameter
     itself will be returned
     @rtype: C{str}
     '''
     path = path.strip()
     startIndex = path.find('$(')
     if startIndex > -1:
         endIndex = path.find(')', startIndex + 2)
         script = path[startIndex + 2:endIndex].split()
         if len(script) == 2 and (script[0] == 'find'):
             pkg = roslib.packages.get_pkg_dir(script[1])
             return os.path.join(pkg, path[endIndex + 2:].strip(os.path.sep))
     elif len(path) > 0 and path[0] != os.path.sep:
         try:
             return resolve_url(path)
         except ValueError, _:
             if len(path) > 0 and path[0] != os.path.sep:
                 return os.path.normpath(''.join([pwd, os.path.sep, path]))
Beispiel #4
0
 def interpretPath(cls, path, pwd='.'):
     '''
     Tries to determine the path of the included file. The statement of
     $(find 'package') will be resolved.
     The supported URL begins with `file:///`, `package://` or `pkg://`.
     The package URL will be resolved to a valid file path. If the file is in a
     subdirectory, you can replace the subdirectory by `///`.
     @param path: the sting which contains the included path
     @type path: C{str}
     @param pwd: current working path
     @type pwd: C{str}
     @return: C{$(find 'package')} will be resolved. The prefixes `file:///`,
     `package://` or `pkg://` are also resolved. Otherwise the parameter
     itself will be returned.
     @rtype: C{str}
     '''
     path = path.strip()
     startIndex = path.find('$(')
     if startIndex > -1:
         endIndex = path.find(')', startIndex + 2)
         script = path[startIndex + 2:endIndex].split()
         if len(script) == 2 and (script[0] == 'find'):
             pkg = roslib.packages.get_pkg_dir(script[1])
             return os.path.join(pkg,
                                 path[endIndex + 2:].strip(os.path.sep))
     elif len(path) > 0 and path[0] != os.path.sep:
         try:
             return resolve_url(path)
         except ValueError, _:
             if len(path) > 0 and path[0] != os.path.sep:
                 return os.path.normpath(''.join([pwd, os.path.sep, path]))
 def _loadInterface(self):
     interface_file = resolve_url(rospy.get_param('~interface_url', ''))
     if interface_file:
         rospy.loginfo("interface_url: %s", interface_file)
     try:
         data = read_interface(interface_file) if interface_file else {}
         # set the ignore hosts list
         self._re_ignore_hosts = create_pattern('ignore_hosts', data,
                                                interface_file, [])
         # set the sync hosts list
         self._re_sync_hosts = create_pattern('sync_hosts', data,
                                              interface_file, [])
         self.__sync_topics_on_demand = False
         if interface_file:
             if data.has_key('sync_topics_on_demand'):
                 self.__sync_topics_on_demand = data[
                     'sync_topics_on_demand']
         elif rospy.has_param('~sync_topics_on_demand'):
             self.__sync_topics_on_demand = rospy.get_param(
                 '~sync_topics_on_demand')
         rospy.loginfo("sync_topics_on_demand: %s",
                       self.__sync_topics_on_demand)
     except:
         import traceback
         # kill the ros node, to notify the user about the error
         rospy.logerr("Error on load interface: %s", traceback.format_exc())
         import os, signal
         os.kill(os.getpid(), signal.SIGKILL)
Beispiel #6
0
def interpret_path(path):
    '''
    Tries to determine the path of the included file. The statement of
    C{$(find 'package')} will be resolved.
    @param path: the sting which contains the included path
    @type path: C{str}
    @return: if no leading C{os.sep} is detected, the path setted by
    L{setCurrentPath()} will be prepend. C{$(find 'package')} will be resolved.
    Otherwise the parameter itself will be returned
    @rtype: C{str}
    '''
    path = path.strip()
    index = path.find('$')
    if index > -1:
        startIndex = path.find('(', index)
        if startIndex > -1:
            endIndex = path.find(')', startIndex + 1)
            script = path[startIndex + 1:endIndex].split()
            if len(script) == 2 and (script[0] == 'find'):
                try:
                    pkg = roslib.packages.get_pkg_dir(script[1])
                    return os.path.normpath('%s/%s' % (pkg, path[endIndex + 1:]))
                except Exception as e:
                    rospy.logwarn(str(e))
    else:
        try:
            return resolve_url(path)
        except ValueError, e:
            pass
def interpret_path(path):
    '''
    Tries to determine the path of the included file. The statement of
    C{$(find 'package')} will be resolved.
    @param path: the sting which contains the included path
    @type path: C{str}
    @return: C{$(find 'package')} will be resolved. The prefixes `file:///`, `package://` or `pkg://` are also resolved.
    Otherwise the parameter itself normalized by `os.path.normpath` will be returned.
    @rtype: C{str}
    '''
    path = path.strip()
    index = path.find('$')
    if index > -1:
        startIndex = path.find('(', index)
        if startIndex > -1:
            endIndex = path.find(')', startIndex + 1)
            script = path[startIndex + 1:endIndex].split()
            if len(script) == 2 and (script[0] == 'find'):
                try:
                    pkg = roslib.packages.get_pkg_dir(script[1])
                    return os.path.normpath('%s/%s' %
                                            (pkg, path[endIndex + 1:]))
                except Exception as e:
                    rospy.logwarn(str(e))
    else:
        try:
            return resolve_url(path)
        except ValueError, e:
            pass
def interpret_path(path):
    '''
    Tries to determine the path of the included file. The statement of
    C{$(find 'package')} will be resolved.
    @param path: the sting which contains the included path
    @type path: C{str}
    @return: C{$(find 'package')} will be resolved. The prefixes `file:///`, `package://` or `pkg://` are also resolved.
    Otherwise the parameter itself normalized by `os.path.normpath` will be returned.
    @rtype: C{str}
    '''
    path = path.strip()
    index = path.find('$')
    if index > -1:
        startIndex = path.find('(', index)
        if startIndex > -1:
            endIndex = path.find(')', startIndex + 1)
            script = path[startIndex + 1:endIndex].split()
            if len(script) == 2 and (script[0] == 'find'):
                try:
                    pkg = roslib.packages.get_pkg_dir(script[1])
                    return os.path.normpath('%s/%s' % (pkg, path[endIndex + 1:]))
                except Exception as e:
                    rospy.logwarn(utf8(e))
    else:
        try:
            return resolve_url(path)
        except ValueError, e:
            pass
Beispiel #9
0
 def __init__(self, script):
     '''
     @param masteruri: the URI of the remote ROS master
     @type masteruri: C{str}
     '''
     threading.Thread.__init__(self)
     self._script = script
     self._cmd = shlex.split(script)
     if self._cmd[0].startswith("pkg://"):
         resolved = resolve_url(self._cmd.pop(0))
         self._cmd.insert(0, resolved)
     self.setDaemon(True)
     self.spopen = None
     self.stop = False
 def index(self, text):
   '''
   Searches in the given text for key indicates the including of a file and 
   return their index.
   @param text: text to find
   @type text: C{str}
   @return: the index of the including key or -1
   @rtype: C{int}
   '''
   for pattern in self.regexp_list:
     index = pattern.indexIn(text)
     if index > -1:
       return index
   try:
     return resolve_url(path)
   except:
     pass
   return -1
 def __init__(self, script):
     '''
     @param masteruri: the URI of the remote ROS master
     @type masteruri: C{str}
     '''
     threading.Thread.__init__(self)
     self._script = script
     cmd_list = shlex.split(script)
     self._cmd = []
     for cmd in cmd_list:
         if cmd.startswith("pkg://"):
             resolved = resolve_url(cmd)
             self._cmd.append(resolved)
         else:
             self._cmd.append(cmd)
     self.setDaemon(True)
     self.spopen = None
     self.stop = False
Beispiel #12
0
 def index(self, text):
   '''
   Searches in the given text for key indicates the including of a file and 
   return their index.
   @param text: text to find
   @type text: C{str}
   @return: the index of the including key or -1
   @rtype: C{int}
   '''
   for pattern in self.regexp_list:
     index = pattern.indexIn(text)
     if index > -1:
       return index
   try:
     return resolve_url(text)
   except:
     pass
   return -1
Beispiel #13
0
 def on_load_profile_file(self, path):
     '''
     Load the profile file.
     :param path: the path of the profile file.
     :type path: str
     '''
     rospy.loginfo("Load profile %s" % path)
     self.progressBar.setValue(0)
     self.setVisible(True)
     self.setWindowTitle("%s profile started" %
                         os.path.basename(path).rstrip('.nmprofile'))
     hasstart = False
     if path:
         try:
             import yaml
             with open(path, 'r') as f:
                 # print yaml.load(f.read())
                 content = yaml.load(f.read())
                 if not isinstance(content, dict):
                     raise Exception("Mailformed profile: %s" %
                                     os.path.basename(path))
                 for muri, master_dict in content.items():
                     local_hostname = get_hostname(
                         self._main_window.getMasteruri())
                     rmuri = muri.replace('$LOCAL$', local_hostname)
                     master = self._main_window.getMaster(rmuri)
                     running_nodes = master.getRunningNodesIfLocal()
                     usr = None
                     self._current_profile[rmuri] = set()
                     if 'user' in master_dict:
                         usr = master_dict['user']
                     if master_dict['mastername'] and master_dict[
                             'mastername']:
                         nm.nameres().add_master_entry(
                             master.masteruri, master_dict['mastername'],
                             master_dict['address'])
                     hostname = master_dict['address'].replace(
                         '$LOCAL$', local_hostname)
                     if 'master_discovery' in master_dict:
                         self._start_node_from_profile(
                             master,
                             hostname,
                             'master_discovery_fkie',
                             'master_discovery',
                             usr,
                             cfg=master_dict['master_discovery'])
                         self._current_profile[rmuri].add(
                             '/master_discovery')
                     if 'master_sync' in master_dict:
                         self._start_node_from_profile(
                             master,
                             hostname,
                             'master_sync_fkie',
                             'master_sync',
                             usr,
                             cfg=master_dict['master_sync'])
                         self._current_profile[rmuri].add('/master_sync')
                     if 'zeroconf' in master_dict:
                         self._start_node_from_profile(
                             master,
                             hostname,
                             'master_discovery_fkie',
                             'zeroconf',
                             usr,
                             cfg=master_dict['zeroconf'])
                         self._current_profile[rmuri].add('/zeroconf')
                     try:
                         do_start = []
                         do_not_stop = {
                             '/rosout',
                             rospy.get_name(), '/node_manager',
                             '/master_discovery', '/master_sync',
                             '*default_cfg', '/zeroconf'
                         }
                         configs = master_dict['configs']
                         conf_set = set()
                         for cfg_name, cmdict in configs.items():
                             cfg_name = cfg_name.replace(
                                 '$LOCAL$', local_hostname)
                             if cfg_name.startswith("pkg://"):
                                 cfg_name = os.path.abspath(
                                     resolve_url(cfg_name))
                             conf_set.add(cfg_name)
                             reload_launch = True
                             argv = []
                             is_default = False
                             if 'default' in cmdict:
                                 if cmdict['default']:
                                     # it is a default configuration, test for load or not
                                     is_default = True
                                     if 'argv_used' in cmdict['params']:
                                         argv = cmdict['params'][
                                             'argv_used']
                                     if cfg_name in master.default_cfgs:
                                         reload_launch = False
                                         if argv:
                                             params = get_rosparam(
                                                 cfg_name, rmuri)
                                             if 'argv_used' in params:
                                                 reload_launch = set(
                                                     params['argv_used']
                                                 ) != set(argv)
                                     if reload_launch:
                                         self._main_window.on_load_launch_as_default_bypkg(
                                             cmdict['params']['package'],
                                             cmdict['params']
                                             ['launch_file'], master, argv,
                                             local_hostname)
                                     else:
                                         do_not_stop.add(cfg_name)
                             elif 'argv' in cmdict:
                                 if 'argv' in cmdict:
                                     argv = cmdict['argv']
                                 # do we need to load to load/reload launch file
                                 if cfg_name in master.launchfiles:
                                     reload_launch = set(
                                         master.launchfiles[cfg_name].argv
                                     ) != set(argv)
                             if reload_launch:
                                 self._main_window.launch_dock.load_file(
                                     cfg_name, argv, master.masteruri)
                             if 'nodes' in cmdict:
                                 self._current_profile[rmuri].update(
                                     cmdict['nodes'])
                                 force_start = True
                                 cfg = cfg_name if not is_default else roslib.names.ns_join(
                                     cfg_name, 'run')
                                 if not reload_launch:
                                     force_start = False
                                     do_not_stop.update(set(
                                         cmdict['nodes']))
                                     do_start.append(
                                         (reload_launch, cfg,
                                          cmdict['nodes'], force_start))
                                 else:
                                     do_start.append(
                                         (reload_launch, cfg,
                                          cmdict['nodes'], force_start))
                         # close unused configurations
                         for lfile in set(
                                 master.launchfiles.keys()) - conf_set:
                             master._close_cfg(lfile)
                         master.stop_nodes_by_name(running_nodes.keys(),
                                                   True, do_not_stop)
                         for reload_launch, cfg, nodes, force_start in do_start:
                             if nodes:
                                 hasstart = True
                             if reload_launch:
                                 master.start_nodes_after_load_cfg(
                                     cfg.rstrip('/run'), list(nodes),
                                     force_start)
                             else:
                                 master.start_nodes_by_name(
                                     list(nodes), cfg, force_start)
                     except Exception as ml:
                         import traceback
                         print traceback.format_exc(1)
                         rospy.logwarn(
                             "Can not load launch file for %s: %s" %
                             (muri, ml))
         except Exception as e:
             import traceback
             print traceback.format_exc(1)
             WarningMessageBox(QMessageBox.Warning, "Load profile error",
                               'Error while load profile', str(e)).exec_()
         if not hasstart:
             self.update_progress()
         else:
             QTimer.singleShot(1000, self.update_progress)
 def on_load_profile_file(self, path):
     '''
     Load the profile file.
     :param path: the path of the profile file.
     :type path: str
     '''
     rospy.loginfo("Load profile %s" % path)
     self.progressBar.setValue(0)
     self.setVisible(True)
     self.setWindowTitle("%s profile started" % os.path.basename(path).rstrip('.nmprofile'))
     hasstart = False
     if path:
         try:
             import yaml
             with open(path, 'r') as f:
                 # print yaml.load(f.read())
                 content = yaml.load(f.read())
                 if not isinstance(content, dict):
                     raise Exception("Mailformed profile: %s" % os.path.basename(path))
                 for muri, master_dict in content.items():
                     local_hostname = get_hostname(self._main_window.getMasteruri())
                     rmuri = muri.replace('$LOCAL$', local_hostname)
                     master = self._main_window.getMaster(rmuri)
                     running_nodes = master.getRunningNodesIfLocal()
                     usr = None
                     self._current_profile[rmuri] = set()
                     if 'user' in master_dict:
                         usr = master_dict['user']
                     if master_dict['mastername'] and master_dict['mastername']:
                         nm.nameres().add_master_entry(master.masteruri, master_dict['mastername'], master_dict['address'])
                     hostname = master_dict['address'].replace('$LOCAL$', local_hostname)
                     if 'master_discovery' in master_dict:
                         self._start_node_from_profile(master, hostname, 'master_discovery_fkie', 'master_discovery', usr, cfg=master_dict['master_discovery'])
                         self._current_profile[rmuri].add('/master_discovery')
                     if 'master_sync' in master_dict:
                         self._start_node_from_profile(master, hostname, 'master_sync_fkie', 'master_sync', usr, cfg=master_dict['master_sync'])
                         self._current_profile[rmuri].add('/master_sync')
                     if 'zeroconf' in master_dict:
                         self._start_node_from_profile(master, hostname, 'master_discovery_fkie', 'zeroconf', usr, cfg=master_dict['zeroconf'])
                         self._current_profile[rmuri].add('/zeroconf')
                     try:
                         do_start = []
                         do_not_stop = {'/rosout', rospy.get_name(), '/node_manager', '/master_discovery', '/master_sync', '*default_cfg', '/zeroconf'}
                         configs = master_dict['configs']
                         conf_set = set()
                         for cfg_name, cmdict in configs.items():
                             cfg_name = cfg_name.replace('$LOCAL$', local_hostname)
                             if cfg_name.startswith("pkg://"):
                                 cfg_name = os.path.abspath(resolve_url(cfg_name))
                             conf_set.add(cfg_name)
                             reload_launch = True
                             argv = []
                             is_default = False
                             if 'default' in cmdict:
                                 if cmdict['default']:
                                     # it is a default configuration, test for load or not
                                     is_default = True
                                     if 'argv_used' in cmdict['params']:
                                         argv = cmdict['params']['argv_used']
                                     if cfg_name in master.default_cfgs:
                                         reload_launch = False
                                         if argv:
                                             params = get_rosparam(cfg_name, rmuri)
                                             if 'argv_used' in params:
                                                 reload_launch = set(params['argv_used']) != set(argv)
                                     if reload_launch:
                                         self._main_window.on_load_launch_as_default_bypkg(cmdict['params']['package'], cmdict['params']['launch_file'], master, argv, local_hostname)
                                     else:
                                         do_not_stop.add(cfg_name)
                             elif 'argv' in cmdict:
                                 if 'argv' in cmdict:
                                     argv = cmdict['argv']
                                 # do we need to load to load/reload launch file
                                 if cfg_name in master.launchfiles:
                                     reload_launch = set(master.launchfiles[cfg_name].argv) != set(argv)
                             if reload_launch:
                                 self._main_window.launch_dock.load_file(cfg_name, argv, master.masteruri)
                             if 'nodes' in cmdict:
                                 self._current_profile[rmuri].update(cmdict['nodes'])
                                 force_start = True
                                 cfg = cfg_name if not is_default else roslib.names.ns_join(cfg_name, 'run')
                                 if not reload_launch:
                                     force_start = False
                                     do_not_stop.update(set(cmdict['nodes']))
                                     do_start.append((reload_launch, cfg, cmdict['nodes'], force_start))
                                 else:
                                     do_start.append((reload_launch, cfg, cmdict['nodes'], force_start))
                         # close unused configurations
                         for lfile in set(master.launchfiles.keys()) - conf_set:
                             master._close_cfg(lfile)
                         master.stop_nodes_by_name(running_nodes.keys(), True, do_not_stop)
                         for reload_launch, cfg, nodes, force_start in do_start:
                             if nodes:
                                 hasstart = True
                             if reload_launch:
                                 master.start_nodes_after_load_cfg(cfg.rstrip('/run'), list(nodes), force_start)
                             else:
                                 master.start_nodes_by_name(list(nodes), cfg, force_start)
                     except Exception as ml:
                         import traceback
                         print utf8(traceback.format_exc(1))
                         rospy.logwarn("Can not load launch file for %s: %s" % (muri, utf8(ml)))
         except Exception as e:
             import traceback
             print traceback.format_exc(1)
             MessageBox.warning(self, "Load profile error",
                                'Error while load profile',
                                utf8(e))
         if not hasstart:
             self.update_progress()
         else:
             QTimer.singleShot(1000, self.update_progress)