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 qWarning
00034
00035 from rospkg import RosPack
00036 from rospkg.common import MANIFEST_FILE, PACKAGE_FILE
00037 from rospkg.manifest import parse_manifest_file, InvalidManifest
00038
00039 from .ros_plugin_provider import RosPluginProvider
00040
00041
00042 class RospkgPluginProvider(RosPluginProvider):
00043
00044 """`RosPluginProvider` using rospkg."""
00045
00046 def __init__(self, export_tag, base_class_type):
00047 super(RospkgPluginProvider, self).__init__(export_tag, base_class_type)
00048 self.setObjectName('RospkgPluginProvider')
00049
00050 def _find_plugins(self, export_tag):
00051 plugins = []
00052 r = RosPack()
00053 for package_name in r.list():
00054 package_path = r.get_path(package_name)
00055 manifest_file_path = os.path.join(package_path, MANIFEST_FILE)
00056 if os.path.isfile(manifest_file_path):
00057 try:
00058 manifest = parse_manifest_file(package_path, MANIFEST_FILE)
00059 except InvalidManifest as e:
00060 qWarning('Could not parse manifest "%s":\n%s' % (manifest_file_path, e))
00061 continue
00062 exports = manifest.get_export(export_tag, 'plugin')
00063 for export in exports:
00064 plugins.append([package_name, str(export)])
00065 continue
00066
00067 package_file_path = os.path.join(package_path, PACKAGE_FILE)
00068 if os.path.isfile(package_file_path):
00069
00070 try:
00071 from catkin_pkg.package import parse_package, InvalidPackage
00072 except ImportError as e:
00073 qWarning('Package "%s" has a package file, but import of parser failed:\n%s' % (package_path, e))
00074 continue
00075 try:
00076 package = parse_package(package_file_path)
00077 except InvalidPackage as e:
00078 qWarning('Could not parse package file "%s":\n%s' % (package_file_path, e))
00079 continue
00080 for export in package.exports:
00081 if export.tagname != export_tag or 'plugin' not in export.attributes:
00082 continue
00083 plugin_path = export.attributes['plugin']
00084 if plugin_path.startswith('${prefix}/'):
00085 plugin_path = os.path.join(package_path, plugin_path[10:])
00086 plugins.append([package_name, plugin_path])
00087 continue
00088 return plugins