wuttasync.exporting.base

Data exporter base classes

class wuttasync.exporting.base.ToFile(config, **kwargs)[source]

Base class for importer/exporter using output file as data target.

Depending on the subclass, it may be able to “guess” (at least partially) the path to the output file. If not, and/or to avoid ambiguity, the caller must specify the file path.

In most cases caller may specify any of these via kwarg to the class constructor, or e.g. process_data():

The subclass itself can also specify via override of these methods:

And of course subclass must override these too:

close_output_file()[source]

Close the output file for target data.

Subclass must override to specify how this happens; default logic blindly calls the close() method on whatever output_file happens to point to.

See also open_output_file().

get_output_file_name()[source]

This must return the output filename, sans folder path.

Default logic will return output_file_name if set, otherwise raise error.

Returns:

Output filename, sans folder path

get_output_file_path()[source]

This must return the full path to output file.

Default logic inspects output_file_path; if that points to a folder then it is combined with get_output_file_name(). Otherwise it’s returned as-is.

Returns:

Path to output file, as string

open_output_file()[source]

Open the output file for writing target data.

Subclass must override to specify how this happens; default logic is not implemented. Remember to set output_file if applicable for reference when closing.

See also get_output_file_path() and close_output_file().

output_file = None

Handle to the open output file, if applicable. May be set by open_output_file() for later reference within close_output_file().

output_file_name = None

Optional static output file name (sans folder path).

If set, this will be used as output filename instead of the importer determining one on its own.

See also get_output_file_name().

output_file_path = None

Path to output folder, or file.

The ideal usage is to set this to the output folder path. That allows the handler to run several importers in one go. The same output folder path is given to each importer; they then each determine their own output filename within that.

But you can also set this to the full output folder + file path, e.g. if you’re just running one importer. This would override the importer’s own logic for determining output filename.

See also get_output_file_path() and get_output_file_name().

setup()[source]

Open the output file. See also open_output_file().

teardown()[source]

Close the output file. See also close_output_file().