rospkg_plugin_provider.py
Go to the documentation of this file.
00001 # Copyright (c) 2011, Dirk Thomas, Dorian Scholz, TU Darmstadt
00002 # All rights reserved.
00003 #
00004 # Redistribution and use in source and binary forms, with or without
00005 # modification, are permitted provided that the following conditions
00006 # are met:
00007 #
00008 #   * Redistributions of source code must retain the above copyright
00009 #     notice, this list of conditions and the following disclaimer.
00010 #   * Redistributions in binary form must reproduce the above
00011 #     copyright notice, this list of conditions and the following
00012 #     disclaimer in the documentation and/or other materials provided
00013 #     with the distribution.
00014 #   * Neither the name of the TU Darmstadt nor the names of its
00015 #     contributors may be used to endorse or promote products derived
00016 #     from this software without specific prior written permission.
00017 #
00018 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00021 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00022 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00023 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00024 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00026 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00027 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00028 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029 # POSSIBILITY OF SUCH DAMAGE.
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                 # only try to import catkin if a PACKAGE_FILE is found
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


rqt_gui
Author(s): Dirk Thomas
autogenerated on Fri Jan 3 2014 11:53:47