rattail.config
¶
Application Configuration
- class rattail.config.ConfigExtension(*args, **kwargs)[source]¶
DEPRECATED - use
wuttjamaican.conf.WuttaConfigExtension
instead.See also
RattailConfigExtension
.
- 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
.
- 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 to0
.
- 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.
- 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.
- 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]¶
Deprecated method for unused Beaker caching logic.
This method has no effect and should not be used.
- demo()[source]¶
Returns boolean indicating whether the app is running in demo mode
Warning
The utility of this method is questionable and it ideally will go away in the future.
- 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. However new code should pass(key, ...)
since that is now the preferred signature.
- get_date(*args, **kwargs)[source]¶
Retrieve a date value from config.
Accepts same params as
get()
but if a value is found, it will be coerced to date viarattail.app.AppHandler.parse_date()
.
- get_enum(**kwargs)[source]¶
Returns a reference to configured “enum” module; defaults to
rattail.enum
.
- get_store(session)[source]¶
Returns a
rattail.db.model.Store
instance corresponding to app config, orNone
.
- 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 or else calling this method will result in an error.
- getbool(*args, **kwargs)[source]¶
Backward-compatible alias for
get_bool()
.New code should use
get_bool()
instead of this method.
- getdate(*args, **kwargs)[source]¶
Backward-compatible alias for
get_date()
.New code should use
get_date()
instead of this method.
- 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_type(default=None)[source]¶
Returns the “type” of current node as string. What this means will generally depend on the app logic. There is no default node type unless caller provides one.
- parse_bool(value)[source]¶
Convenience method around the
parse_bool()
function.
- parse_list(value)[source]¶
Convenience method around the
parse_list()
function.
- property prioritized_files¶
Backward-compatible property which just calls
get_prioritized_files()
.New code should use
get_prioritized_files()
instead of this property.
- running_from_source()[source]¶
Returns boolean indicating whether the app is running from source, as opposed to official release.
Warning
The utility of this method is questionable and it ideally will go away in the future.
- 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. However new code should pass(key, value)
since that is now the preferred signature.
- 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.
- class rattail.config.RattailConfigExtension[source]¶
The config extension for Rattail.
This is a subclass of
wuttjamaican.conf.WuttaConfigExtension
.This primarily exists to add default config settings for sake of the various importers etc. contained in the
rattail
package.Note
If you are adding a new config extension, do not subclass this, but rather subclass
wuttjamaican.conf.WuttaConfigExtension
directly.- startup(config)[source]¶
This method is called after the config object is fully created and all extensions have been applied, i.e. after
configure()
has been called for each extension.At this point the config settings for the running app should be settled, and each extension is then allowed to act on those initial settings if needed.
- 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
isTrue
, 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 withfilename
.The
createdir
argument will be passed toget_user_dir()
as itscreate
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:- Parameters:
versioning¶ – Controls whether or not the versioning system is configured with the new config object. If
True
, versioning will be configured. IfFalse
then it will not be configured. IfNone
(the default) then versioning will be configured only if the config values say that it should be.- Returns:
An instance of
RattailConfig
.
- 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.