Onyx logo

Previous topic

onyx.util.discrete – Tools for working with discrete spaces.

Next topic

onyx.util.duration – Support for reproducible strings for floating point durations

This Page

onyx.util.dotdisplay – Tools and mix-in classes for DOT-based graphical display.

DISPLAY_COMMAND_FORMAT is the default command-line for displaying a DOT file, where %s is replaced with the name of the file to display

class onyx.util.dotdisplay.DotDisplay

Bases: object

Mix-in baseclass for displaying a DOT rendering of an object.

Uses the object’s :meth`dot_iter` method to display a DOT rendering of the object.

dot_display(dot_iter=None, temp_file_prefix=None, display_command_format=None, **kwargs)

Display a dot-generated representation of the graph.

Optional dot_iter is the generator function to pull on for text lines of DOT code. It is called with kwargs. It defaults to the object’s dot_iter method

Optional temp_file_prefix is the prefix used for the temporary filename. It defaults to the name of the type of self.

Optional display_command_format is a formatting string, with %s where the temporary filename goes, that is used to generate the command that will display the file. It defaults to the the value of the module’s DISPLAY_COMMAND_FORMAT attribute.

Remaining keyword arguments, kwargs, are handed to the dot_iter generator function. In general, no arguments are necessary to get an object to display.

Returns a tuple of four items: (temp_filename, stdout, stderr, cmd), where temp_filename is the name of the temporary file that gets created for the display command to use, stdout and stderr are the standard-out and standard-error from the command, and cmd is a string representing the command. The caller is responsible for removing temp_filename.

Raises AttributeError if dot_iter is not given and the object doesn’t have a dot_iter method

Raises SubprocessError if the command fails to execute or if the command exits with a non-zero return code.

onyx.util.dotdisplay.test_DotDisplay()

Function for testing DotDisplay functionality.

>>> obj = test_DotDisplay()
>>> temp_filename, stdout, stderr, cmd = obj.dot_display(display_command_format="cat %s")
>>> temp_filename 
'/tmp/TestDotDisplay_....dot'
>>> cmd 
'cat /tmp/TestDotDisplay_....dot'
>>> stdout
'digraph { \n  n00 [label="node_00"]; \n  n01 [label="node_01"]; \n  n00 -> n01; \n} \n'
>>> stderr
''
>>> os.remove(temp_filename)