HTML Utilities
The following are a number of utility functions used to generate the HTML log
file produced by ShellLogger.
Various utilities for building the HTML log file.
- shell_logger.html_utilities.append_html(*args, output)[source]
Append whatever is given to the
outputHTML file.
- shell_logger.html_utilities.child_logger_card(log)[source]
Generate a child logger card.
Create a card to go in the HTML log file containing everything pertaining to a child
ShellLogger.- Parameters:
log (ShellLogger) – The child
ShellLoggerfor which to generate the card.- Return type:
- Returns:
A generator that will lazily yield the elements of the HTML for the card one at a time.
Todo
The type hinting for
logis done in the docstring instead of the function signature, because to put it in the signature would create a circular dependency betweenshell_logger.pyandhtml_utilities.py. This function needs to be reworked such that there’s no longer a dependency onShellLogger.
- shell_logger.html_utilities.child_logger_card_html(name, duration, *args)[source]
Generate the HTML for a child logger card.
Generate the HTML for a card corresponding to the child
ShellLogger. The HTML elements are yielded one at a time to avoid loading all the data from theShellLoggerinto memory at once.- Parameters:
- Yields:
The header, followed by all the contents of the child
ShellLogger, and then the footer.- Return type:
Todo
Should we replace the
forloop with the one found inparent_logger_card_html()?
- shell_logger.html_utilities.closing_html_text()[source]
Get the closing HTML tag.
- Return type:
- Returns:
A string with the closing HTML tag in it.
- shell_logger.html_utilities.command_card(log, stream_dir)[source]
Generate a command card.
Create a card in the HTML log file containing the output of a command, along with all its corresponding data (environment information, trace output, memory/CPU/disk statistics, etc.).
- Parameters:
- Return type:
- Returns:
A generator to lazily yield the elements of the command card one at a time.
- shell_logger.html_utilities.command_card_html(log, *args)[source]
Generate the HTML for a command card.
Generate the HTML for a card corresponding to a command that was run. The HTML elements are yielded one at a time to avoid loading all the data into memory at once.
- Parameters:
- Yields:
The header, followed by all the contents of the command card, and then the footer.
- Return type:
- shell_logger.html_utilities.command_detail(cmd_id, name, value, *, hidden=False)[source]
Generate the HTML for a command detail.
Create the HTML snippet for a detail associated with a command that was run.
- Parameters:
- Return type:
- Returns:
The HTML snippet for this command detail.
- shell_logger.html_utilities.command_detail_list(cmd_id, *args)[source]
Generate the list of command details.
Generate the HTML for a list of details associated with a command that was run.
- Parameters:
- Yields:
The header, followed by each of the details associated with the command that was run, and then the footer.
- Return type:
- shell_logger.html_utilities.diagnostics_card(cmd_id, *args)[source]
Generate a diagnostics card.
Generate a card containing system diagnostic information associated with a command that was run.
- Parameters:
- Yields:
The header, followed by each piece of diagnostic information, and then the footer.
- Return type:
- shell_logger.html_utilities.disk_time_series_plot(cmd_id, data_tuples, volume_name)[source]
Generate a time series plot of disk usage.
Create the HTML for a plot of the disk usage time series data for a particular volume.
- Parameters:
- Return type:
- Returns:
A HTML snippet for a plot of the given data.
Todo
Should we combine this with
time_series_plot()?
- shell_logger.html_utilities.embed_html(resource)[source]
Embed the contents of a file in the HTML.
Get a HTML
resourcefrom a file for the sake of embedding it into the HTML header.- Parameters:
resource (
str) – The name of a HTML file to embed.- Return type:
- Returns:
The contents of the file.
Todo
Why do we use
pkgutil.get_data()instead of a simpleread().
- shell_logger.html_utilities.embed_script(resource)[source]
Embed a script in the HTML.
Wrap the given
resourcein an appropriate<script>...</script>block for embedding in the HTML header.
- shell_logger.html_utilities.embed_style(resource)[source]
Embed a style in the HTML.
Wrap the given
resourcein an appropriate<style>...</style>block for embedding in the HTML header.- Parameters:
resource (
str) – The name of a style file to embed.- Return type:
- Returns:
A string containing the
<style>...</style>block.
Todo
Should we combine this with
embed_script()andembed_html()?
- shell_logger.html_utilities.fixed_width(text)[source]
Convert the text to a fixed-width font.
Wrap the given
textin a<pre><code>...</code></pre>block such that it displays in a fixed-width font.
- shell_logger.html_utilities.flatten(element)[source]
Turn a tree of lists into a flat iterable of strings.
- shell_logger.html_utilities.html_encode(text)[source]
Replace special characters with their HTML encodings.
- shell_logger.html_utilities.html_header()[source]
Get the HTML header, complete with embedded styles and scripts.
- Return type:
- Returns:
A string with the
<head>...</head>contents.
- shell_logger.html_utilities.html_message_card(log)[source]
Generate the HTML for a message card.
Generate the HTML for a card corresponding to a message to only be included in the HTML log file (e.g., not printed to
stdoutas well).
- shell_logger.html_utilities.load_template(template)[source]
Load a template HTML file.
- Parameters:
template (
str) – The file name to load.- Return type:
- Returns:
A string containing the contents of the file.
Todo
Should we combine this with
embed_html()?
- shell_logger.html_utilities.message_card(log)[source]
Generate a message card.
Generate the HTML for a card corresponding to a message to be both printed to
stdoutand included in the HTML log file.
- shell_logger.html_utilities.nested_simplenamespace_to_dict(namespace)[source]
Convert a
SimpleNamespaceto adict.Convert a
SimpleNamespace, which may include nested namespaces, iterables, and mappings, to adictcontaining the equivalent items.
- shell_logger.html_utilities.opening_html_text()[source]
Get the opening HTML text.
- Return type:
- Returns:
A string containing the first line of the HTML document through
</head>.
- shell_logger.html_utilities.output_block(output, name, cmd_id)[source]
Generate an output block.
Given the output from a command, generate the HTML equivalent for inclusion in the log file.
- shell_logger.html_utilities.output_block_card(title, output, cmd_id, *, collapsed=True)[source]
Generate an output block card.
Given the output from a command, generate a corresponding HTML card for inclusion in the log file.
- Parameters:
- Yields:
The header, followed by each line of the output, and then the footer.
- Return type:
- shell_logger.html_utilities.output_block_html(lines, name, cmd_id)[source]
Generate the HTML for an output block.
Given the output of a command, generate its HTML equivalent for inclusion in the log file.
- Parameters:
- Yields:
The header, followed by the HTML corresponding to each line of output, and then the footer.
- Return type:
- shell_logger.html_utilities.output_line_html(line, line_no)[source]
Generate the HTML for a line of output.
Given a line of output from a command, along with the corresponding line number, create the HTML equivalent to be included in the log file.
- shell_logger.html_utilities.parent_logger_card_html(name, *args)[source]
Generate the HTML for a parent logger card.
Generate the HTML for the card corresponding to the parent
ShellLogger. The HTML elements are yielded one at a time to avoid loading all the data from theShellLoggerinto memory at once.
- shell_logger.html_utilities.sgr_24bit_color_to_html(sgr_params)[source]
Convert 24-bit SGR colors to HTML.
Convert a 24-bit Select Graphic Rendition (SGR) code to valid HTML/CSS.
- shell_logger.html_utilities.sgr_4bit_color_and_style_to_html(sgr)[source]
Convert from Select Graphic Rendition (SGR) codes to CSS styles.
- shell_logger.html_utilities.sgr_8bit_color_to_html(sgr_params)[source]
Convert 8-bit SGR colors to HTML.
Convert an 8-bit Select Graphic Rendition (SGR) code to valid HTML/CSS.
- shell_logger.html_utilities.sgr_to_html(text)[source]
Convert SGR to HTML.
Translate Select Graphic Rendition (SGR, a.k.a. ANSI escape codes) to valid HTML/CSS.
- shell_logger.html_utilities.split_template(template, split_at, **kwargs)[source]
Subdivide a HTML template.
Take a templated HTML snippet and split it into a header and footer, meaning everything that comes before and after the line containing
split_at. Also determine the indentation for the content that will be inserted between the header and footer.Example
If the following snippet is
templateandsplit_atischild_body, then the header is lines 1-6, the footer is lines 8-9, and the indent is eight spaces.1<details class="child-logger"> 2 <summary> 3 <h6 class="child-logger-heading">{name}</h6> 4 <span class="duration"> (Duration: {duration})</span> 5 </summary> 6 <div class="child-logger-body"> 7 {child_body} 8 </div> 9</details>
- shell_logger.html_utilities.stat_chart_card(labels, data, title, identifier)[source]
Create the HTML for a two-dimensional plot.