rattail.config

Application Configuration

class rattail.config.ConfigExtension[source]

Base class for all config extensions.

This is just a compatibility wrapper around wuttjamaican.conf.WuttaConfigExtension; new code should probably use that directly.

class rattail.config.ConfigProfile(config, key, **kwargs)[source]

Generic class to represent a config “profile”, as used by the filemon and datasync daemons, etc.

Todo

This clearly needs more documentation.

config

Reference to the primary Rattail config object for the running app.

key

String identifier unique to this profile, within the broader config section.

load()[source]

Read all relevant settings etc. from the config object, setting attributes on this profile instance as needed.

load_actions()[source]

Read the “actions” from config, for the current profile, and assign the result to self.actions.

load_defaults()[source]

Read all “default” (common) settings from config, for the current profile.

property section

Each subclass of ConfigProfile must define this.

class rattail.config.ConfigProfileAction[source]

Simple class to hold configuration for a particular “action” defined within a monitor ConfigProfile. Each instance has the following attributes:

spec

The original “spec” string used to obtain the action callable.

action

A reference to the action callable.

args

A sequence of positional arguments to be passed to the callable (in addition to the file path) when invoking the action.

kwargs

A dictionary of keyword arguments to be passed to the callable (in addition to the positional arguments) when invoking the action.

retry_attempts

Number of attempts to make when invoking the action. Defaults to 1, meaning the first attempt will be made but no retries will happen.

retry_delay

Number of seconds to pause between retry attempts, if retry_attempts is greater than one. Defaults to 0.

class rattail.config.FreeTDSLoggingFilter(*args, **kwargs)[source]

Custom logging filter, to suppress certain “write to server failed” messages relating to FreeTDS database connections. They seem harmless and just cause unwanted error emails.

filter(record)[source]

Determine if the specified record is to be logged.

Returns True if the record should be logged, or False otherwise. If deemed appropriate, the record may be modified in-place.

class rattail.config.RattailConfig(*args, **kwargs)[source]

Configuration for Rattail apps.

A single instance of this class is created on app startup, by way of calling rattail.config.make_config().

This class is based on WuttaConfig but adds many methods specific to Rattail.

Some of the customizations supplied by this class are described below.

versioning_has_been_enabled

Flag indicating whether SQLAlchemy-Continuum versioning has been enabled for the running app. This gets set when configure_versioning() happens.

app_package(default=None)[source]

Returns the name of Python package for the top-level app.

app_title(**kwargs)[source]

DEPRECATED

appdir(require=True, **kwargs)[source]

Returns path to the ‘app’ dir, if known.

base_url()[source]

Returns the configured “base” (root) URL for the web app.

batch_filedir(key=None)[source]

Returns path to root folder where batches (optionally of type ‘key’) are stored.

batch_filepath(key, uuid, filename=None, makedirs=False)[source]

Returns absolute path to a batch’s data folder, with optional filename appended. If makedirs is set, the batch data folder will be created if it does not already exist.

beaker_invalidate_setting(name)[source]

Backward-compatible method for unused Beaker caching logic.

This method has no effect and should not be used.

datadir(require=True)[source]

Returns path to the ‘data’ dir, if known.

datasync_url(**kwargs)[source]

Returns configured URL for managing datasync daemon.

demo()[source]

Returns boolean indicating whether the app is running in demo mode

export_filedir(key=None)[source]

Returns path to root folder where exports (optionally of type ‘key’) are stored.

export_filepath(key, uuid, filename=None, makedirs=False)[source]

Returns absolute path to export data file, generated from the given args.

get(*args, **kwargs)[source]

We override this method to support different calling signatures.

wuttjamaican.conf.WuttaConfig.get() normally expects just (key, ...) args, but we also (for now) support the older style of (section, option, ...) - eventually that will go away but probably not in the near future.

get_enum(**kwargs)[source]

Returns a reference to configured “enum” module; defaults to rattail.enum.

get_model()[source]

Returns a reference to configured ‘model’ module; defaults to rattail.db.model.

get_store(session)[source]

Returns a rattail.db.model.Store instance corresponding to app config, or None.

get_trainwreck_model()[source]

Returns a reference to the configured data ‘model’ module for Trainwreck. Note that there is not a default value for this; it must be configured.

getbool(*args, **kwargs)[source]

Backward-compatible alias for get_bool().

New code should use get_bool() instead of this method.

getdate(*args, **kwargs)[source]

Retrieve a date value from config.

getint(*args, **kwargs)[source]

Backward-compatible alias for get_int().

New code should use get_int() instead of this method.

getlist(*args, **kwargs)[source]

Backward-compatible alias for get_list().

New code should use get_list() instead of this method.

make_list_string(values)[source]

Coerce the given list of values to a string, for config storage. If this string is later parsed via parse_list() then it should return the same list of values.

For example:

string = config.make_list_string(['foo', 'bar'])

assert string == 'foo, bar'

values = config.parse_list(string)

assert values == ['foo', 'bar']
node_title(**kwargs)[source]

DEPRECATED

node_type(default=None)[source]

Returns the “type” of current node. What this means will generally depend on the app logic.

parse_bool(value)[source]

Convenience method around the parse_bool() function.

Usage of this method is discouraged, at least until some more dust settles. This probably belongs on the app handler instead so it can be overridden more easily.

parse_list(value)[source]

Convenience method around the parse_list() function.

Usage of this method is discouraged, at least until some more dust settles. This probably belongs on the app handler instead so it can be overridden more easily.

property prioritized_files

Backward-compatible property which just calls get_prioritized_files().

New code should use get_prioritized_files() instead of this property.

product_key(**kwargs)[source]

Deprecated; instead please see rattail.app.AppHandler.get_product_key_field().

product_key_title(key=None)[source]

Deprecated; instead please see rattail.app.AppHandler.get_product_key_label().

production()[source]

Returns boolean indicating whether the app is running in production mode

running_from_source()[source]

Returns boolean indicating whether the app is running from source, as opposed to official release.

setdefault(*args)[source]

We override this method to support different calling signatures.

wuttjamaican.conf.WuttaConfig.setdefault() normally expects just (key, value) args, but we also (for now) support the older style of (section, option, value) - eventually that will go away but probably not in the near future.

single_store()[source]

Returns boolean indicating whether the system is configured to behave as if it belongs to a single Store.

upgrade_command(default='/bin/sleep 30')[source]

Returns command to be used when performing upgrades.

upgrade_filedir()[source]

Returns path to root folder where upgrade files are stored.

upgrade_filepath(uuid, filename=None, makedirs=False)[source]

Returns absolute path to upgrade data file, generated from the given args.

versioning_enabled()[source]

Returns boolean indicating whether data versioning is enabled.

workdir(require=True)[source]

Returns path to the ‘work’ dir, if known.

class rattail.config.RattailConfigWrapper(*args, **kwargs)[source]

Simple wrapper which serves as the main app config object.

This will eventually go away in favor of using the config object directly. It was needed for migration to the new config class.

But for now, make_config() actually returns an instance of this wrapper class.

rattail.config.get_user_dir(create=False)[source]

Returns a path to the “preferred” user-level folder, in which additional config files (etc.) may be placed as needed. This essentially returns a platform-specific variation of ~/.rattail/.

If create is True, then the folder will be created if it does not already exist.

rattail.config.get_user_file(filename, createdir=False)[source]

Returns a full path to a user-level config file location. This is obtained by first calling get_user_dir() and then joining the result with filename.

The createdir argument will be passed to get_user_dir() as its create arg, and may be used to ensure the user-level folder exists.

rattail.config.make_config(files=None, plus_files=None, versioning=None, **kwargs)[source]

Make a new config object (presumably for global use), initialized per the given parameters and (usually) further modified by all registered config extensions.

This is a wrapper around upstream wuttjamaican.conf.make_config(); see those docs for most of the param descriptions. Rattail customizes the logic as follows:

Note

This function always returns a RattailConfigWrapper instance, which “wraps” the underlying config object. But that will likely change soon, so this function would return the config object directly and skip the wrapper.

Parameters:

versioning – Controls whether or not the versioning system is configured with the new config object. If True, versioning will be configured. If False then it will not be configured. If None (the default) then versioning will be configured only if the config values say that it should be.

Returns:

An instance of RattailConfigWrapper which wraps an instance of RattailConfig.

rattail.config.parse_bool(value)[source]

Compatibility wrapper for wuttjamaican.util.parse_bool().

This function will eventually be deprecated; new code should use the upstream function instead.

rattail.config.parse_list(value)[source]

Compatibility wrapper for wuttjamaican.util.parse_list().

This function will eventually be deprecated; new code should use the upstream function instead.

rattail.config.rattail_default_files(appname)[source]

This is used in place of upstream wuttjamaican.conf.generic_default_files() to customize the default files when none are specified at startup.

Rattail has traditionally used e.g. /path/to/venv/app/quiet.conf as its “preferred default file” when running ad-hoc commands. So this function will look for that file and return it if found; otherwise it just calls the upstream function.