zabgrab.services.naming

Output file names.

zabgrab.services.naming.MAX_LENGTH

The longest automatic name (without extension).

Type:

int

zabgrab.services.naming.MAX_HOSTS

The most host names in an automatic name before the rest are counted.

Type:

int

zabgrab.services.naming.PLACEHOLDERS

The placeholders output_pattern can use.

Type:

tuple of str

zabgrab.services.naming.EXTENSIONS

The file extension for each format.

Type:

dict of Format to str

Functions

format_for(path)

Get the output format implied by a file name's extension, if any.

output_name(pattern, *, hosts, template, ...)

Build a file name (without extension) from output_pattern.

unique_path(path)

Get path, or path with -2, -3, .

zabgrab.services.naming.format_for(path)[source]

Get the output format implied by a file name’s extension, if any.

Parameters:

path (Path)

Return type:

Format | None

zabgrab.services.naming.output_name(pattern, *, hosts, template, custom, start, end, server, resolution)[source]

Build a file name (without extension) from output_pattern.

Unsafe characters become -, and the name is kept to MAX_LENGTH characters, showing fewer hosts if needed.

Parameters:
  • pattern (str) – The pattern. Placeholders: {hosts} (matched hosts, sorted, joined with +; more than three are shortened), {template} (the template’s name, plus __custom if the command line added or changed data), {from}/{to} (UTC, e.g. 20261014T101500Z), {server} and {resolution}.

  • hosts (sequence of str) – The hosts of the fetched items.

  • template (str or None) – The template used, if any.

  • custom (bool) – Whether the command line added or changed data.

  • start (datetime) – The fetched time range.

  • end (datetime) – The fetched time range.

  • server (str) – A short name for the server.

  • resolution (str) – raw or 1h.

Returns:

str – The name.

Raises:

ZabgrabError – If the pattern is invalid (e.g. an unknown placeholder).

Return type:

str

zabgrab.services.naming.unique_path(path)[source]

Get path, or path with -2, -3, … added if it exists.

Parameters:

path (Path)

Return type:

Path