plugins.py
Go to the documentation of this file.
00001 #import roslib; roslib.load_manifest('rcommander_core')
00002 import sys
00003 #import pdb
00004 #pdb.set_trace()
00005 import tool_utils as tu
00006 import roslib.rospack
00007 import inspect
00008 import os
00009 
00010 def load_plugins(robot_namespaces):
00011     """
00012     @return: list of static roswtf plugins, list of online
00013     roswtf plugins
00014     @rtype: [fn], [fn]
00015     """
00016     dependencies = roslib.rospack.rospack_depends_on_1('rcommander')
00017     plugin_classes = []
00018     for pkg in dependencies:
00019         m_filename = roslib.manifest.manifest_file(pkg, True)
00020         manifest   = roslib.manifest.parse_file(m_filename)
00021         p_modules  = manifest.get_export('rcommander', 'plugin')
00022         p_tabs     = manifest.get_export('rcommander', 'tab')
00023         p_robots   = manifest.get_export('rcommander', 'robot')
00024         if not p_modules:
00025             continue
00026 
00027         for p_module, p_tab, p_robot in zip(p_modules, p_tabs, p_robots):
00028             if not (p_robot in robot_namespaces):
00029                 continue
00030             ## import the specified plugin module
00031             try:
00032                 roslib.load_manifest(pkg)
00033                 mod = __import__(p_module)
00034                 for sub_mod in p_module.split('.')[1:]:
00035                     mod = getattr(mod, sub_mod)
00036 
00037                 for cls in dir(mod):
00038                     cls_obj = getattr(mod, cls)
00039                     if inspect.isclass(cls_obj) and (tu.ToolBase in inspect.getmro(cls_obj)):
00040                         plugin_classes.append([p_tab, cls_obj])
00041             except Exception, e:
00042                 print e.__class__, e
00043                 print >> sys.stderr, "Unable to load plugin [%s] from package [%s]"% (p_module, pkg)
00044     return plugin_classes
00045 
00046 if __name__ == '__main__':
00047     print load_plugins('rcommander')


rcommander
Author(s): Hai Nguyen (haidai@gmail.com)
autogenerated on Thu Nov 28 2013 11:46:34