rattail Module

rattail – Pythonic retail software framework

Attributes

rattail.__version__

Rattail’s version string.

rattail.config

RattailConfig instance, global to the application. After rattail.init() is called, contains all settings read from config files.

Functions

rattail.get_default_engine(assert_=False)

Returns the default database engine. The first time this function is called, rattail.db.get_engine_from_config() is used to load the engine from the current values in rattail.config.

When no default engine is defined: If assert_ is True, an exception will be raised; otherwise None is returned.

rattail.get_uuid()

Generates a universally-unique identifier and returns its value in hex.

rattail.init(*args)

Initializes the framework. This must be called prior to doing anything really useful, because it is responsible for extending the “live” API.

This function will usually read some config file(s) to determine how to connect to the database. If you wish to prevent the reading of config files then you should first tell Rattail how to connect to the database (via rattail.set_default_engine()) and then pass None to init().

Note

Even if you do not wish to read config files, it is still necessary to call init(); see preceding paragraph.

Once the connection is established, the database is consulted to see which extensions it contains. Each extension is loaded and applied to the live framework, and then the rattail namespace is updated with all classes, enumeration values, etc.

Note

Prior to init(), all primary entity classes may only be imported from rattail.classes. It is only after init() occurs that you may e.g. from rattail import Product. The same applies to rattail.enum.

The meaning of args is as follows:

If args is empty, it is assumed that one or more config files are to be found in the “standard” locations. These standard locations vary by platform, but are fed directly to rattail.config.read(); any files found will contribute to the final configuration values:

Win32:

  • <COMMON_APPDATA>\Rattail\rattail.conf
  • <APPDATA>Rattail\rattail.conf

Linux:

  • /etc/rattail/rattail.conf
  • /usr/local/etc/rattail/rattail.conf
  • ~/.rattail/rattail.conf

If args contains only a single value of None, no config files will be looked for or read.

Any other values in args will be passed directly to rattail.config.read() and so will be interpreted there. Basically they are assumed to be either strings, or sequences of strings, which represent paths to various config files, all of which will be read in the order in which they appear as args.

rattail.reinit(*args)

Tear down and rebuild the framework. This should probably only be useful for tests; normally you’d call rattail.init() instead. This function passes its args directly to rattail.init(); see that function for usage.

rattail.require_extensions(*args)

Explicitly require named extension(s) to be active. args may be one or more strings.

rattail.set_default_engine(engine)

Sets the default database engine.

Classes

Note

The classes shown here are always available in the root rattail namespace. Most of the interesting classes though are not available there until after rattail.init() is called; see that function for more info.

class rattail.RattailConfig(*args, **kwargs)

Subclasses ConfigParser.SafeConfigParser. Most users shouldn’t need to use this directly, but instead would access rattail.config.

class rattail.Session(*args, **kwargs)

This is a standard Session class as returned by sqlalchemy.orm.sessionmaker(); it is not a thread-local as returned by sqlalchemy.orm.scoped_session().

__init__(*args, **kwargs)

Constructor.

If no bind parameter is provided, rattail.db.get_default_engine() is called (with assert_=True) to determine which engine should be bound to.

get_subscribed_classes()

Returns a (possibly cached) dictionary of class names to which one or more other databases have subscribed. Each value in the dictionary is a list of relevant rattail.Subscriber instances for the class.

class rattail.FrameworkExtension

Base class for Rattail extensions.

schema

Reference to a Python module containing a SQLAlchemy-Migrate repository.

enum

Reference to a Python module containing enumeration values.

permissions

Dictionary of grouped permission definitions.

add_class(class_)

Convenience method for use in extend_classes().

extend_classes()

Extra classes may be added to Rattail within this method. Note that there is an add_class() method for convenience in doing so.

extend_mappers(metadata)

Any arbitrary manipulation to Rattail’s class mappings is done within this method. Typically any extra classes the extension provides will be mapped here, but existing (e.g. “core”) class mappings may be altered as well, by adding new properties to them, etc.

get_metadata()

Should return a sqlalchemy.MetaData instance containing table info for the extension, or None.

remove_class(class_name)

Convenience method for use in restore_classes().

restore_classes()

This method should remove any extra classes which were added within extend_classes(). Note that there is a remove_class() method for convenience in doing so.

Table Of Contents

Previous topic

Core API

Next topic

rattail.classes Module

This Page