Back to index

obnam  1.1
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
obnamlib.pluginmgr.PluginManager Class Reference

List of all members.

Public Member Functions

def __init__
def plugin_files
def plugins
def __getitem__
def find_plugin_files
def load_plugins
def is_older
def load_plugin_file
def compatible_version
def parse_version
def enable_plugins
def disable_plugins

Public Attributes

 locations
 plugin_arguments
 plugin_keyword_arguments
 application_version

Static Public Attributes

string suffix = '_plugin.py'

Private Attributes

 _plugins
 _plugin_files

Detailed Description

Manage plugins.

This class finds and loads plugins, and keeps a list of them that
can be accessed in various ways.

The locations are set via the locations attribute, which is a list.

When a plugin is loaded, an instance of its class is created. This
instance is initialized using normal and keyword arguments specified
in the plugin manager attributes plugin_arguments and 
plugin_keyword_arguments.

The version of the application using the plugin manager is set via
the application_version attribute. This defaults to '0.0.0'.

Definition at line 116 of file pluginmgr.py.


Constructor & Destructor Documentation

Definition at line 137 of file pluginmgr.py.

00137 
00138     def __init__(self):
00139         self.locations = []
00140         self._plugins = None
00141         self._plugin_files = None
00142         self.plugin_arguments = []
00143         self.plugin_keyword_arguments = {}
00144         self.application_version = '0.0.0'


Member Function Documentation

Definition at line 157 of file pluginmgr.py.

00157 
00158     def __getitem__(self, name):
00159         for plugin in self.plugins:
00160             if plugin.name == name:
00161                 return plugin
00162         raise KeyError('Plugin %s is not known' % name)

Here is the call graph for this function:

def obnamlib.pluginmgr.PluginManager.compatible_version (   self,
  required_application_version 
)
Check that the plugin is version-compatible with the application.

This checks the plugin's required_application_version against
the declared application version and returns True if they are
compatible, and False if not.

Definition at line 224 of file pluginmgr.py.

00224 
00225     def compatible_version(self, required_application_version):
00226         '''Check that the plugin is version-compatible with the application.
00227         
00228         This checks the plugin's required_application_version against
00229         the declared application version and returns True if they are
00230         compatible, and False if not.
00231         
00232         '''
00233 
00234         req = self.parse_version(required_application_version)
00235         app = self.parse_version(self.application_version)
00236         
00237         return app[0] == req[0] and app >= req

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.pluginmgr.PluginManager.disable_plugins (   self,
  plugins = None 
)
Disable all or selected plugins.

Definition at line 249 of file pluginmgr.py.

00249 
00250     def disable_plugins(self, plugins=None):
00251         '''Disable all or selected plugins.'''
00252         
00253         for plugin in plugins or self.plugins:
00254             plugin.disable_wrapper()
00255 

Here is the call graph for this function:

def obnamlib.pluginmgr.PluginManager.enable_plugins (   self,
  plugins = None 
)
Enable all or selected plugins.

Definition at line 243 of file pluginmgr.py.

00243 
00244     def enable_plugins(self, plugins=None):
00245         '''Enable all or selected plugins.'''
00246         
00247         for plugin in plugins or self.plugins:
00248             plugin.enable_wrapper()

Here is the call graph for this function:

Find files that may contain plugins.

This finds all files named *_plugin.py in all locations.
The returned list is sorted.

Definition at line 163 of file pluginmgr.py.

00163 
00164     def find_plugin_files(self):
00165         '''Find files that may contain plugins.
00166         
00167         This finds all files named *_plugin.py in all locations.
00168         The returned list is sorted.
00169         
00170         '''
00171         
00172         pathnames = []
00173         
00174         for location in self.locations:
00175             try:
00176                 basenames = os.listdir(location)
00177             except os.error:
00178                 continue
00179             for basename in basenames:
00180                 s = os.path.join(location, basename)
00181                 if s.endswith(self.suffix) and os.path.exists(s):
00182                     pathnames.append(s)
00183         
00184         return sorted(pathnames)

Here is the caller graph for this function:

def obnamlib.pluginmgr.PluginManager.is_older (   self,
  version1,
  version2 
)
Is version1 older than version2?

Definition at line 201 of file pluginmgr.py.

00201 
00202     def is_older(self, version1, version2):
00203         '''Is version1 older than version2?'''
00204         return self.parse_version(version1) < self.parse_version(version2)

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.pluginmgr.PluginManager.load_plugin_file (   self,
  pathname 
)
Return plugin classes in a plugin file.

Definition at line 205 of file pluginmgr.py.

00205 
00206     def load_plugin_file(self, pathname):
00207         '''Return plugin classes in a plugin file.'''
00208 
00209         name, ext = os.path.splitext(os.path.basename(pathname))
00210         f = file(pathname, 'r')
00211         module = imp.load_module(name, f, pathname, 
00212                                  ('.py', 'r', imp.PY_SOURCE))
00213         f.close()
00214         
00215         plugins = []
00216         for dummy, member in inspect.getmembers(module, inspect.isclass):
00217             if issubclass(member, Plugin):
00218                 p = member(*self.plugin_arguments,
00219                            **self.plugin_keyword_arguments)
00220                 if self.compatible_version(p.required_application_version):
00221                     plugins.append(p)
00222         
00223         return plugins

Here is the call graph for this function:

Here is the caller graph for this function:

Load plugins from all plugin files.

Definition at line 185 of file pluginmgr.py.

00185 
00186     def load_plugins(self):
00187         '''Load plugins from all plugin files.'''
00188         
00189         plugins = dict()
00190         
00191         for pathname in self.plugin_files:
00192             for plugin in self.load_plugin_file(pathname):
00193                 if plugin.name in plugins:
00194                     p = plugins[plugin.name]
00195                     if self.is_older(p.version, plugin.version):
00196                         plugins[plugin.name] = plugin
00197                 else:
00198                     plugins[plugin.name] = plugin
00199 
00200         return plugins.values()

Here is the call graph for this function:

Here is the caller graph for this function:

def obnamlib.pluginmgr.PluginManager.parse_version (   self,
  version 
)
Parse a string represenation of a version into list of ints.

Definition at line 238 of file pluginmgr.py.

00238 
00239     def parse_version(self, version):
00240         '''Parse a string represenation of a version into list of ints.'''
00241         
00242         return [int(s) for s in version.split('.')]

Here is the caller graph for this function:

Definition at line 146 of file pluginmgr.py.

00146 
00147     def plugin_files(self):
00148         if self._plugin_files is None:
00149             self._plugin_files = self.find_plugin_files()
00150         return self._plugin_files

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 152 of file pluginmgr.py.

00152 
00153     def plugins(self):
00154         if self._plugins is None:
00155             self._plugins = self.load_plugins()
00156         return self._plugins

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 140 of file pluginmgr.py.

Definition at line 139 of file pluginmgr.py.

Definition at line 143 of file pluginmgr.py.

Definition at line 138 of file pluginmgr.py.

Definition at line 141 of file pluginmgr.py.

Definition at line 142 of file pluginmgr.py.

string obnamlib.pluginmgr.PluginManager.suffix = '_plugin.py' [static]

Definition at line 135 of file pluginmgr.py.


The documentation for this class was generated from the following file: