Exemple #1
0
def plugin_init():
    """It is a chicken egg situation in pluggdapp's component system.

    * The plugin class objects are not available until the classes are fully
      parsed and loaded.
    * PluginMeta._implementers need to save plugin class object based on
      the plugin class's implements() calls which happens during class
      loading.

    Additionally,

    * Every plugin class object's `_interfs` attribute is populated with a
      list of interfaces implemented by the class.

    Hence the automagic of plugin system is supplemented by a call to this
    function, once during startup, after all pluggdapps packages are loaded.
    """
    from pluggdapps import papackages

    # Re-initialize _interfs list for each plugin class, so that plugin_init()
    # will not create duplicate entries.
    [
        setattr(info['cls'], '_interfs', [])
        for _, info in PluginMeta._pluginmap.items()
    ]

    # Optimize _implementers and _interfs for query_*
    d = {}
    for i, pmap in PluginMeta._implementers.items():
        x = {}
        for nm in pmap:
            cls = PluginMeta._pluginmap[nm]['cls']
            x[nm] = cls
            cls._interfs.append(i)
        d[i] = x
    # All plugins, because they derive from :class:`Plugin`, implement
    # ISettings interface.
    d[ISettings] = {
        nm: info['cls']
        for nm, info in PluginMeta._pluginmap.items()
    }
    PluginMeta._implementers = d

    # Compute asset-specification for all interfaces and plugins
    for nm, info in PluginMeta._interfmap.items():
        assetspec = h.asset_spec_from_abspath(info['file'], papackages)
        if assetspec:
            info['assetspec'] = assetspec

    for nm, info in PluginMeta._pluginmap.items():
        assetspec = h.asset_spec_from_abspath(info['file'], papackages)
        if assetspec:
            info['assetspec'] = assetspec
Exemple #2
0
def plugin_init():
    """It is a chicken egg situation in pluggdapp's component system.

    * The plugin class objects are not available until the classes are fully
      parsed and loaded.
    * PluginMeta._implementers need to save plugin class object based on
      the plugin class's implements() calls which happens during class
      loading.

    Additionally,

    * Every plugin class object's `_interfs` attribute is populated with a
      list of interfaces implemented by the class.

    Hence the automagic of plugin system is supplemented by a call to this
    function, once during startup, after all pluggdapps packages are loaded.
    """
    from pluggdapps import papackages

    # Re-initialize _interfs list for each plugin class, so that plugin_init()
    # will not create duplicate entries.
    [ setattr(info['cls'], '_interfs', []) 
            for _, info in PluginMeta._pluginmap.items() ]

    # Optimize _implementers and _interfs for query_*
    d = {}
    for i, pmap in PluginMeta._implementers.items() :
        x = {}
        for nm in pmap :
            cls = PluginMeta._pluginmap[nm]['cls']
            x[nm] = cls
            cls._interfs.append(i)
        d[i] = x
    # All plugins, because they derive from :class:`Plugin`, implement
    # ISettings interface.
    d[ ISettings ] = { nm : info['cls'] 
                       for nm, info in PluginMeta._pluginmap.items() }
    PluginMeta._implementers = d

    # Compute asset-specification for all interfaces and plugins
    for nm, info in PluginMeta._interfmap.items() :
        assetspec = h.asset_spec_from_abspath( info['file'], papackages )
        if assetspec :
            info['assetspec'] = assetspec
        
    for nm, info in PluginMeta._pluginmap.items() :
        assetspec = h.asset_spec_from_abspath( info['file'], papackages )
        if assetspec :
            info['assetspec'] = assetspec
Exemple #3
0
    def _init( self, file=None, text=None ):
        """Reinitialize the compiler object to compile a different template
        script."""
        from pluggdapps import papackages
        self.ttlloc = TemplateLookup( self, file, text )
        self.encoding = self.ttlloc.encoding
        self.ttlfile = self.ttlloc.ttlfile
        self.ttltext = self.ttlloc.ttltext
        self.pyfile = self.ttlloc.pyfile
        
        # Compute the module name from ttlfile.
        asset = h.asset_spec_from_abspath( self.ttlfile, papackages )
        if asset :
            n = '.'.join(asset.split(':', 1)[1].split( os.path.sep ))
            self.modulename = n[:-4] if n.endswith('.ttl') else n
        else :
            n = '.'.join(self.ttlfile.split( os.path.sep ))
            self.modulename = n[:-4] if n.endswith('.ttl') else n

        self.mach._init( self.ttlfile )
        self.igen._init()

        # Check whether pyfile is older than the ttl file. In debug mode is is
        # always re-generated.
        self.pytext = ''
        if self['debug'] == False :
            if self.ttlfile and isfile( self.ttlfile ) :
                if self.pyfile and isfile( self.pyfile ) :
                    m1 = os.stat( self.ttlfile ).st_mtime
                    m2 = os.stat( self.pyfile ).st_mtime
                    if m1 <= m2 :
                        self.pytext = open( self.pyfile ).read()
    def _init(self, file=None, text=None):
        """Reinitialize the compiler object to compile a different template
        script."""
        from pluggdapps import papackages
        self.ttlloc = TemplateLookup(self, file, text)
        self.encoding = self.ttlloc.encoding
        self.ttlfile = self.ttlloc.ttlfile
        self.ttltext = self.ttlloc.ttltext
        self.pyfile = self.ttlloc.pyfile

        # Compute the module name from ttlfile.
        asset = h.asset_spec_from_abspath(self.ttlfile, papackages)
        if asset:
            n = '.'.join(asset.split(':', 1)[1].split(os.path.sep))
            self.modulename = n[:-4] if n.endswith('.ttl') else n
        else:
            n = '.'.join(self.ttlfile.split(os.path.sep))
            self.modulename = n[:-4] if n.endswith('.ttl') else n

        self.mach._init(self.ttlfile)
        self.igen._init()

        # Check whether pyfile is older than the ttl file. In debug mode is is
        # always re-generated.
        self.pytext = ''
        if self['debug'] == False:
            if self.ttlfile and isfile(self.ttlfile):
                if self.pyfile and isfile(self.pyfile):
                    m1 = os.stat(self.ttlfile).st_mtime
                    m2 = os.stat(self.pyfile).st_mtime
                    if m1 <= m2:
                        self.pytext = open(self.pyfile).read()