zabgrab.cli.fetch

zabgrab fetch: downloading data.

Functions

download(app, query, *, yes)

Find the items and download their data, reporting any problems.

fetch_summary(result, query)

Describe what was fetched, e.g. Fetched 2 items (4 points) from ....

guard_text(app, target, result, query, allow)

Check before writing a lot of text to a .mat file.

report_problems(app, result)

Warn about skipped items and report failed ones.

resolve_request(app, *, templates, items, ...)

Work out what to fetch from the command line, the template and the config.

run_plan(app, plan, query, *, dry_run, empty)

Download the data for a plan's jobs, then close its connections.

save_target(target, result, metadata, query, ...)

Write fetched data to a file.

settings_values(given)

Check fetch settings given on the command line.

show_equivalent(app, query, *[, templates])

Show the command that repeats this command without its questions.

zabgrab.cli.fetch.settings_values(given)[source]

Check fetch settings given on the command line.

Parameters:

given (dict) – The options’ values, by setting name (None where not given).

Returns:

dict – The settings given.

Raises:

click.UsageError – If a value isn’t valid.

Return type:

dict[str, Any]

zabgrab.cli.fetch.resolve_request(app, *, templates, items, servers, values, now)[source]

Work out what to fetch from the command line, the template and the config.

Parameters:
  • app (AppContext) – For the config and the UI (anything missing is asked for).

  • templates (tuple) – --template, --item and --server.

  • items (tuple) – --template, --item and --server.

  • servers (tuple) – --template, --item and --server.

  • values (dict) – The other settings given (see settings_values()).

  • now (datetime) – The start of the command, for relative times.

Returns:

  • CliRequest – The command line’s request.

  • Query – What to fetch, and where each setting came from.

Return type:

tuple[CliRequest, Query]

zabgrab.cli.fetch.show_equivalent(app, query, *, templates=True)[source]

Show the command that repeats this command without its questions.

Parameters:
  • app (AppContext) – For the UI.

  • query (Query) – The query, with the answers given to questions.

  • templates (bool, optional) – Whether the command can save templates (--save-template).

Return type:

None

zabgrab.cli.fetch.fetch_summary(result, query)[source]

Describe what was fetched, e.g. Fetched 2 items (4 points) from ....

Parameters:
  • result (FetchResult) – The data (with at least one series).

  • query (Query) – The query, for the time range and time zone.

Returns:

str – The description, without a full stop.

Return type:

str

zabgrab.cli.fetch.download(app, query, *, yes)[source]

Find the items and download their data, reporting any problems.

Parameters:
  • app (AppContext) – For the UI and the connections.

  • query (Query) – What to fetch.

  • yes (bool) – --yes: fetch however many items match.

Returns:

FetchResult – The data, with at least one series.

Raises:

ZabgrabError – If there are no items, or nothing could be fetched.

Return type:

FetchResult

async zabgrab.cli.fetch.run_plan(app, plan, query, *, dry_run, empty)[source]

Download the data for a plan’s jobs, then close its connections.

Parameters:
  • app (AppContext) – For the UI and the clock.

  • plan (Plan) – The items to download, and the connections to their servers.

  • query (Query) – The time range and settings.

  • dry_run (bool) – Show the items that would be downloaded instead.

  • empty (ZabgrabError) – The error to raise if there are no items.

Returns:

FetchResult or None – The data, or None for a dry run.

Return type:

FetchResult | None

zabgrab.cli.fetch.guard_text(app, target, result, query, allow)[source]

Check before writing a lot of text to a .mat file.

See zabgrab.services.output.guard_large_text().

Parameters:
  • app (AppContext) – For the UI.

  • target (Target) – Where the data is to be saved.

  • result (FetchResult) – The data.

  • query (Query) – For the mat_text_warn_entries setting.

  • allow (bool) – --allow-large-text.

Returns:

tuple of Target and FetchResult – Where to save, and what.

Return type:

tuple[Target, FetchResult]

zabgrab.cli.fetch.save_target(target, result, metadata, query, options)[source]

Write fetched data to a file.

Parameters:
  • target (Target) – Where and how to save.

  • result (FetchResult) – The data.

  • metadata (dict) – The metadata to save with it.

  • query (Query) – The query, for its time range and timezone.

  • options (SaveOptions) – --group and --in-place, for appending.

Returns:

str – A description of where the data went, for the summary.

Return type:

str

zabgrab.cli.fetch.report_problems(app, result)[source]

Warn about skipped items and report failed ones.

Parameters:
Raises:

ZabgrabError – If nothing was fetched.

Return type:

None