wuttjamaican.app

WuttJamaican - app handler

class wuttjamaican.app.AppHandler(config)[source]

Base class and default implementation for top-level app handler.

aka. “the handler to handle all handlers”

aka. “one handler to bind them all”

For more info see App Handler.

There is normally no need to create one of these yourself; rather you should call get_app() on the config object if you need the app handler.

Parameters:

config – Config object for the app. This should be an instance of WuttaConfig.

providers

Dictionary of AppProvider instances, as returned by get_all_providers().

property appname

The app name for the current app. This is just an alias for wuttjamaican.conf.WuttaConfig.appname.

Note that this appname does not necessariy reflect what you think of as the name of your (e.g. custom) app. It is more fundamental than that; your Python package naming and the app title are free to use a different name as their basis.

get_all_providers()[source]

Load and return all registered providers.

Note that you do not need to call this directly; instead just use providers.

Returns:

Dictionary keyed by entry point name; values are AppProvider instances.

get_setting(session, name, **kwargs)[source]

Get a setting value from the DB.

This does not consult the config object directly to determine the setting value; it always queries the DB.

Default implementation is just a convenience wrapper around get_setting().

Parameters:
  • session – App DB session.

  • name – Name of the setting to get.

Returns:

Setting value as string, or None.

make_appdir(path, subfolders=None, **kwargs)[source]

Establish an app dir at the given path.

Default logic only creates a few subfolders, meant to help steer the admin toward a convention for sake of where to put things. But custom app handlers are free to do whatever.

Parameters:
  • path – Path to the desired app dir. If the path does not yet exist then it will be created. But regardless it should be “refreshed” (e.g. missing subfolders created) when this method is called.

  • subfolders – Optional list of subfolder names to create within the app dir. If not specified, defaults will be: ['data', 'log', 'work'].

make_engine_from_config(config_dict, prefix='sqlalchemy.', **kwargs)[source]

Construct a new DB engine from configuration dict.

This is a wrapper around upstream sqlalchemy.engine_from_config(). For even broader context of the SQLAlchemy Engine and their configuration, see Engine Configuration.

The purpose of the customization is to allow certain attributes of the engine to be driven by config, whereas the upstream function is more limited in that regard. The following in particular:

  • poolclass

  • pool_pre_ping

If these options are present in the configuration dict, they will be coerced to appropriate Python equivalents and then passed as kwargs to the upstream function.

An example config file leveraging this feature:

[wutta.db]
default.url = sqlite:///tmp/default.sqlite
default.poolclass = sqlalchemy.pool:NullPool
default.pool_pre_ping = true

Note that if present, the poolclass value must be a “spec” string, as required by load_object().

make_session(**kwargs)[source]

Creates a new SQLAlchemy session for the app DB. By default this will create a new Session instance.

Returns:

SQLAlchemy session for the app DB.

short_session(**kwargs)[source]

Returns a context manager for a short-lived database session.

This is a convenience wrapper around short_session.

If caller does not specify factory nor config params, this method will provide a default factory in the form of make_session().

class wuttjamaican.app.AppProvider(config)[source]

Base class for app providers.

These can add arbitrary extra functionality to the main app handler. See also App Providers.

Parameters:

config – Config object for the app. This should be an instance of WuttaConfig.

Instances have the following attributes:

config

Reference to the config object.

app

Reference to the parent app handler.

class wuttjamaican.app.GenericHandler(config, **kwargs)[source]

Generic base class for handlers.

When the app defines a new type of handler it may subclass this when defining the handler base class.

Parameters:

config – Config object for the app. This should be an instance of WuttaConfig.