Pluggdapps

Component system. Web framework. And more ...

platform – Platform.

This module along with the plugin module implement the component architechture. We expect that most of the logic written using pluggdapps will, one way or the other, be organised as plugins implementing one or more interface(s). This module,

  • provide platform base class in whose context plugins are instantiated.
  • responsible for parsing configuration parameters from various sources, aggregate them, make them avialable on plugin instances.
  • supply methods for logging error and warning messages.

The platform is instantiated by calling the Pluggdapps.boot() method.

Pre-boot and boot

Pluggdapps component system is always instantiated in the context of a platform defined by Pluggdapps class or by classes deriving from Pluggdapps.

Platform boots in two phase, first there is a pre-boot which more or less does every thing that is done during an actual boot and then the actual booting. Pre-booting is designed such a way that other pluggdapps-packages can take part in platform booting, such as loading dynamic plugins, pre-compiling template scripts etc ...

So here is what happens duing pre-booting,

  • all pluggdapps packages are loaded. But entry points are not called.
  • component system is initialized by calling pluggdapps.plugin.plugin_init().
  • a plain vanilla platform is instantiated using Pluggdapps.
  • configuration settings from .ini files and database backend, if available, is loaded.

Pre-booting comes to an end by a call to pluggdapps.callpackages() function, which in turn is responsible for re-loading pluggdapps packages and calling the package entry-point. Note that package re-loading is handle in the context of a plain vanilla platform instantiated during pre-boot phase.

During the actual boot phase, everything that was done in pre-booting phase is repeated. But the entire blue-print of interfaces and plugins from all the installed packages will be remembered in the context of, probably a more sophisticated Webapps, platform class. The choice of platform class depends on how the user started pluggdapps.

Configuration:

Like mentioned before, platform classes are responsible for handling configuration.

default configuration,

All plugins deriving from pluggdapps.plugin.Plugin class, which is how plugins are authored, will automatically implement ISettings interface. And configurable plugins must override ISettings interface methods. Refer to pluggdapps.plugin.ISettings interface to learn more about their interface methods. When platform is booted, default_settings from loaded plugins will be gathered and remembered.

ini file,

Platform is typically booted by supplying an ini-file regarded as master configuration file. Settings in this master configuration file will override package default settings for plugins and other special sections. Configuration sections not prefixed with plugin: is considered as special section which are explained further below.

Master configuration file can refer to other configuration file.

An example master configuration file,

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
[DEFAULT]
<option> = <value>
... = ...

[pluggdapps]
<option> = <value>
... = ...

[plugin:<pkgname>.<pluginname>]
<option> = <value>
... = ...

[...]

Special sections:

[DEFAULT] special section. Settings from this section is applicable to all configuration sections including plugins and referred configuration files. Semantic meaning of [DEFAULT] section is same as described by configparser module from python stdlib.

[pluggdapps] special section. Settings from this section is applicable to pluggdapps platform typically handled by Pluggdapps.

[mountloc] special section. Specific to web-framework (explained below) that is built on top of pluggdapps’ component system. Provides configuration settings on how to mount web-applications on web-url. Handled by Webapps platform class.

To learn more about backend store for configuration settings refer to module, pluggdapps.config.

Web-application platform:

Implemented by Webapps class (which derives from base platform class Pluggdapps), it can host any number web-application, and/or instance of same web-application in single python environment. Every web-application is a plugin implementing pluggdapps.interfaces.IWebApp interface. Like mentioned above every plugin gets instantiated in the context of a platform, and in this case, when plugins are instantiated by IWebApp plugin, either directly or indirectly, the instantiated plugins are automatically supplied with .webapp attribute which is now part of its context.

[mountloc] section and application wise ini file,

Web-applications can be mounted, hosted, on a netlocation and script-path (collectively called as netpath). This is configured under [mountloc] special section. While mounting web-applications under [mountloc] additional configuration files can be referred. Example [mountloc] section,

1
2
3
4
[mountloc]
pluggdapps.com/issues = <appname>, <ini-file>
tayra.pluggdapps.com/issues = <appname>, <ini-file>
tayra.pluggdapps.com/source = <appname>, <ini-file>

The lhs side is called netpath which typically contains subdomain, hostname and scripth-path. The rhs side is a tuple of two elements. First is the name of a IWebApp plugin and second is path to application configuration file.

Referred configuration files are exclusive to the scope of the mounted application, and shall not contain any special sections, except [DEFAULT], unless otherwise explicitly mentioned. When a plugin is instantiated in the context of a web-application, configuration settings from application-ini-file will override settings from the master-ini-file.

Module contents

class pluggdapps.platform.Pluggdapps(erlport=None)[source]

Bases: builtins.object

Platform class tying together pluggdapps platform, component architecture and configuration system. Do not instantiate this class directly, instead use the boot() method call (which is a classmethod) to start the platform.

inifile = None

Master Configuration file, absolute location.

settings = {}

Default settings for plugins, gathered from plugin-default settings, master configuration file and other backend stores, if any.

configdb = None

pluggdapps.interfaces.IConfigDB plugin instance.

classmethod boot(baseini, *args, **kwargs)[source]

Boot the platform using master configuration file baseini. Return a new instance of this class object. This is the only way to create a platform instance.

start()[source]

Expected to be called after boot(). Start pluggdapps.

shutdown()[source]

Reverse of start() method.

masterinit(plugin, *args, **kwargs)[source]

Call back function during plugin instantiation, from pluggdapps.plugin.PluginMeta class.

plugin,
Instantiated plugin. plugin is automatically populated with configuration settings.
args and kwargs,
are received from query_plugin’s args and kwargs.
config(**kwargs)[source]

Get or set configuration parameter for the platform. If no keyword arguments are supplied, will return platform-settings. This API is meant applications who wish to admister the platform configuration.

Keyword arguments,

section,
Section name to get or set config parameter. Optional.
name,
Configuration name to get or set for section. Optional.
value,
If present, this method was invoked for setting configuration name under section. Optional.
static query_plugins(pa, interface, *args, **kwargs)[source]

Use this API to query for plugins using the interface class it implements. Positional and keyword arguments will be used to instantiate the plugin object.

pa,
Platform object, whose base class is Pluggdapps.
interface,
pluggdapps.plugin.Interface class or canonical form of interface-name.
args and kwargs,
Positional and key-word arguments used to instantiate the plugin.

If settings key-word argument is present, it will be used to override default plugin settings. Returns a list of plugin instance implementing interface

static query_pluginr(pa, interface, pattern, *args, **kwargs)[source]

Use this API to query for plugins using the interface class it implements. Positional and keyword arguments will be used to instantiate the plugin object.

pa,
Platform object, whose base class is Pluggdapps.
interface,
pluggdapps.plugin.Interface class or canonical form of interface-name.
pattern,
Instantiate plugins who’s name match this pattern. Pattern can be any regular-expression.
args and kwargs,
Positional and key-word arguments used to instantiate the plugin.

If settings key-word argument is present, it will be used to override default plugin settings. Returns a list of plugin instance implementing interface

static query_plugin(pa, interface, name, *args, **kwargs)[source]

Same as queryPlugins, but returns a single plugin instance as opposed an entire list. name will be used to identify that plugin. Positional and keyword arguments will be used to instantiate the plugin object.

pa,
Platform object, whose base class is Pluggdapps.
interface,
pluggdapps.plugin.Interface class or canonical form of interface-name.
name,
Plugin name in canonical format. For example, canonical name for plugin class ConfigSqlite3DB defined under pluggdapps package will be, pluggdapps.ConfigSqlite3DB.
args and kwargs,
Positional and key-word arguments used to instantiate the plugin.

If settings key-word argument is present, it will be used to override default plugin settings. Return a single Plugin instance.

loginfo(formatstr, values=[])[source]

Use this method to log informational messages. The log messages will be formated and handled based on the configuration settings from [pluggdapps] section.

logdebug(formatstr, values=[])[source]

Use this method to log debug messages. The log messages will be formated and handled based on the configuration settings from [pluggdapps] section.

logwarn(formatstr, values=[])[source]

Use this method to log warning messages. The log messages will be formated and handled based on the configuration settings from [pluggdapps] section.

logerror(formatstr, values=[])[source]

Use this method to log error messages. The log messages will be formated and handled based on the configuration settings from [pluggdapps] section.

class pluggdapps.platform.Webapps(*args, **kwargs)[source]

Bases: pluggdapps.platform.Pluggdapps

Provides a web-framework based on a pluggable MVC design pattern. Can mount any number of web-application in the same python environment.

webapps = {}

Dictionay mapping of mount-key and pluggdapps.web.webapp.WebApp instance, where mount-key is a tuple of appsec, netpath, application-ini

netpaths = {}

Dictionay mapping of netpath, and pluggdapps.web.webapp.WebApp instance.

appurls = {}

A dictionary map of webapp’s instkey and its base-url. The base url consists of scheme, netloc, scriptname.

classmethod boot(baseini, *args, **kwargs)[source]

Parse [mountloc] section for application-wise configuration settings and return a fresh instance of Webapps class.

start()[source]

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.

shutdown()[source]

Reverse of start() method.

masterinit(plugin, webapp, *args, **kwargs)[source]

Call back function during plugin instantiation, from pluggdapps.plugin.PluginMeta class.

plugin,
Instantiated plugin. plugin is automatically populated with configuration settings and webapp attribute.
args and kwargs,
are received from query_plugin’s args and kwargs.
config(**kwargs)[source]

Get or set configuration parameter for the platform. If no keyword arguments are present, will return a dictionary of webapp-settings, where each webapp is identified by netpath as key.

Keyword arguments,

netpath,
Netpath, including hostname and script-path, on which web-application is mounted. Optional.
section,
Section name to get or set config parameter. Optional.
name,
Configuration name to get or set for section. Optional.
value,
If present, this method was invoked for setting configuration name under section. Optional.
static query_plugins(pa, webapp, interface, *args, **kwargs)[source]

Use this API to query for plugins using the interface class it implements. Positional and keyword arguments will be used to instantiate the plugin object.

pa,
Platform object, whose base class is Pluggdapps.
webapp,
Web application object, plugin implementing pluggdapps.interfaces.IWebApp interface. It is an optional argument, which must be passed None otherwise.
interface,
pluggdapps.plugin.Interface class or canonical form of interface-name.
args and kwargs,
Positional and key-word arguments used to instantiate the plugin.

If settings key-word argument is present, it will be used to override default plugin settings. Returns a list of plugin instance implementing interface

static query_pluginr(pa, webapp, interface, pattern, *args, **kwargs)[source]

Use this API to query for plugins using the interface class it implements. Positional and keyword arguments will be used to instantiate the plugin object.

pa,
Platform object, whose base class is Pluggdapps.
webapp,
Web application object, plugin implementing pluggdapps.interfaces.IWebApp interface. It is an optional argument, which must be passed None otherwise.
interface,
pluggdapps.plugin.Interface class or canonical form of interface-name.
pattern,
Instantiate plugins who’s name match this pattern. Pattern can be any regular-expression.
args and kwargs,
Positional and key-word arguments used to instantiate the plugin.

If settings key-word argument is present, it will be used to override default plugin settings. Returns a list of plugin instance implementing interface

static query_plugin(pa, webapp, interface, name, *args, **kwargs)[source]

Same as queryPlugins, but returns a single plugin instance as opposed an entire list. name will be used to identify that plugin. Positional and keyword arguments will be used to instantiate the plugin object.

pa,
Platform object, whose base class is Pluggdapps.
webapp,
Web application object, plugin implementing pluggdapps.interfaces.IWebApp interface. It is an optional argument, which must be passed None otherwise.
interface,
pluggdapps.plugin.Interface class or canonical form of interface-name.
name,
plugin name in canonical format. For example, canonical name for plugin class ConfigSqlite3DB defined under pluggdapps package will be, pluggdapps.ConfigSqlite3DB.
args and kwargs,
Positional and key-word arguments used to instantiate the plugin.

If settings key-word argument is present, it will be used to override default plugin settings. Return a single Plugin instance.

resolveapp(uri, hdrs)[source]

Resolve application for request.

uri,
byte-string of request URI.
hdrs,
Dictionary of request headers.

Return a tuple of, (uriparts, mountedat).

uriparts,
dictionary of URL parts
webapp,
IWebApp plugin instance.

Table Of Contents

Related Topics

This Page