Ejemplo n.º 1
0
    def boot(cls, baseini, *args, **kwargs):
        """Parse ``[mountloc]`` section for application-wise configuration
        settings and return a fresh instance of :class:`Webapps` class.
        """
        pa = super().boot(baseini, *args, **kwargs)
        pa.webapps = {}
        pa.appurls = {}

        appsettings = pa._mountapps()

        netpaths = [instkey[1] for instkey, appsett in appsettings.items()]
        pa.configdb.dbinit(netpaths=netpaths)

        # Mount webapp instances for subdomains and scripts.
        for instkey, appsett in appsettings.items():
            appsec, netpath, config = instkey

            # Instantiate the IWebAPP plugin here for each `instkey`
            appname = h.sec2plugin(appsec)
            webapp = pa.qp(pa, instkey, IWebApp, appname, appsett)
            webapp.appsettings = appsett
            # Update with backend configuration.
            [webapp.appsettings[section].update(d) for section, d in pa.configdb.config(netpath=netpath).items()]

            webapp.instkey, webapp.netpath = instkey, None
            pa.webapps[instkey] = webapp
            pa.netpaths[netpath] = webapp
            pa.appurls[instkey] = webapp.baseurl = pa._make_appurl(instkey)

            pa._app_resolve_cache[h.parse_netpath(netpath)] = webapp

            # Resolution mapping for web-applications
            webapp.netpath = netpath

        return pa
Ejemplo n.º 2
0
 def start(self):
     """Boot all loaded application. Web applicationss are loaded when the
     system is booted via boot() call. Apps are booted only when an
     explicit call is made to this method."""
     super().start()
     appnames = []
     for instkey, webapp in self.webapps.items():
         appsec, netpath, configini = instkey
         self.loginfo("Booting application %r ..." % netpath)
         webapp.startapp()
         appnames.append(h.sec2plugin(appsec))
     return appnames
Ejemplo n.º 3
0
 def start(self):
     """Boot all loaded application. Web applicationss are loaded when the
     system is booted via boot() call. Apps are booted only when an
     explicit call is made to this method."""
     super().start()
     appnames = []
     for instkey, webapp in self.webapps.items():
         appsec, netpath, configini = instkey
         self.loginfo("Booting application %r ..." % netpath)
         webapp.startapp()
         appnames.append(h.sec2plugin(appsec))
     return appnames
Ejemplo n.º 4
0
 def _ls_plugin(self, args):
     from pluggdapps.web.webapp import WebApp
     for instkey, webapp in self.pa.webapps.items():
         appsec, netpath, config = instkey
         if h.sec2plugin(appsec) == args.plugin:
             print("Mounted app %r" % appsec)
             print("  Instkey   : ", end='')
             pprint(webapp.instkey, indent=4)
             print("  Subdomain : ", webapp.netpath)
             print("  Router    : ", webapp.router)
             print("Application settings")
             pprint(webapp.appsettings, indent=4)
             print()
Ejemplo n.º 5
0
def get_html_config( request, c ):
    """Full page to configure application -> sections for all loaded
    applications."""
    response = request.response
    common_context( request, c )
    netpath = request.matchdict['netpath']
    section = request.matchdict['section']
    c['pluginname'] = plugin = h.sec2plugin( section )

    # URL.
    c['url_putconfig'] = \
        request.pathfor( 'updateconfig', netpath=netpath, section=section )
    
    #Context
    c['describe'] = h.conf_descriptionfor( plugin )
    # Gather ConfigDict for DEFAULT section, as a fall back in .ttl file.
    c['DEFAULT'] = DEFAULT()

    # Section settings, TODO : What to do about `here` variables in section.
    setts = deepcopy( h.section_settings( request.pa, netpath, section ))
    c['secsetts'] = ( c['describe'].__doc__, setts )

    # Breadcrumbs
    c['navigate'] = [ (netpath, None), (section, None) ]
    appmenu = [
        ( 'platform',
          request.pathfor('htmlconfig1', netpath='platform', section='DEFAULT')
        )
    ]
    for s in request.pa.netpaths :
        appmenu.append(
            ( s,
              request.pathfor('htmlconfig1', netpath=s, section='DEFAULT')
            ))

    secmenu = []
    for pn in h.netpath_settings( request.pa, netpath ).keys() :
        if pn in ['mountloc'] : continue
        name = h.plugin2sec( pn )
        secmenu.append(
            ( name,
              request.pathfor( 'htmlconfig1', netpath=netpath, section=name )
            ))

    c['crumbsmenu'] = { netpath : appmenu, section : secmenu }

    html = response.render(
                request, c, file='pluggdapps:webadmin/templates/config.ttl' )
    response.write( html )
    response.flush( finishing=True )
Ejemplo n.º 6
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
Ejemplo n.º 7
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
Ejemplo n.º 8
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])
Ejemplo n.º 9
0
    def boot(cls, baseini, *args, **kwargs):
        """Parse ``[mountloc]`` section for application-wise configuration
        settings and return a fresh instance of :class:`Webapps` class.
        """
        pa = super().boot(baseini, *args, **kwargs)
        pa.webapps = {}
        pa.appurls = {}

        appsettings = pa._mountapps()

        netpaths = [instkey[1] for instkey, appsett in appsettings.items()]
        pa.configdb.dbinit(netpaths=netpaths)

        # Mount webapp instances for subdomains and scripts.
        for instkey, appsett in appsettings.items():
            appsec, netpath, config = instkey

            # Instantiate the IWebAPP plugin here for each `instkey`
            appname = h.sec2plugin(appsec)
            webapp = pa.qp(pa, instkey, IWebApp, appname, appsett)
            webapp.appsettings = appsett
            # Update with backend configuration.
            [
                webapp.appsettings[section].update(d)
                for section, d in pa.configdb.config(netpath=netpath).items()
            ]

            webapp.instkey, webapp.netpath = instkey, None
            pa.webapps[instkey] = webapp
            pa.netpaths[netpath] = webapp
            pa.appurls[instkey] = webapp.baseurl = pa._make_appurl(instkey)

            pa._app_resolve_cache[h.parse_netpath(netpath)] = webapp

            # Resolution mapping for web-applications
            webapp.netpath = netpath

        return pa
Ejemplo n.º 10
0
 def _ls_settings(self, args):
     sett = deepcopy(self.pa.settings)
     if args._ls_settings.startswith('spec'):
         print("Special sections")
         pprint({k: sett.pop(k, {})
                 for k in SPECIAL_SECS + ['DEFAULT']},
                indent=2)
     elif args._ls_settings.startswith('plug'):
         print("Plugin sections")
         pprint({k: sett[k]
                 for k in sett if h.is_plugin_section(k)},
                indent=2)
     elif args._ls_settings.startswith('wa') and args.plugin:
         for instkey, webapp in getattr(self.pa, 'webapps', {}).items():
             appsec, netpath, instconfig = instkey
             if h.sec2plugin(appsec) == args.plugin:
                 print("Settings for %r" % (instkey, ))
                 pprint(webapp.appsettings, indent=2)
                 print()
     elif args._ls_settings.startswith('def') and args.plugin:
         print("Default settings for plugin %r" % args.plugin)
         defaultsett = pa.defaultsettings()
         pprint(defaultsett().get(h.plugin2sec(args.plugin), {}), indent=2)
Ejemplo n.º 11
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])