gwdetchar.io.html module

Utilties for HTML output

class gwdetchar.io.html.FancyPlot(img, caption=None)[source]

Bases: object

A helpful class of objects that coalesce image links and caption text for fancybox figures.

Parameters:

img : str or FancyPlot

either a filename (including relative or absolute path) or another FancyPlot instance

caption : str

the text to be displayed in a fancybox as this figure’s caption

gwdetchar.io.html.about_this_page(config, packagelist=True)[source]

Write a blurb documenting how a page was generated, including the command-line arguments and configuration files used

Parameters:

config : str, list, optional

the absolute path(s) to one or a number of INI files used in this process

packagelist : bool, optional

boolean switch to include (True) or exclude (False) a comprehensive list of system packages

Returns:

page : page

the HTML page to be inserted into the #main <div>.

Write a channel name as a link to the Channel Information System

Parameters:

channel : str

the name of the channel to link

**params

other HTML parmeters for the <a> tag

Returns:
html : str
gwdetchar.io.html.close_page(page, target, **kwargs)[source]

Close an HTML document with markup then write to disk

This method writes the closing markup to complement the opening written by init_page, something like:

</div>
<footer>
    <!-- some stuff -->
</footer>
</body>
</html>
Parameters:

page : markup.page

the markup object to close

target : str

the output filename for HTML

gwdetchar.io.html.dropdown(text, links, active=None, class_='dropdown-toggle')[source]

Construct a dropdown menu in bootstrap format

Parameters:

text : str

dropdown menu header

links : list

list of (Link text, linkurl) tuples or dict of such tuples for grouped dropdowns

active : int or list of ints, optional

collection of links to make active, default: None

class_ : str, optional

object class of the dropdown menu, default: 'dropdown-toggle'

Returns:

page : page

HTML element with the following grammar: .. code:: html

<a>text</a> <ul>

<li>link</li> <li>link</li>

</ul>

Format links within a dropdown menu

Parameters:

page : page

a page object to format in-place

link : page or list

the link(s) to format

active : bool, optional

boolean switch to enable (True) or disable (False) an active link, default: False

class_ : str, optional

object class of the link, default: ''

gwdetchar.io.html.fancybox_img(img, linkparams={}, **params)[source]

Return the markup to embed an <img> in HTML

Parameters:

img : FancyPlot

a FancyPlot object containing the path of the image to embed and its caption to be displayed

linkparams : dict

the HTML attributes for the <a> tag

**params

the HTML attributes for the <img> tag

Returns:

page : page

the markup object containing fancyplot HTML

gwdetchar.io.html.finalize_static_urls(static, cssfiles, jsfiles)[source]

Finalise the necessary CSS and javascript files as URLS.

The method parses the lists of files given, copying any local files into static as necessary to create resolvable URLs to include in the HTML <head>.

Parameters:

static : str

the target directory for the static files, will be created if necessary

cssfiles : list of str

the list of CSS files to include

jsfiles : list of str

the (complete) list of javascript files to include

Returns:

cssurls : list of str

the finalised list of CSS files

jsurls : list of str

the finalised list of javascript files

gwdetchar.io.html.get_brand(ifo, name, gps, about=None)[source]

Return a brand for navigation bar formatting

Parameters:

ifo : str

interferometer prefix for color-coding, e.g. 'L1'

name : str

name of the analysis, e.g. 'Scattering'

gps : float

GPS second of the analysis

about : str, optional

relative path to the about page for this analysis, default: None

Returns:

brand : page

the navbar brand page object

class_ : str

object class of the navbar

gwdetchar.io.html.get_command_line(language='bash')[source]

Render the command line invocation used to generate a page

Parameters:

language : str, optional

type of environment the code is run in, default: 'bash'

Returns:

page : page

fully rendered command-line arguments

Write an HTML <a> tag

Parameters:

href : str

the URL to point to

txt : str

the text for the link

target : str, optional

the target of this link

**params

other HTML parameters for the <a> tag

Returns:
html : str
gwdetchar.io.html.navbar(links, class_='navbar navbar-fixed-top', brand=None, collapse=True)[source]

Construct a navigation bar in bootstrap format

Parameters:

links : list

list of either (text, URL) tuples or page objects. Tuples will be written in <a> tags while pages will be copied directly. Both will be enclosed in a <li> element inside the navbar

class_ : str, optional

navbar object class, default: 'navbar navbar-fixed-top'

brand : str or page, optional

branding for the navigation bar, default: None

collapse : bool, optional

whether to toggle all dropdown menus, default: True

Returns:

page : page

navbar HTML page object

gwdetchar.io.html.new_bootstrap_page(base='.', lang='en', refresh=False, navbar=None, **kwargs)[source]

Create a new page with custom twitter bootstrap CSS and JS headers

Parameters:

base : str

relative path to the base directory where the page is located

lang : str, optional

language of the page, default: en

refresh : bool, optional

boolean switch to enable periodic page refresh, default: False

navbar : str, optional

HTML enconding of a floating navbar, will be ignored if not given, default: None

gwdetchar.io.html.package_list()[source]

Get the list of packages installed alongside this one

Returns a list of dict

gwdetchar.io.html.package_table(h2='Environment', class_='table table-hover table-condensed table-responsive', caption='Table of packages installed in the production environment', id_='package-table')[source]

Write a table listing packages installed in the current environment

Parameters:

h2 : str, None, optional

the header for the HTML section

caption : str, None, optional

the <caption> for the package table

Returns:

html : str

an HTML table

gwdetchar.io.html.render_code(code, language)[source]

Render a block of code with syntax highlighting

Parameters:

code : str

a raw block of source code

language : str

language the code is written in, e.g. 'python'

gwdetchar.io.html.scaffold_omega_scans(times, channel, plot_durations=[1, 4, 16], scandir='.')[source]

Preview a batch of omega scans in HTML

gwdetchar.io.html.scaffold_plots(plots, nperrow=3)[source]

Embed a list of images in a bootstrap scaffold

Parameters:

plot : list of FancyPlot

the list of image paths to embed

nperrow : int

the number of images to place in a row (on a desktop screen)

Returns:

page : page

the markup object containing the scaffolded HTML

gwdetchar.io.html.table(headers, data, caption=None, separator='', id=None, **class_)[source]

Write a <table> with one row of headers and many rows of data

Parameters:

headers : list

list of column header names

data : list of lists

list of column data lists, for m rows and n columns, this should have dimensions m x n

caption : str, optional

content for this table’s <caption>

**class_

class attribute declarations for each tag used in the table, any of table, thead, tbody, tr, th, td, caption

Returns:

table : page

a formatted HTML page object containing the <table>

gwdetchar.io.html.write_arguments(content, start, end, flag=None, section='Parameters', info='This analysis used the following parameters:', id_='parameters')[source]

Render an informative section with run parameters in HTML

Parameters:

content: `dict`

a collection of parameters to list

section: `str`

name of the section, will appear as a header with an <h2> tag

gwdetchar.io.html.write_flag_html(flag, span=None, id=0, parent='accordion', context='warning', title=None, plotdir=None, plot_func=<function plot_segments at 0x7f74f281b378>, **kwargs)[source]

Write HTML for data quality flags

Write a <footer> for a bootstrap page

Parameters:

about : str, optional

path of about page to link

link : str, optional

HTML link to software name and version

issues : str, optional

HTML link to issue report page

content : str or page, optional

additional footer content

Returns:

page : page

the markup object containing the footer HTML

gwdetchar.io.html.write_param(param, value)[source]

Format a parameter value with HTML