Package entropy :: Package spm :: Package plugins :: Module factory

Source Code for Module entropy.spm.plugins.factory

 1  # -*- coding: utf-8 -*- 
 2  """ 
 3   
 4      @author: Fabio Erculiani <[email protected]> 
 5      @contact: [email protected] 
 6      @copyright: Fabio Erculiani 
 7      @license: GPL-2 
 8   
 9      B{Entropy Source Package Manager Plugins factory module}. 
10   
11  """ 
12  from entropy.core import EntropyPluginFactory 
13  from entropy.core.settings.base import SystemSettings 
14  from entropy.spm.plugins.skel import SpmPlugin 
15  import entropy.spm.plugins.interfaces as plugs 
16   
17  _settings = SystemSettings() 
18  _USER_PLUG = _settings['system'].get('spm_backend') 
19   
20  FACTORY = EntropyPluginFactory(SpmPlugin, plugs, 
21      default_plugin_name = _USER_PLUG) 
22   
23  get_available_plugins = FACTORY.get_available_plugins 
24   
25 -def get_default_class():
26 """ 27 Return default Source Package Manager plugin class. 28 29 @return: default Source Package Manager plugin class 30 @raise SystemError: if no default plugin class has been specified. 31 This usually means a programming error. 32 """ 33 fallback_used = False 34 myplugs = get_available_plugins() 35 if _USER_PLUG is not None: 36 user_plugin = myplugs.get(_USER_PLUG) 37 if user_plugin is not None: 38 return user_plugin 39 fallback_used = True 40 41 for plug_id in sorted(myplugs): 42 plug_class = myplugs[plug_id] 43 if plug_class.IS_DEFAULT: 44 if fallback_used: 45 import warnings 46 warnings.warn("%s: %s" % ( 47 "User configured Source Package Manager Plugin not available, " 48 "using fallback", plug_id,)) 49 return plug_class 50 51 raise SystemError("no SPM default plugin configured")
52
53 -def get_default_instance(output_interface):
54 """ 55 Return the currently configured Entropy SPM interface instance. 56 57 @param output_interface: Entropy Output Interface instance 58 @type output_interface: entropy.output.TextInterface based instance 59 @return: currently selected SPM interface 60 @rtype: entropy.spm.plugins.skel.SpmPlugin based instance 61 """ 62 spm_class = get_default_class() 63 return spm_class(output_interface)
64