rattail.importing.handlers

Import Handlers

class rattail.importing.handlers.ImportHandler(config=None, **kwargs)[source]

Base class for all import handlers.

direction

Should be a string, either 'import' or 'export'. This value is used to improve verbiage for logging and other output, for a better overall user experience. It may also be used by importer logic, where the direction would otherwise be ambiguous.

For “most” handlers the distinction is somewhat implied, e.g. Rattail -> POS is almost certainly thought of as an export, whereas POS -> Rattail would be an import. However “export” handlers should still define this value accordingly; it’s optional for “import” since that is the default.

The value is most useful though, where it is otherwise ambiguous. Within a Rattail -> Rattail handler for instance, importer logic may consult this value in order to do different things depending on which “side” is the local “default” DB. For example you may have a “host” and multiple “store” nodes, and you want to “push” some tables from host -> store, but not the other way around. Since presumably both of the rattail import-rattail and rattail export-rattail (i.e. pull and push) commands should be valid to run from any given node, and since the importers themselves are “direction-agnostic”, the importers must consult direction (as well as node_type()) to know which tables to support for each command run.

extra_importer_kwargs

Dictionary of “extra” kwargs which should be passed as-is to the constructor when making a new importer instance. Note that these kwargs will be used when making a new importer of any type. Ultimately the logic for this is to be found in get_importer_kwargs().

get_default_keys()[source]

Returns the list of keys corresponding to the “default” importers. Override this if you wish certain importers to be excluded by default, e.g. when first testing them out etc.

get_importer(key, **kwargs)[source]

Returns an importer instance corresponding to the given key.

get_importer_keys()[source]

Returns the list of keys corresponding to the available importers.

get_importer_kwargs(key, **kwargs)[source]

Return a dict of kwargs to be used when construcing an importer with the given key. Default behaior here is just to ensure everything in extra_importer_kwargs gets included.

get_importers()[source]

Returns a dict of all available importers, where the keys are model names and the values are importer factories. All subclasses will want to override this. Note that if you return an collections.OrderedDict instance, you can affect the ordering of keys in the command line help system, etc.

import_data(*keys, **kwargs)[source]

Import all data for the given importer/model keys.

Parameters:

retain_used_importers – Optional flag to indicate the handler should retain references to all importers it creates/runs. If this flag is set then the handler will have a used_importers attribute after this method completes. This would be a dictionary whose keys are model names and values are the importer instances.

make_batches(*keys, **kwargs)[source]

Make new import/export batch for each specified model key.

process_changes(changes)[source]

This method is called any time changes occur, regardless of whether the import is running in “warnings” mode. Default implementation does nothing; override as needed.

setup()[source]

Perform any additional setup if/as necessary, prior to running the import task(s).

teardown()[source]

Perform any cleanup necessary, after running the import task(s).

class rattail.importing.handlers.BulkImportHandler(config=None, **kwargs)[source]

Base class for bulk import handlers.

import_data(*keys, **kwargs)[source]

Import all data for the given importer/model keys.

class rattail.importing.handlers.FromSQLAlchemyHandler(config=None, **kwargs)[source]

Handler for imports for which the host data source is represented by a SQLAlchemy engine and ORM.

get_importer_kwargs(key, **kwargs)[source]

Return a dict of kwargs to be used when construcing an importer with the given key. Default behaior here is just to ensure everything in extra_importer_kwargs gets included.

make_host_session()[source]

Subclasses must override this to define the host database connection.

class rattail.importing.handlers.ToSQLAlchemyHandler(config=None, **kwargs)[source]

Handler for imports which target a SQLAlchemy ORM on the local side.

get_importer_kwargs(key, **kwargs)[source]

Return a dict of kwargs to be used when construcing an importer with the given key. Default behaior here is just to ensure everything in extra_importer_kwargs gets included.

make_session()[source]

Subclasses must override this to define the local database connection.