33 from python_qt_binding.QtCore
import qDebug, qWarning
35 from rospkg.common
import MANIFEST_FILE, PACKAGE_FILE
36 from rospkg.manifest
import parse_manifest_file, InvalidManifest
38 from .ros_plugin_provider
import RosPluginProvider
45 """`RosPluginProvider` using rospkg."""
47 def __init__(self, export_tag, base_class_type):
48 super(RospkgPluginProvider, self).
__init__(export_tag, base_class_type)
49 self.setObjectName(
'RospkgPluginProvider')
51 if RospkgPluginProvider.rospack
is None:
52 from rospkg
import RosPack
53 RospkgPluginProvider.rospack = RosPack()
58 data = discovery_data.get_settings(
'rqt_gui.RospkgPluginProvider')
59 export_data = data.get_settings(export_tag)
60 crawl = export_tag
not in data.child_groups()
64 qDebug(
"RospkgPluginProvider._find_plugins() crawling for plugins of type '%s'" %
66 r = RospkgPluginProvider.rospack
67 for package_name
in r.list():
68 package_path = r.get_path(package_name)
69 manifest_file_path = os.path.join(package_path, MANIFEST_FILE)
70 if os.path.isfile(manifest_file_path):
72 manifest = parse_manifest_file(package_path, MANIFEST_FILE)
73 except InvalidManifest
as e:
74 qWarning(
'Could not parse manifest "%s":\n%s' % (manifest_file_path, e))
76 exports = manifest.get_export(export_tag,
'plugin')
77 for export
in exports:
78 plugins.append([package_name, str(export)])
81 package_file_path = os.path.join(package_path, PACKAGE_FILE)
82 if os.path.isfile(package_file_path):
85 from catkin_pkg.package
import parse_package, InvalidPackage
86 except ImportError
as e:
88 'Package "%s" has a package file, but import of parser failed:\n%s' % (package_path, e))
91 package = parse_package(package_file_path)
92 except InvalidPackage
as e:
93 qWarning(
'Could not parse package file "%s":\n%s' % (package_file_path, e))
95 for export
in package.exports:
96 if export.tagname != export_tag
or 'plugin' not in export.attributes:
98 plugin_xml_path = export.attributes[
'plugin']
99 plugin_xml_path = plugin_xml_path.replace(
'${prefix}', package_path)
100 plugins.append([package_name, plugin_xml_path])
105 plugins_by_package = {}
106 for (package_name, export)
in plugins:
107 if package_name
not in plugins_by_package:
108 plugins_by_package[package_name] = []
109 plugins_by_package[package_name].append(export)
110 for package_name, exports
in plugins_by_package.items():
111 export_data.set_value(package_name, os.pathsep.join([str(e)
for e
in exports]))
115 for package_name
in export_data.all_keys():
116 exports = export_data.value(package_name)
118 for export
in exports.split(os.pathsep):
119 plugins.append([package_name, export])