예제 #1
0
    def _loadini(self, baseini, defaultsett):
        """Parse master ini configuration file ``baseini`` and ini files
        refered by `baseini`. Construct a dictionary of settings for special
        sections and plugin sections."""
        from pluggdapps.plugin import pluginnames, plugin_info

        if not baseini or (not isfile(baseini)):
            return deepcopy(defaultsett)

        # Initialize return dictionary.
        settings = {}

        # context for parsing ini files.
        _vars = {"here": abspath(dirname(baseini))}

        # Read master ini file.
        cp = SafeConfigParser()
        cp.read(baseini)

        # [DEFAULT] overriding global def.
        s = deepcopy(defaultsett["DEFAULT"])
        s.update(dict(cp.defaults()))
        settings["DEFAULT"] = normalize_defaults(s)

        # [pluggdapps]
        s = deepcopy(defaultsett["pluggdapps"])
        if cp.has_section("pluggdapps"):
            s.update(dict(cp.items("pluggdapps", vars=_vars)))
            s.pop("here", None)  # TODO : how `here` gets populated ??
            settings["pluggdapps"] = normalize_pluggdapps(s)

        # Override plugin's package default settings with [DEFAULT] settings.
        for pluginsec, sett in defaultsett.items():
            if not pluginsec.startswith("plugin:"):
                continue
            sett = h.mergedict(sett, settings["DEFAULT"])
            if cp.has_section(pluginsec):
                sett.update(dict(cp.items(pluginsec, vars=_vars)))
                sett.pop("here", None)  # TODO : how `here` ??
            cls = plugin_info(h.sec2plugin(pluginsec))["cls"]
            for b in reversed(cls.mro()):
                if hasattr(b, "normalize_settings"):
                    sett = b.normalize_settings(sett)
            settings[pluginsec] = sett
        return settings
예제 #2
0
    def _loadini(self, baseini, defaultsett):
        """Parse master ini configuration file ``baseini`` and ini files
        refered by `baseini`. Construct a dictionary of settings for special
        sections and plugin sections."""
        from pluggdapps.plugin import pluginnames, plugin_info

        if not baseini or (not isfile(baseini)):
            return deepcopy(defaultsett)

        # Initialize return dictionary.
        settings = {}

        # context for parsing ini files.
        _vars = {'here': abspath(dirname(baseini))}

        # Read master ini file.
        cp = SafeConfigParser()
        cp.read(baseini)

        # [DEFAULT] overriding global def.
        s = deepcopy(defaultsett['DEFAULT'])
        s.update(dict(cp.defaults()))
        settings['DEFAULT'] = normalize_defaults(s)

        # [pluggdapps]
        s = deepcopy(defaultsett['pluggdapps'])
        if cp.has_section('pluggdapps'):
            s.update(dict(cp.items('pluggdapps', vars=_vars)))
            s.pop('here', None)  # TODO : how `here` gets populated ??
            settings['pluggdapps'] = normalize_pluggdapps(s)

        # Override plugin's package default settings with [DEFAULT] settings.
        for pluginsec, sett in defaultsett.items():
            if not pluginsec.startswith('plugin:'): continue
            sett = h.mergedict(sett, settings['DEFAULT'])
            if cp.has_section(pluginsec):
                sett.update(dict(cp.items(pluginsec, vars=_vars)))
                sett.pop('here', None)  # TODO : how `here` ??
            cls = plugin_info(h.sec2plugin(pluginsec))['cls']
            for b in reversed(cls.mro()):
                if hasattr(b, 'normalize_settings'):
                    sett = b.normalize_settings(sett)
            settings[pluginsec] = sett
        return settings
예제 #3
0
    def _loadinstance(self, appsett, instanceini):
        """Load configuration settings for a web application's instance."""
        from pluggdapps.plugin import plugin_info
        _vars = {'here': abspath(dirname(instanceini))}
        cp = SafeConfigParser()
        cp.read(instanceini)

        # Update appsett with [DEFAULT] section of instanceini
        defaultsett = normalize_defaults(dict(cp.defaults()))
        appsett['DEFAULT'].update(defaultsett)
        [sett.update(appsett['DEFAULT']) for key, sett in appsett.items()]

        # Update plugin sections in appsett from instanceini
        for sec in cp.sections():
            if not sec.startswith('plugin:'): continue
            sett = dict(cp.items(sec, vars=_vars))
            sett.pop('here', None)  # TODO : how `here` gets populated ??
            appsett[sec].update(sett)
            cls = plugin_info(h.sec2plugin(sec))['cls']
            for b in reversed(cls.mro()):
                if hasattr(b, 'normalize_settings'):
                    appsett[sec] = b.normalize_settings(appsett[sec])
예제 #4
0
    def _loadinstance(self, appsett, instanceini):
        """Load configuration settings for a web application's instance."""
        from pluggdapps.plugin import plugin_info

        _vars = {"here": abspath(dirname(instanceini))}
        cp = SafeConfigParser()
        cp.read(instanceini)

        # Update appsett with [DEFAULT] section of instanceini
        defaultsett = normalize_defaults(dict(cp.defaults()))
        appsett["DEFAULT"].update(defaultsett)
        [sett.update(appsett["DEFAULT"]) for key, sett in appsett.items()]

        # Update plugin sections in appsett from instanceini
        for sec in cp.sections():
            if not sec.startswith("plugin:"):
                continue
            sett = dict(cp.items(sec, vars=_vars))
            sett.pop("here", None)  # TODO : how `here` gets populated ??
            appsett[sec].update(sett)
            cls = plugin_info(h.sec2plugin(sec))["cls"]
            for b in reversed(cls.mro()):
                if hasattr(b, "normalize_settings"):
                    appsett[sec] = b.normalize_settings(appsett[sec])