kojismokydingo.cli.sift

Some CLI adapters for working with Sifty Dingo filtering

author:

Christopher O'Brien <obriencj@gmail.com>

license:

GPL v3

class BuildSifting[source]

Bases: Sifting

get_sieves(entry_points=True)[source]
class Sifting[source]

Bases: object

A mixin for SmokyDingo instances that wish to offer a sifter.

default_params()[source]
Return type:

Dict[str, str]

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.

Parameters:

options (Namespace)

Return type:

Dict[str, str]

get_params(options)[source]
Parameters:

options (Namespace)

Return type:

Dict[str, str]

get_sieves(entry_points=True)[source]
Parameters:

entry_points (bool)

Return type:

List[Type[Sieve]]

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.

Parameters:

options (Namespace)

Return type:

Sifter

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:

ArgumentParser

class TagSifting[source]

Bases: Sifting

get_sieves(entry_points=True)[source]
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 the open_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.