-í
67ýFc       s_     d  Z  
  d k Z  d k Z  d k Z  d k Z  d f  d „  ƒ  YZ Û d Z d S(   sá  
Provides a plugin facility.  Plugins are simply modules that can loaded
dynamically at run time.  Since Python is an interpreted scripting language
dynamic code loading is easy.  However, this module provides an interface
to do request loading (and reloading if file is replaced).  It also provides
an interface to request a module from a string name, an interface to 
query whether or not a named plugin has been loaded, and an interface for
querying the list of loaded plugins.
Ns   PluginManagerc      s†     d d „ Z   d „  Z 5 d „  Z K d „  Z Y d „  Z i d „  Z v d „  Z ˆ f  d	 „ Z ¦ f  d
 „ Z É d „  Z	 RS(   Ns   pluginsc    s+     | |  _  | |  _  h  |  _ d  S(   N(   s
   pluginRoots   selfs   _roots	   nameSpaces
   _nameSpaces   _plugins(   s   selfs
   pluginRoots	   nameSpace(    (    s   PluginManager.pys   __init__ s   c    s    t  }	  d }  d d t i f d d t i f g } # x¡ | D# ]– } $ | \ } } }
 % d |  i | | f } & t i i | ƒ o
 ' qF n ) t i i | ƒ } * | | j o + | } , | | | f }	 n qF W. |	 t  j o / t d |  i | f ‚ n 2 |	 Sd  S(   Ni    s   pys   rs   pycs   rbs   %s/%s.%ss   cannot find plugin %s/%s(   s   Nones   fdescs   ftimes   imps	   PY_SOURCEs   PY_COMPILEDs   fls   fattrs   exts   modes   types   selfs   _roots
   pluginNames   fnames   oss   paths   existss   getmtimes   fts   ImportError(   s   selfs
   pluginNames   fts   fls   fattrs   exts   ftimes   modes   fnames   fdescs   type(    (    s   PluginManager.pys   _getPluginFileAttribs s    		'
 	
	c    sÛ   5 8 | \ }	 }
 } : t i d | ƒ } ; d |  i	 | f } = t | |
 ƒ } > zn ? t i | | | | ƒ | _ A t | i t t ƒ } B | t j o C t | | ƒ n E | |  i | <Wd  G H | i ƒ  Xd  S(   Ns   mtimes   %s_%s(   s   fattrs   exts   modes   types	   twccommons   Datas   ftimes   plugins   selfs
   _nameSpaces
   pluginNames   qualifiedNames   opens   fnames   fs   imps   load_modules   mods   getattrs   FN_INITs   Nones   fns   applys
   initFnArgss   _pluginss   close(   s   selfs
   pluginNames   fnames   ftimes   fattrs
   initFnArgss   qualifiedNames   plugins   fs   exts   modes   types   fn(    (    s   PluginManager.pys   _loadPlugin5 s   c    sp   K L d } M y4 N |  i | } P | | i j o Q d } n Wn S t j
 o T d } n XV | Sd  S(   Ni    i   (   s   loads   selfs   _pluginss
   pluginNames   plugins   ftimes   mtimes   KeyError(   s   selfs
   pluginNames   ftimes   loads   plugin(    (    s   PluginManager.pys   _needsLoadingK s   	c    s5   Y c e t  | ƒ \ } } } f |  i | | ƒ Sd S(   sE  Determine if the plugin file needs to be loaded (or reloaded).

        Parameters:
        - pluginName: The name of the plugin of interest.

        Return: 
            Returns true if either the plugin has not been loaded or
            if the plugin file has been replaced since it was last 
            loaded.
        N(   s   _getPluginFileAttribss
   pluginNames   fnames   ftimes   fattrs   selfs   _needsLoading(   s   selfs
   pluginNames   ftimes   fnames   fattr(    (    s   PluginManager.pys   needsLoadingY s   
c    s   i q s |  i i | ƒ Sd S(   sÝ   Indicates whether the specified plugin has been loaded.

        Parameters:
        - pluginName: The name of the plugin of interest.

        Return: 
        Returns true if the plugin has already been loaded.
        N(   s   selfs   _pluginss   has_keys
   pluginName(   s   selfs
   pluginName(    (    s   PluginManager.pys   isPluginLoadedi s   c    s   v ƒ … |  i | i Sd S(   s¾  Gets a module object for the specified plugin.
        No attempt is made to load (or reload) the module.

        It is an error to call this func. for a plugin that 
        has not been previously loaded.  The isPluginLoaded()
        function can be used as a test.

        Parameters:
        - pluginName: The name of the plugin of interest.

        Return: 
        Returns a ref. to the module corresponding to the plugin name.
        N(   s   selfs   _pluginss
   pluginNames   mod(   s   selfs
   pluginName(    (    s   PluginManager.pys   getPluginModulev s   c    sR   ˆ ž   |  i | ƒ \ } } } ¡ |  i | | | | | ƒ £ |  i | i	 Sd S(   s   Load (or reload) the specified plugin.
        
        If the plugin module has not been loaded before, then it will 
        be imported.  Otherwise it will be reloaded.  No test is performed
        to determine if the plugin file has been updated.  See 
        retrievePlugin().

        If the module has defined a function named 'init', it will be
        exectued and initFnArgs specifies the parametes for the call.

        If the plugin cannot be loaded, then a corresponding exception 
        will be raised: IOError, ImportError, etc.

        Parameters:
        - pluginName: The name of the plugin of interest.
        - initFnArgs: Parameters passed when the plugin modules init fn
        is invoked.  Must be a tuple with an arity matching
        the number of params.  Defaults to no params (an empty tuple).

        Return: 
        Returns a ref. to the module corresponding to the plugin name.
        N(
   s   selfs   _getPluginFiles
   pluginNames   fnames   ftimes   fattrss   _loadPlugins
   initFnArgss   _pluginss   mod(   s   selfs
   pluginNames
   initFnArgss   fattrss   fnames   ftime(    (    s   PluginManager.pys
   loadPluginˆ s   c    su   ¦ º ½ |  i | ƒ \ } } } À |  i | | ƒ } Á | o  Â |  i | | | | | ƒ n Æ |  i
 | i Sd S(   so  Get a module object for the specified plugin.
        If the plugin module has not been loaded before, then it will 
        be imported.  If the plugin file is newer than the last time
        it was loaded, then it will be reloaded.

        If the module has defined a function named 'init', it will be
        exectued and initFnArgs specifies the parametes for the call.

        If the plugin cannot be loaded, then a corresponding exception 
        will be raised: IOError, ImportError, etc.

        Parameters:
        - pluginName: The name of the plugin of interest.
        - initFnArgs: Parameters passed when the plugin modules init fn
        is invoked.  Must be a tuple with an arity matching
        the number of params.  Defaults to no params (an empty tuple).

        Return: 
        Returns a ref. to the module corresponding to the plugin name.
        N(   s   selfs   _getPluginFileAttribss
   pluginNames   fnames   ftimes   fattrss   _needsLoadings   loads   _loadPlugins
   initFnArgss   _pluginss   mod(   s   selfs
   pluginNames
   initFnArgss   loads   fattrss   fnames   ftime(    (    s   PluginManager.pys   retrievePlugin¦ s   
 c    sM   É Ï Ò g  } Ó x- |  i i ƒ  DÓ ] } Ô | i | i ƒ q" W× | Sd S(   s£   Return a list of loaded plugins.

        Return: 
        Returns a list of references to the modules corresponding to all of
        the loaded plugins.
        N(   s   lists   selfs   _pluginss   valuess   ps   appends   mod(   s   selfs   ps   list(    (    s   PluginManager.pys
   getPluginsÉ s   	 	(
   s   __init__s   _getPluginFileAttribss   _loadPlugins   _needsLoadings   needsLoadings   isPluginLoadeds   getPluginModules
   loadPlugins   retrievePlugins
   getPlugins(    (    (    s   PluginManager.pys   PluginManager s   #s   init(   s   __doc__s   os.paths   oss   imps   syss	   twccommons   PluginManagers   FN_INIT(   s   syss   imps   FN_INITs	   twccommons   PluginManagers   os(    (    s   PluginManager.pys   ?
 s   É