Csv to Dot for Graphviz
- class csv_to_dot.csv_to_dot.CsvToDot(nodes_shape: str = 'box', nodes_style: str = 'filled', nodes_bg_color: str = 'blue', nodes_font_color: str = 'white')
Convert a 2 columns CSV file to a .dot, who can be converted with Graphviz to .jpg, .ps, …
- _csv_fh
Protected. CSV file handler
- Type
handler
- _node_indice
Protected. Indice to increment at each node
- Type
int
- _node_key_tpl
Protected. Template to create node key
- Type
string
- _nodes
Protected. All nodes, key>label
- Type
dict
- _edges
Protected. Dict of list with all edges
- Type
dict
- _dot_tpl
Protected. Jinja template for dot file
- Type
jinja2.Template
- _nodes_opts
Protected. Nodes options
- Type
dict
- __init__(nodes_shape: str = 'box', nodes_style: str = 'filled', nodes_bg_color: str = 'blue', nodes_font_color: str = 'white')
Default constructor
- Parameters
nodes_shape (str) – Nodes option : shape, default : box
nodes_style (str) – Nodes option : style, default : filled
nodes_bg_color (str) – Nodes option : background color, default : blue
nodes_font_color (str) – Nodes option : font color, default : white
- _add_edge(n1: str, n2: str)
Store edge between n1 > n2
- Parameters
n1 (string) – Node 1 : label
n2 (string) – Node 2 : label
- _close_fh()
Close file handlers
- _create_node_key() str
Create new node key
- Returns
Node key
- Return type
string
- _csv_reader(local_file: str, delimiter: str)
Create CSV reader
- Parameters
local_file (string) – Absolute local file path to csv file
delimiter (string) – Csv delimiter
- Returns
Csv reader
- Return type
csv.Reader
- _dict_search_value(d: dict, value: str) Optional[str]
Search value on dict & returns key if exists
- Parameters
d (dict) – Dictionnary to lookup
value (string) – Value to get key
- Returns
Key if found. None otherwise
- Return type
string|None
- _flat_edges_to_dot() list
Convert all edges to a list for templating
- Returns
Edges for jinja2 templates
- Return type
string[]
- _flat_nodes_to_dot() list
Convert all nodes to a list for templating
- Returns
Nodes for jinja2 templates
- Return type
string[]
- _get_fh_csv(local_file: str)
Open file handler : csv file (singleton)
- Parameters
local_file (string) – Absolute local file path to csv file
- Returns
Opened file
- Return type
handler
- _get_node_key(node: str) str
Get/create a node key
- Parameters
node (string) – Node label
- Returns
Key associated to label
- Return type
string
- _init_j2()
Init jinja2
- _init_resources()
Init resources used by system : init jinja2
- _nodes_search_value(value: str) Optional[str]
Seach node key from value
- Parameters
value (string) – Node value to get key
- Returns
Node key if found. None otherwise
- Return type
string|None
- _print_dot(local_file: Optional[str] = None) bool
Print dot file
- Parameters
local_file (string|None) – Absolute local file path to create .dot file. If None, print on stdout
- Returns
True if write on stdout. False otherwise
- Return type
bool
- _print_dot_file(local_file: str, content: str)
Print dot file on stdout
- Parameters
local_file (string) – Absolute local file path to create .dot file
content (string) – Content to print
- _print_dot_stdout(content: str)
Print dot file on stdout
- Parameters
content (string) – Content to print
- _print_graphvz_instructions(local_file: str)
Print some instructions to use graphwiz on stdout
- Parameters
local_file (string) – Absolute local file path to create .dot file
- run(local_in_file: str, delimiter: str = ';', local_out_file: Optional[str] = None)
Run process csv > dot
- Parameters
local_in_file (string) – Absolute local file path to csv file
delimiter (string) – Csv delimiter. Default : ‘;’
local_out_file (string|None) – Absolute local file path to create .dot file. If None, print on stdout
- csv_to_dot.csv_to_dot.MODULE_PATH = '/home/debian/modules/python-csv-to-dot/csv_to_dot'
Current module path
- csv_to_dot.csv_to_dot.RESOURCE_PATH = '/home/debian/modules/python-csv-to-dot/csv_to_dot/resources'
Resource path