rospkg_plugin_provider.py
Go to the documentation of this file.
1 # Copyright (c) 2011, Dirk Thomas, Dorian Scholz, TU Darmstadt
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7 #
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following
12 # disclaimer in the documentation and/or other materials provided
13 # with the distribution.
14 # * Neither the name of the TU Darmstadt nor the names of its
15 # contributors may be used to endorse or promote products derived
16 # from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30 
31 import os
32 
33 from python_qt_binding.QtCore import qDebug, qWarning
34 
35 from rospkg.common import MANIFEST_FILE, PACKAGE_FILE
36 from rospkg.manifest import parse_manifest_file, InvalidManifest
37 
38 from .ros_plugin_provider import RosPluginProvider
39 
40 
41 class RospkgPluginProvider(RosPluginProvider):
42 
43  rospack = None
44 
45  """`RosPluginProvider` using rospkg."""
46 
47  def __init__(self, export_tag, base_class_type):
48  super(RospkgPluginProvider, self).__init__(export_tag, base_class_type)
49  self.setObjectName('RospkgPluginProvider')
50 
51  if RospkgPluginProvider.rospack is None:
52  from rospkg import RosPack
53  RospkgPluginProvider.rospack = RosPack()
54 
55  def _find_plugins(self, export_tag, discovery_data):
56  crawl = True
57  if discovery_data:
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()
61 
62  plugins = []
63  if crawl:
64  qDebug("RospkgPluginProvider._find_plugins() crawling for plugins of type '%s'" %
65  export_tag)
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):
71  try:
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))
75  continue
76  exports = manifest.get_export(export_tag, 'plugin')
77  for export in exports:
78  plugins.append([package_name, str(export)])
79  continue
80 
81  package_file_path = os.path.join(package_path, PACKAGE_FILE)
82  if os.path.isfile(package_file_path):
83  # only try to import catkin if a PACKAGE_FILE is found
84  try:
85  from catkin_pkg.package import parse_package, InvalidPackage
86  except ImportError as e:
87  qWarning(
88  'Package "%s" has a package file, but import of parser failed:\n%s' % (package_path, e))
89  continue
90  try:
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))
94  continue
95  for export in package.exports:
96  if export.tagname != export_tag or 'plugin' not in export.attributes:
97  continue
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])
101  continue
102 
103  # write crawling information to cache
104  if discovery_data:
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]))
112 
113  else:
114  # use cached information
115  for package_name in export_data.all_keys():
116  exports = export_data.value(package_name)
117  if exports:
118  for export in exports.split(os.pathsep):
119  plugins.append([package_name, export])
120 
121  return plugins
def _find_plugins(self, export_tag, discovery_data)
def __init__(self, export_tag, base_class_type)


rqt_gui
Author(s): Dirk Thomas
autogenerated on Mon Mar 22 2021 02:13:21