Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 import os
00032
00033 from python_qt_binding.QtCore import qDebug, qWarning
00034
00035 from rospkg.common import MANIFEST_FILE, PACKAGE_FILE
00036 from rospkg.manifest import parse_manifest_file, InvalidManifest
00037
00038 from .ros_plugin_provider import RosPluginProvider
00039
00040
00041 class RospkgPluginProvider(RosPluginProvider):
00042
00043 rospack = None
00044
00045 """`RosPluginProvider` using rospkg."""
00046
00047 def __init__(self, export_tag, base_class_type):
00048 super(RospkgPluginProvider, self).__init__(export_tag, base_class_type)
00049 self.setObjectName('RospkgPluginProvider')
00050
00051 if RospkgPluginProvider.rospack is None:
00052 from rospkg import RosPack
00053 RospkgPluginProvider.rospack = RosPack()
00054
00055 def _find_plugins(self, export_tag, discovery_data):
00056 crawl = True
00057 if discovery_data:
00058 data = discovery_data.get_settings('rqt_gui.RospkgPluginProvider')
00059 export_data = data.get_settings(export_tag)
00060 crawl = export_tag not in data.child_groups()
00061
00062 plugins = []
00063 if crawl:
00064 qDebug("RospkgPluginProvider._find_plugins() crawling for plugins of type '%s'" % export_tag)
00065 r = RospkgPluginProvider.rospack
00066 for package_name in r.list():
00067 package_path = r.get_path(package_name)
00068 manifest_file_path = os.path.join(package_path, MANIFEST_FILE)
00069 if os.path.isfile(manifest_file_path):
00070 try:
00071 manifest = parse_manifest_file(package_path, MANIFEST_FILE)
00072 except InvalidManifest as e:
00073 qWarning('Could not parse manifest "%s":\n%s' % (manifest_file_path, e))
00074 continue
00075 exports = manifest.get_export(export_tag, 'plugin')
00076 for export in exports:
00077 plugins.append([package_name, str(export)])
00078 continue
00079
00080 package_file_path = os.path.join(package_path, PACKAGE_FILE)
00081 if os.path.isfile(package_file_path):
00082
00083 try:
00084 from catkin_pkg.package import parse_package, InvalidPackage
00085 except ImportError as e:
00086 qWarning('Package "%s" has a package file, but import of parser failed:\n%s' % (package_path, e))
00087 continue
00088 try:
00089 package = parse_package(package_file_path)
00090 except InvalidPackage as e:
00091 qWarning('Could not parse package file "%s":\n%s' % (package_file_path, e))
00092 continue
00093 for export in package.exports:
00094 if export.tagname != export_tag or 'plugin' not in export.attributes:
00095 continue
00096 plugin_xml_path = export.attributes['plugin']
00097 plugin_xml_path = plugin_xml_path.replace('${prefix}', package_path)
00098 plugins.append([package_name, plugin_xml_path])
00099 continue
00100
00101
00102 if discovery_data:
00103 plugins_by_package = {}
00104 for (package_name, export) in plugins:
00105 if package_name not in plugins_by_package:
00106 plugins_by_package[package_name] = []
00107 plugins_by_package[package_name].append(export)
00108 for package_name, exports in plugins_by_package.items():
00109 export_data.set_value(package_name, os.pathsep.join([str(e) for e in exports]))
00110
00111 else:
00112
00113 for package_name in export_data.all_keys():
00114 exports = export_data.value(package_name)
00115 if exports:
00116 for export in exports.split(os.pathsep):
00117 plugins.append([package_name, export])
00118
00119 return plugins