Beispiel #1
0
def defaultsettings():
    """By now it is expected that all interface specs and plugin definitions
    would have been loaded by loading packages implementing them and
    pluggdapps' plugin meta-classing. This function will collect their default
    settings and return them as a tuple of two dictionaries.

        (appdefaults, plugindefaults)

    appdefaults,
        { "webapp:<appname>" : default_settings,
           ...
        }

    plugindefaults
        { "plugin:<pluginname>" : default_settings,
           ...
        }
    """
    from pluggdapps.plugin import PluginMeta, applications

    # Default settings for applications and plugins.
    appdefaults, plugindefaults = {}, {}
    appnames = applications()

    # Fetch all the default-settings for loaded plugins using `ISettings`
    # interface. Plugin inheriting from other plugins will override its base's
    # default_settings() in cls.mro() order.
    for info in PluginMeta._pluginmap.values() :
        name = info['name']
        bases = reversed( info['cls'].mro() )
        sett = {}
        [ sett.update( dict( b.default_settings().items() )) for b in bases ]
        if name in appnames :
            appdefaults[ app2sec(name) ] = sett
        else :
            plugindefaults[ plugin2sec(name) ] = sett

    # Validation check
    appnames_ = sorted( list( map( app2sec, appnames )))
    if appnames_ != sorted( list( appdefaults.keys() )) :
        raise Exception( "appnames and appdefaults do not match" )
    return appdefaults, plugindefaults
Beispiel #2
0
    # Override plugin's package default settings with [DEFAULT] settings.
    plugindefaults = { key : h.mergedict(defaultsett1, sett, defaultsett2)
                       for key, sett plugindefaults.items() }
    settings.update( deepcopy( plugindefaults ))

    # Create instance-wise full settings dictionary.
    for instkey, values in instdef.items() :
        appsec, t, mountname, config = instkey
        settings[instkey] = { appsec : h.mergedict( defaultsett1,
                                                    values[appsec], 
                                                    defaultsett2 ) }
        settings[instkey].update( deepcopy( plugindefaults ))

    # Validate application sections and plugin sections in master ini file
    appnames = applications()
    pluginms = pluginnames()
    for secname in cp.sections() :
        if is_app_section(secname) and sec2app(secname) not in appnames :
            raise Exception( "%r web-app is not found" % secname )
        elif is_plugin_section(secname) and sec2plugin(secname) not in pluginms:
            raise Exception( "%r plugin is not found" % secname )

    # Load web-app section configuration in master ini file into app instance
    # settings
    for instkey, instsett in settings.items() :
        if not isinstance( instkey, tuple ) : continue
        # Only application settings
        appsec, t, mountname, config = instkey
        if cp.has_section( appsec ) :
            instsett[appsec].update( dict( cp.items( appsec, vars=_vars )))