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
andrattail 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 consultdirection
(as well asnode_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_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.
- class rattail.importing.handlers.BulkImportHandler(config=None, **kwargs)[source]¶
Base class for bulk import handlers.
- 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.
- class rattail.importing.handlers.ToSQLAlchemyHandler(config=None, **kwargs)[source]¶
Handler for imports which target a SQLAlchemy ORM on the local side.