Graph-talk Export API

class gt.export.ExportProcess

Bases: gt.core.VisitorProcess

Export process is a base class for the serialization processes. It is a child of gt.core.VisitorProcess with support of writing serialization data to a file while visiting gt.core.Graph elements. For a better readability, each graph element gets a unique name depending on its class. Uses gt.core.VisitorProcess.visit_event event as a trigger for the export functions.

FILENAME = 'file'

Target file name parameter, a part of the start context.

ID_PATTERN = '%s_%s'

Element id pattern.

start_export(new=True)

Starts the export, opens the file if specified.

Parameters:new (bool.) – if True, the file content will be cleared.
write_data(data)

Writes data to an open file or to the stdout.

Parameters:data (str.) – data to be written.
stop_export(finished=True)

Stops the writing to a file and closes it, if it was opened.

Parameters:finished (bool.) – True if the process is finished.
get_type_id(element)

Converts the element type to the id, for example gt.core.ComplexNotion will be converted to “cn”, gt.core.Relation will be converted to “r” and so on.

Parameters:element – object to get the type id.
Return type:str.
Returns:class name converted to the id.
get_serial_id(type_id)

Gets the serialization id for the specified type: “type_id_NN”, where NN is a 0-based counter for the type. Increases the counter after use. Uses ExportProcess.ID_PATTERN as a template.

Parameters:type_id (str.) – type identifier
Return type:str.
Returns:serialization id for the type.
get_object_id(obj)

Gets the non-graph element identifier.

Parameters:obj – input object.
Returns:object id.
Return type:str.
get_element_id(element)

Gets the unique element serialization id. Safe to call multiple times, will return the same id for the same element.

Parameters:element – serializing object.
Return type:str.
Returns:element id string.
export_graph(graph)

Called when a graph is visited for serialization.

Parameters:graph – serializing graph.
Return type:str.
Returns:export string to write to the file or None.
export_notion(notion)

Called when a notion is visited for serialization.

Parameters:notion – serializing notion.
Return type:str.
Returns:export string to write to the file or None.
export_relation(relation)

Called when a relation is visited for serialization.

Parameters:relation – serializing graph.
Return type:str.
Returns:export string to write to the file or None.
on_export()

Export event, calls ExportProcess.export_graph(), ExportProcess.export_notion(), or ExportProcess.export_relation() depending on gt.core.Process.current element type. If export data is not empty, it will be written to the file using ExportProcess.write_data().

Returns:True
Return type:bool.
on_new(message, context)

Gets the file name from ExportProcess.FILENAME context parameter, opens it using ExportProcess.start_export() with new=True and clears internal counters.

on_resume(message, context)

Opens current ExportProcess.filename to continue the writing using ExportProcess.start_export() with new=False.

handle(message, context)

In addition to gt.core.Process.handle() closes the file, calling ExportProcess.stop_export().

setup_events()

In addition to gt.core.Process.setup_events() adds ExportProcess.on_export() as a visit event.

filename

Target file name (read-only).

Returns:current file name.
Return type:str.
out

Output buffer (read-only).

Returns:export buffer, if no output file specified.
Return type:str.
class gt.export.DotExport

Bases: gt.export.ExportProcess

Exports the graph to the DOT language (http://en.wikipedia.org/wiki/DOT_(graph_description_language)) format.

get_condition_string(relation)

Turns the gt.core.Relation‘s condition to a printable string.

Parameters:relation (Relation.) – input relation.
Returns:condition string or an empty string.
Return type:str.
get_dot_string(node_string, **attributes)

Creates the DOT string for the node, like a -> b [label = “*”]

Parameters:
  • node_string (str.) – node id string.
  • attributes – additional attributes, like label or shape.
Returns:

DOT string ready for export.

Return type:

str.

get_object_id(obj)

Gets the non-element object id. Uses a separate list to export the objects after the elements export.

Parameters:obj – non-element object.
Returns:object id.
Return type:str.
get_element_id(element)

Gets the unique element serialization id. Supports empty elements (for relations without gt.core.Relation.object).

Parameters:element – serializing object.
Returns:object id.
Return type:str.
export_empty(counter)

Exports an empty element as a point shape.

Parameters:counter (int.) – element counter
Returns:export string to write to the file or None.
Return type:str.
export_object(name)

Exports a non-element object as a rect shape.

Parameters:name – object’s name.
Returns:export string to write to the file or None.
Return type:str.
stop_export(finished=True)

When finished dumps empty and non-graph objects and puts the closing bracket.

Parameters:finished (bool.) – True if the process is finished.

Previous topic

Graph-talk Debug API

This Page