zabgrab.services.output¶
Deciding where and how to save fetched data.
- zabgrab.services.output.STRUCTURED¶
Formats that hold several fetches (as groups), so can be appended to.
- zabgrab.services.output.MAT_TEXT_BYTES¶
The measured size of a text entry in a .mat file (see
benchmarks/mat_text.py).- Type:
- zabgrab.services.output.MAT_TEXT_WRITE_SECONDS¶
The measured time to write a text entry to a .mat file.
- Type:
Functions
|
Make the automatic file name (without extension) for a query's data. |
|
Choose the output format(s). |
|
Decide how to save to a file, asking what to do if it exists. |
|
Warn before writing a lot of text to a .mat file. |
|
Decide where to save the data. |
|
Count a fetch's text values (each is a cell entry in a .mat file). |
Classes
|
Command line options about saving. |
|
A file to save data to. |
- class zabgrab.services.output.Target(path, format, append=False, large_text_accepted=False)[source]¶
Bases:
objectA file to save data to.
- path¶
The file.
- Type:
Path
- class zabgrab.services.output.SaveOptions(format=None, overwrite=False, append=False, group=None, in_place=False, allow_large_text=False, plot=False)[source]¶
Bases:
objectCommand line options about saving.
- Parameters:
- plot¶
--plot: the data will be plotted, so without--outputit’s neither saved nor asked about.- Type:
- check(outputs)[source]¶
Reject options that don’t make sense together.
- Parameters:
outputs (sequence of str) – The
--outputvalues given (none if it wasn’t).- Raises:
ZabgrabError – If the options conflict.
- Return type:
None
- zabgrab.services.output.auto_name(query, *, hosts, server)[source]¶
Make the automatic file name (without extension) for a query’s data.
- zabgrab.services.output.targets(outputs, query, ui, *, name, options)[source]¶
Decide where to save the data.
- Parameters:
outputs (sequence of str) – The
--outputvalues, each saved to:""for an automatic name inoutput_dir, a directory for an automatic name there, or a file. With none, the user is asked (or, if the session isn’t interactive or the data is plotted, it isn’t saved).query (Query) – The query, for its configured formats and output directory.
ui (UI) – For questions and messages.
name (str) – The automatic file name (see
auto_name()).options (SaveOptions) – The other command line options about saving.
- Returns:
list of Target – The files to write (one per output and format, each path once); empty if the data isn’t to be saved.
- Raises:
ZabgrabError – If the options conflict.
Cancelled – If the user cancels.
- Return type:
- zabgrab.services.output.choose_formats(configured, cli_format, file, ui, answers=None)[source]¶
Choose the output format(s).
- Parameters:
configured (sequence of Format) – The formats from the template or
[defaults].cli_format (Format or None) –
--format, which wins if given.file (Path or None) – The output file, whose extension is used next.
ui (UI) – For asking, when nothing else decides.
answers (Answers, optional) – Where to record the answer, if asked.
- Returns:
tuple of Format – The formats.
- Raises:
InputRequired – If nothing decides and the session isn’t interactive.
- Return type:
- zabgrab.services.output.existing_target(path, format, ui, options)[source]¶
Decide how to save to a file, asking what to do if it exists.
- Parameters:
path (Path) – The file.
format (Format) – Its format.
ui (UI) – For asking; non-interactive sessions save next to it instead.
options (SaveOptions) –
--overwriteand--appenddecide without asking.
- Returns:
Target – Where to save.
- Raises:
Cancelled – If the user cancels.
- Return type:
- zabgrab.services.output.text_entries(result)[source]¶
Count a fetch’s text values (each is a cell entry in a .mat file).
- Parameters:
result (FetchResult) – The fetched data.
- Returns:
int – The number of text values, including log sources.
- Return type:
- zabgrab.services.output.guard_large_text(target, result, ui, *, threshold, allow, existing_entries, accepted_before)[source]¶
Warn before writing a lot of text to a .mat file.
Text makes .mat files big and slow to load in MATLAB. Interactive users can continue, save as .h5 instead, skip the text items or cancel; others get a warning. Accepting (or
allow) is remembered in the file, so later appends don’t ask again.- Parameters:
target (Target) – Where the data is to be saved.
result (FetchResult) – The data.
ui (UI) – For warnings and questions.
threshold (int) – How many text values (including those already in the file) to allow without warning; 0 never warns.
allow (bool) –
--allow-large-text.existing_entries (callable) – Counts the text values already in a file.
accepted_before (callable) – Whether a file records that large text was accepted before.
- Returns:
tuple of Target and FetchResult – Where to save, and what (without the text items if they’re left out).
- Raises:
Cancelled – If the user cancels.
- Return type: