Exemplo n.º 1
0
 def getRobotDescr(self):
     '''
 Parses the launch file for C{robots} parameter to get the description of the
 robot.
 @return: the robot description stored in the configuration
 @rtype: C{dict(robot:dict('type' :str, 'name': str, 'images' : [str], 'description': str))}
 '''
     result = dict()
     if not self.Roscfg is None:
         for param, p in self.Roscfg.params.items():
             if param.endswith('robots'):
                 if isinstance(p.value, list):
                     if len(p.value) > 0 and len(p.value[0]) != 5:
                         print "WRONG format, expected: ['host', 'type', 'name', 'images', 'description'] -> ignore", param
                     else:
                         for entry in p.value:
                             result[entry[0]] = {
                                 'type':
                                 entry[1],
                                 'name':
                                 entry[2],
                                 'images':
                                 resolve_paths(entry[3]).split(','),
                                 'description':
                                 resolve_paths(self._decode(entry[4]))
                             }
     return result
Exemplo n.º 2
0
 def updateDescription(self, index, cfg, name, displayed_name, robot_type,
                       description, images):
     '''
 Sets the values of an existing item to the given items only if the current 
 value is empty.
 '''
     if index < len(self._data):
         obj = self._data[index]
         if not cfg in obj['cfgs']:
             obj['cfgs'].append(cfg)
         if not obj['name']:
             obj['name'] = name
         if not obj['displayed_name']:
             obj['displayed_name'] = displayed_name
         if not obj['type']:
             obj['type'] = robot_type
         if not obj['description']:
             obj['description'] = resolve_paths(description)
         if not obj['images']:
             for image_path in images:
                 img = resolve_paths(image_path)
                 if img and img[0] != os.path.sep:
                     img = os.path.join(nm.settings().PACKAGE_DIR,
                                        image_path)
                 if os.path.isfile(img):
                     obj['images'].append(QtGui.QPixmap(img))
 def setDescription(self, index, cfg, name, displayed_name, robot_type, description, images):
   '''
   Sets the values of an existing item to the given items.
   '''
   if index < len(self._data):
     obj = self._data[index]
     if not cfg in obj['cfgs']:
       obj['cfgs'].append(cfg)
     obj['name'] = name
     obj['displayed_name'] = displayed_name
     obj['type'] = robot_type
     obj['description'] = resolve_paths(description)
     del obj['images'][:]
     for image_path in images:
       img = resolve_paths(image_path)
       if img and img[0] != os.path.sep:
         img = os.path.join(nm.settings().PACKAGE_DIR, image_path)
       if os.path.isfile(img):
         obj['images'].append(QtGui.QPixmap(img))
Exemplo n.º 4
0
 def getCapabilitiesDesrc(self):
   '''
   Parses the launch file for C{capabilities} and C{capability_group} parameter 
   and creates  dictionary for grouping the nodes.
   @return: the capabilities description stored in this configuration
   @rtype: C{dict(machine : dict(namespace: dict(group:dict('type' : str, 'images' : [str], 'description' : str, 'nodes' : [str]))))}
   '''
   result = dict()
   capabilies_descr = dict()
   if not self.Roscfg is None:
     # get the capabilities description
     # use two separate loops, to create the description list first
     # TODO read the group description depending on namespace 
     for param, p in self.Roscfg.params.items():
       if param.endswith('capabilities'):
         if isinstance(p.value, list):
           if len(p.value) > 0 and len(p.value[0]) != 4:
             print "WRONG format, expected: ['name', 'type', 'images', 'description'] -> ignore", param
           else:
             for entry in p.value:
               capabilies_descr[entry[0]] = { 'type' : ''.join([entry[1]]), 'images' : resolve_paths(entry[2]).split(','), 'description' : resolve_paths(self._decode(entry[3]))}
     # get the capability nodes
     for item in self.Roscfg.nodes:
       node_fullname = roslib.names.ns_join(item.namespace, item.name)
       machine_name = item.machine_name if not item.machine_name is None and not item.machine_name == 'localhost' else ''
       added = False
       cap_param = roslib.names.ns_join(node_fullname, 'capability_group')
       cap_ns = node_fullname
       #find the capability group parameter in namespace
       while not self.Roscfg.params.has_key(cap_param) and cap_param.count(roslib.names.SEP) > 1:
         cap_ns = roslib.names.namespace(cap_ns).rstrip(roslib.names.SEP)
         if not cap_ns:
           cap_ns = roslib.names.SEP
         cap_param = roslib.names.ns_join(cap_ns, 'capability_group')
       if cap_ns == node_fullname:
         cap_ns = item.namespace.rstrip(roslib.names.SEP)
         if not cap_ns:
           cap_ns = roslib.names.SEP
       # if the 'capability_group' parameter found, assign node to the group
       if self.Roscfg.params.has_key(cap_param) and self.Roscfg.params[cap_param].value:
         p = self.Roscfg.params[cap_param]
         if not result.has_key(machine_name):
           result[machine_name] = dict()
         for (ns, groups) in result[machine_name].items():
           if ns == cap_ns and groups.has_key(p.value):
             groups[p.value]['nodes'].append(node_fullname)
             added = True
             break
         if not added:
           ns = cap_ns
           # add new group in the namespace of the node
           if not result[machine_name].has_key(ns):
             result[machine_name][ns] = dict()
           if not result[machine_name][ns].has_key(p.value):
             try:
               result[machine_name][ns][p.value] = {'type' : capabilies_descr[p.value]['type'],
                                                    'images': capabilies_descr[p.value]['images'],
                                                    'description' : capabilies_descr[p.value]['description'],
                                                    'nodes' : [] }
             except:
               result[machine_name][ns][p.value] = { 'type' : '',
                                                    'images': [],
                                                    'description' : '',
                                                    'nodes' : [] }
           result[machine_name][ns][p.value]['nodes'].append(node_fullname)
   return result
Exemplo n.º 5
0
 def getRobotDescr(self):
   '''
   Parses the launch file for C{robots} parameter to get the description of the
   robot.
   @return: the robot description stored in the configuration
   @rtype: C{dict(robot:dict('type' :str, 'name': str, 'images' : [str], 'description': str))}
   '''
   result = dict()
   if not self.Roscfg is None:
     for param, p in self.Roscfg.params.items():
       if param.endswith('robots'):
         if isinstance(p.value, list):
           if len(p.value) > 0 and len(p.value[0]) != 5:
             print "WRONG format, expected: ['host', 'type', 'name', 'images', 'description'] -> ignore", param
           else:
             for entry in p.value:
               result[entry[0]] = { 'type' : entry[1], 'name' : entry[2], 'images' : resolve_paths(entry[3]).split(','), 'description' : resolve_paths(self._decode(entry[4])) }
   return result
Exemplo n.º 6
0
 def getCapabilitiesDesrc(self):
     '''
 Parses the launch file for C{capabilities} and C{capability_group} parameter 
 and creates  dictionary for grouping the nodes.
 @return: the capabilities description stored in this configuration
 @rtype: C{dict(machine : dict(namespace: dict(group:dict('type' : str, 'images' : [str], 'description' : str, 'nodes' : [str]))))}
 '''
     result = dict()
     capabilies_descr = dict()
     if not self.Roscfg is None:
         # get the capabilities description
         # use two separate loops, to create the description list first
         # TODO read the group description depending on namespace
         for param, p in self.Roscfg.params.items():
             if param.endswith('capabilities'):
                 if isinstance(p.value, list):
                     if len(p.value) > 0 and len(p.value[0]) != 4:
                         print "WRONG format, expected: ['name', 'type', 'images', 'description'] -> ignore", param
                     else:
                         for entry in p.value:
                             capabilies_descr[entry[0]] = {
                                 'type':
                                 ''.join([entry[1]]),
                                 'images':
                                 resolve_paths(entry[2]).split(','),
                                 'description':
                                 resolve_paths(self._decode(entry[3]))
                             }
         # get the capability nodes
         for item in self.Roscfg.nodes:
             node_fullname = roslib.names.ns_join(item.namespace, item.name)
             machine_name = item.machine_name if not item.machine_name is None and not item.machine_name == 'localhost' else ''
             added = False
             cap_param = roslib.names.ns_join(node_fullname,
                                              'capability_group')
             cap_ns = node_fullname
             #find the capability group parameter in namespace
             while not self.Roscfg.params.has_key(
                     cap_param) and cap_param.count(roslib.names.SEP) > 1:
                 cap_ns = roslib.names.namespace(cap_ns).rstrip(
                     roslib.names.SEP)
                 if not cap_ns:
                     cap_ns = roslib.names.SEP
                 cap_param = roslib.names.ns_join(cap_ns,
                                                  'capability_group')
             if cap_ns == node_fullname:
                 cap_ns = item.namespace.rstrip(roslib.names.SEP)
                 if not cap_ns:
                     cap_ns = roslib.names.SEP
             # if the 'capability_group' parameter found, assign node to the group
             if self.Roscfg.params.has_key(
                     cap_param) and self.Roscfg.params[cap_param].value:
                 p = self.Roscfg.params[cap_param]
                 if not result.has_key(machine_name):
                     result[machine_name] = dict()
                 for (ns, groups) in result[machine_name].items():
                     if ns == cap_ns and groups.has_key(p.value):
                         groups[p.value]['nodes'].append(node_fullname)
                         added = True
                         break
                 if not added:
                     ns = cap_ns
                     # add new group in the namespace of the node
                     if not result[machine_name].has_key(ns):
                         result[machine_name][ns] = dict()
                     if not result[machine_name][ns].has_key(p.value):
                         try:
                             result[machine_name][ns][p.value] = {
                                 'type':
                                 capabilies_descr[p.value]['type'],
                                 'images':
                                 capabilies_descr[p.value]['images'],
                                 'description':
                                 capabilies_descr[p.value]['description'],
                                 'nodes': []
                             }
                         except:
                             result[machine_name][ns][p.value] = {
                                 'type': '',
                                 'images': [],
                                 'description': '',
                                 'nodes': []
                             }
                     result[machine_name][ns][p.value]['nodes'].append(
                         node_fullname)
     return result