kojismokydingo.cli.sift¶
Some CLI adapters for working with Sifty Dingo filtering
- author:
Christopher O'Brien <obriencj@gmail.com>
- license:
GPL v3
- class Sifting[source]¶
Bases:
object
A mixin for SmokyDingo instances that wish to offer a sifter.
- get_outputs(options)[source]¶
Produces a dict mapping flag names to output files based on the accumulated results of the
--output FLAG:FILENAME
argument.This dict can be used with
output_sifted
to record the results of a sifter to a collection of files.
- get_sifter(options)[source]¶
Produces a Sifter instances constructed from values in options. These options should have been generated from a parser that has had the
Sifting.sifter_arguments
invoked on it.
- sifter_arguments(parser)[source]¶
Adds an argument group for for loading a Sifter from either an text argument or a filename, and specifying output files for the expected flags from that Sifter's results.
--output/-o FLAG:FILENAME[,...]
--filter FILTER
--filter-file FILTER_FILE
- Parameters:
parser (ArgumentParser)
- Return type:
- output_sifted(results, key='id', outputs=None, sort=None)[source]¶
Records the results of a sifter to output. As sifter results are dicts, the
key
parameter can be either a unary callable or an index value to be used to fetch a simplified, printable representaiton from the dicts.outputs
is a mapping of flag names to filenames using the rules of theopen_output()
function.- Parameters:
results (Dict[str, List[dict]]) -- results of invoking a Sifter on a set of data
key (Callable[[Any], Any] | Any) -- transformation to apply to the individual data elements prior to recording. Default, lookup the
"id"
index from the element.outputs (Dict[str, str] | None) -- mapping of flags to destination filenames. If unspecified, the default flag will be written to stdout and the rest will be discarded.
sort (Callable[[Any], Any] | Any | None) -- sorting to apply to the results in each flag. If unspecified, order is preserved.