Beispiel #1
0
def main():
    file_name = "pluginlib_helper.cpp"
    fileh = open(file_name, "w")
    plugin1 = PluginDescription()
    plugin1.lookup_name = "name1"
    plugin1.class_type = "class1"
    plugin2 = PluginDescription()
    plugin2.lookup_name = "name2"
    plugin2.class_type = "class2"
    generate(fileh, [plugin1, plugin2])
    close(fileh)
def parse_plugin_xml(xml_str, package="", manifest=""):
  """
  Parse a plugin description and return all the plugin classes
  that were found.
  xml_str the xml string to parse.
  """
  plugin_classes = []
  parser = etree.XMLParser(recover=True)
  #xml_tree = xml.parse(file, parser=parser)
  #xml_root = xml_tree.getroot()
  xml_root = xml.fromstring(xml_str, parser)
  for xml_library in xml_root.iter("library"):
    debug_print(xml_library.attrib)
    for xml_class in xml_library.iter("class"):
      debug_print(xml_class.attrib)
      plugin_class = PluginDescription()
      plugin_class.library_name = xml_library.attrib["path"]
      try:
        plugin_class.lookup_name = xml_class.attrib["name"]
      except KeyError:
        plugin_class.lookup_name = ""
      plugin_class.class_type = xml_class.attrib["type"]
      try:
        plugin_class.base_class = xml_class.attrib["base_class_type"]
      except KeyError:
        debug_print("ERROR: NO BASE CLASS!")
        exit(1)
        #plugin_class.lookup_name = ""
      desc = xml_class.find("description")
      if desc is not None:
        plugin_class.description = desc.text.strip()
      else:
        plugin_class.description = ""
      plugin_class.package = package
      plugin_class.manifest_path = manifest
      plugin_classes.append(plugin_class)
      debug_print(plugin_class)
  return plugin_classes
def main():
  file_name = "pluginlib_helper.cpp"
  fileh = open(file_name, "w")
  plugin1 = PluginDescription()
  plugin1.lookup_name = "name1"
  plugin1.class_type = "class1"
  plugin2 = PluginDescription()
  plugin2.lookup_name = "name2"
  plugin2.class_type = "class2"
  generate(fileh, [plugin1, plugin2])
  close(fileh)
def parse_plugin_xml(xml_str, package="", manifest=""):
    """
  Parse a plugin description and return all the plugin classes
  that were found.
  xml_str the xml string to parse.
  """
    plugin_classes = []
    parser = etree.XMLParser(recover=True)
    #xml_tree = xml.parse(file, parser=parser)
    #xml_root = xml_tree.getroot()
    xml_root = xml.fromstring(xml_str, parser)
    for xml_library in xml_root.iter("library"):
        debug_print(xml_library.attrib)
        for xml_class in xml_library.iter("class"):
            debug_print(xml_class.attrib)
            plugin_class = PluginDescription()
            plugin_class.library_name = xml_library.attrib["path"]
            try:
                plugin_class.lookup_name = xml_class.attrib["name"]
            except KeyError:
                plugin_class.lookup_name = ""
            plugin_class.class_type = xml_class.attrib["type"]
            try:
                plugin_class.base_class = xml_class.attrib["base_class_type"]
            except KeyError:
                debug_print("ERROR: NO BASE CLASS!")
                exit(1)
                #plugin_class.lookup_name = ""
            desc = xml_class.find("description")
            if desc is not None:
                plugin_class.description = desc.text.strip()
            else:
                plugin_class.description = ""
            plugin_class.package = package
            plugin_class.manifest_path = manifest
            plugin_classes.append(plugin_class)
            debug_print(plugin_class)
    return plugin_classes