zabgrab.services.resolve

Turning command line options, a template and config into a Query.

zabgrab.services.resolve.TimeParser

Parses a user-supplied time in a timezone (None for local) to aware UTC.

Type:

type

zabgrab.services.resolve.DefaultsSource

Gets where a [defaults] key’s value came from (a file path or built-in).

Type:

type

zabgrab.services.resolve.SETTINGS

Settings resolved from the command line, the template and [defaults], in the order they’re resolved (the timezone is needed to compare and parse times).

Type:

tuple of str

zabgrab.services.resolve.DATA_SETTINGS

Settings that change which data is fetched (used to mark a query as custom).

Type:

frozenset of str

Functions

find_template(name, config, ui[, answers])

Look up a template, with "did you mean" for unknown names.

flag(key)

Get the command line option for a config key.

resolve_query(cli, config, ui, *, ...)

Combine the command line, template and config into a Query.

Classes

CliRequest([template, items, server, values])

What was given on the command line.

class zabgrab.services.resolve.CliRequest(template=None, items=(), server=None, values=<factory>)[source]

Bases: object

What was given on the command line.

Parameters:
template

--template.

Type:

str or None

items

The items given as arguments.

Type:

tuple of ItemSpec

server

--server.

Type:

str or None

values

Settings given explicitly, by config key (e.g. "from").

Type:

mapping

zabgrab.services.resolve.flag(key)[source]

Get the command line option for a config key.

Parameters:

key (str) – The config key.

Returns:

str – The option.

Return type:

str

Examples

>>> flag("output_dir")
'--output-dir'
zabgrab.services.resolve.resolve_query(cli, config, ui, *, parse_time, defaults_source)[source]

Combine the command line, template and config into a Query.

Precedence: the command line, then the template, then [defaults] (including built-in values). Missing times are asked for. Overrides of template values are logged.

Parameters:
  • cli (CliRequest) – What was given on the command line.

  • config (Config) – The configuration.

  • ui (UI) – For questions and messages.

  • parse_time (TimeParser) – Parses times.

  • defaults_source (DefaultsSource) – Says where [defaults] values came from, for --dry-run.

Returns:

Query – The query.

Raises:
  • ZabgrabError – If the template is unknown or a time is invalid, and the user can’t be asked.

  • InputRequired – If a question is needed but the session isn’t interactive.

Return type:

Query

zabgrab.services.resolve.find_template(name, config, ui, answers=None)[source]

Look up a template, with “did you mean” for unknown names.

Parameters:
  • name (str) – The template’s name.

  • config (Config) – The configuration.

  • ui (UI) – For questions, when the name is unknown.

  • answers (Answers, optional) – Where to record the template chosen instead, if any.

Returns:

tuple of str and Template – The template used and its name, which differs from name if the user chose another.

Raises:

ZabgrabError – If the name is unknown and the user can’t choose another.

Return type:

tuple[str, Template]