def add_plugin(self, f):
        """Adding and verifying plugin.

        Args:
            f: the filepath for the plugin.
        """
        if f.endswith('.py'):

            # Just the basename without extension
            plugin_name = os.path.splitext(os.path.basename(f))[0]

            # It's possible the plugin has been modified and needs to be reloaded
            if plugin_name in sys.modules:
                try:
                    handler = reload(sys.modules[plugin_name])
                    print'\t- %s %sRELOAD%s' % (plugin_name, color.Yellow, color.Normal)
                except ImportError, error:
                    print 'Failed to import plugin: %s (%s)' % (plugin_name, error)
                    return
            else:
                # Not already loaded so try to import it
                try:
                    handler = __import__(plugin_name, globals(), locals(), [], -1)
                except ImportError, error:
                    print 'Failed to import plugin: %s (%s)' % (plugin_name, error)
                    return

            # Run the handler through plugin validation
            plugin = self.validate(handler)
            print '\t- %s %sOK%s' % (plugin_name, color.Green, color.Normal)
            if plugin:

                # Okay must be successfully loaded so capture the plugin meta-data,
                # modification time and register the plugin through the callback
                plugin['name'] = plugin_name
                plugin['dependencies'] = plugin['class'].dependencies
                plugin['docstring'] = plugin['class'].__doc__
                plugin['mod_time'] = datetime.utcfromtimestamp(os.path.getmtime(f))

                # Plugin may accept sample_sets as input
                try:
                    plugin['sample_set_input'] = getattr(plugin['class'], 'sample_set_input')
                except AttributeError:
                    plugin['sample_set_input'] = False

                # Now pass the plugin back to workbench
                self.plugin_callback(plugin)
def add_plugin ( self , f ) : if f . endswith ( '.py' ) : plugin_name = os . path . splitext ( os . path . basename ( f ) ) [ 0 ] if plugin_name in sys . modules : try : handler = reload ( sys . modules [ plugin_name ] ) print '\t- %s %sRELOAD%s' % ( plugin_name , color . Yellow , color . Normal ) except ImportError , error : print 'Failed to import plugin: %s (%s)' % ( plugin_name , error ) return else : try : handler = __import__ ( plugin_name , globals ( ) , locals ( ) , [ ] , - 1 ) except ImportError , error : print 'Failed to import plugin: %s (%s)' % ( plugin_name , error ) return plugin = self . validate ( handler ) print '\t- %s %sOK%s' % ( plugin_name , color . Green , color . Normal ) if plugin : plugin [ 'name' ] = plugin_name plugin [ 'dependencies' ] = plugin [ 'class' ] . dependencies plugin [ 'docstring' ] = plugin [ 'class' ] . __doc__ plugin [ 'mod_time' ] = datetime . utcfromtimestamp ( os . path . getmtime ( f ) ) try : plugin [ 'sample_set_input' ] = getattr ( plugin [ 'class' ] , 'sample_set_input' ) except AttributeError : plugin [ 'sample_set_input' ] = False self . plugin_callback ( plugin )
Adding and verifying plugin.

        Args:
            f: the filepath for the plugin.