Package entropy :: Package core :: Class EntropyPluginFactory

Class EntropyPluginFactory

source code

Generic Entropy Components Plugin Factory (loader).

Instance Methods
 
__init__(self, base_plugin_class, plugin_package_module, default_plugin_name=None, fallback_plugin_name=None, egg_entry_point_group=None)
Entropy Generic Plugin Factory constructor.
source code
 
clear_cache(self)
Clear available plugins cache.
source code
dict
get_available_plugins(self)
Return currently available plugin classes.
source code
default plugin class given
get_default_plugin(self)
Return currently configured Entropy Plugin class.
source code
Method Details

__init__(self, base_plugin_class, plugin_package_module, default_plugin_name=None, fallback_plugin_name=None, egg_entry_point_group=None)
(Constructor)

source code 

Entropy Generic Plugin Factory constructor. MANDATORY: every plugin module/package(name) must end with _plugin suffix.

Base plugin classes must have the following class attributes set:

  • BASE_PLUGIN_API_VERSION: integer describing API revision in use in class

Subclasses of Base plugin class must have the following class attributes set:

  • PLUGIN_API_VERSION: integer describing the currently implemented plugin API revision, must match with BASE_PLUGIN_API_VERSION above otherwise plugin won't be loaded and a warning will be printed.

Moreover, plugin classes must be "Python new-style classes", otherwise parser won't be able to determine if classes have subclasses and thus pick the proper object (one with no subclasses!!). See: http://www.python.org/doc/newstyle -- in other words, you have to inherit the built-in "object" class (yeah, it's called object). So, even if using normal classes could work, if you start doing nasty things (nested inherittance of plugin classes), behaviour cannot be guaranteed. If it's not clear, let me repeat once again, valid plugin classes must not have subclasses around! Think about it, it's an obvious thing.

If plugin class features a "PLUGIN_DISABLED" class attribute with a boolean value of True, such plugin will be ignored.

If egg_entry_point_group is specified, Python Egg support is enabled and classes are loaded via this infrastructure. NOTE: if egg_entry_point_group is set, you NEED the setuptools package.

Parameters:
  • base_plugin_class (class) - Base class that valid plugin classes must inherit from.
  • plugin_package_module (Python module) - every plugin repository must work as Python package, the value of this argument must be a valid Python package module that can be scanned looking for valid Entropy Plugin classes.
  • default_plugin_name (string) - identifier of the default plugin to load
  • fallback_plugin_name (string) - identifier of the fallback plugin to load if default is not available
  • egg_entry_point_group (string) - valid Python Egg entry point group, in this case, Python Egg support is used
Raises:
  • AttributeError - when passed plugin_package_module is not a valid Python package module

clear_cache(self)

source code 

Clear available plugins cache. When calling get_available_plugins() module object is parsed again.

get_available_plugins(self)

source code 

Return currently available plugin classes. Note: Entropy plugins can either be Python packages or modules and their name MUST end with PluginFactory._PLUGIN_SUFFIX ("_plugin").

Returns: dict
dictionary composed by Entropy plugin id as key and Entropy Python module as value

get_default_plugin(self)

source code 

Return currently configured Entropy Plugin class.

Returns: default plugin class given
Entropy plugin class
Raises:
  • KeyError - if default plugin is not set or not found