Last active
December 6, 2025 11:33
-
-
Save mdmitry1/671c4eb38e85a473af1b5f00230b9eb3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3.12 | |
| # coding: utf-8 | |
| # author: github.com/vuiseng9 | |
| # dependency ubt1804: graphviz libgraphviz-dev libgl1-mesa-glx | |
| import os, sys | |
| import pygraphviz | |
| from glob import glob | |
| from natsort import natsorted | |
| from rich import print as rprint | |
| def dot2png(dotfile, pngfile=None): | |
| if pngfile is None: | |
| pngfile = dotfile | |
| if dotfile.endswith(".dot"): | |
| pngfile = pngfile.replace('.dot', '.png') | |
| else: | |
| pngfile += '.png' | |
| dotgraph = pygraphviz.AGraph(dotfile) | |
| dotgraph.draw(pngfile, prog='dot') | |
| try: | |
| nargs=len(sys.argv)-1 | |
| if nargs != 1: | |
| raise ValueError(f"\n[red]ERROR: Invalid number of arguments:[/red] {nargs}\n\n[blue]Usage: dot2png.py <.dot or directory>") | |
| except ValueError as e: | |
| rprint(f"{e}\n") | |
| exit(1) | |
| target = sys.argv[1] | |
| try: | |
| if os.path.isfile(target) and target.endswith('.dot'): | |
| dot2png(target) | |
| elif os.path.isdir(target): | |
| for root, dirs, files in os.walk(target): | |
| for file in natsorted(files): | |
| if file.endswith('.dot'): | |
| dot2png('/'.join([root, file])) | |
| else: | |
| rprint(f"\n[red]Argument [bold]{target}[/bold] is not a dot file nor a directory\n\n[blue]Usage: dot2png.py <.dot or directory>\n") | |
| except Exception as e: | |
| rprint(f"[red]ERROR: {e}\n") | |
| exit(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3.14 | |
| # coding: utf-8 | |
| # author: github.com/vuiseng9 | |
| # dependency ubt1804: graphviz libgraphviz-dev libgl1-mesa-glx | |
| import os | |
| from sys import argv | |
| import pygraphviz | |
| from glob import glob | |
| from natsort import natsorted | |
| from rich import print as rprint | |
| def dot2png(dotfile, pngfile=None): | |
| if pngfile is None: | |
| pngfile = dotfile | |
| if dotfile.endswith(".dot"): | |
| pngfile = pngfile.replace('.dot', '.png') | |
| else: | |
| pngfile += '.png' | |
| dotgraph = pygraphviz.AGraph(dotfile) | |
| dotgraph.draw(pngfile, prog='dot') | |
| try: | |
| nargs=len(argv)-1 | |
| if nargs != 1: | |
| raise ValueError(f"\n[red]ERROR: Invalid number of arguments:[/red] {nargs}\n\n[blue]Usage: dot2png.py <.dot or directory>") | |
| except ValueError as e: | |
| rprint(f"{e}\n") | |
| exit(1) | |
| target = argv[1] | |
| try: | |
| if os.path.isfile(target) and target.endswith('.dot'): | |
| dot2png(target) | |
| elif os.path.isdir(target): | |
| for root, dirs, files in os.walk(target): | |
| for file in natsorted(files): | |
| if file.endswith('.dot'): | |
| dot2png('/'.join([root, file])) | |
| else: | |
| rprint(f"\n[red]Argument [bold]{target}[/bold] is not a dot file nor a directory\n\n[blue]Usage: dot2png.py <.dot or directory>\n") | |
| except Exception as e: | |
| rprint(f"[red]ERROR: {e}\n") | |
| exit(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| digraph G { | |
| node [shape=box, color=blue] // No semicolon | |
| edge [color=red] // No semicolon | |
| A [label="Node A", style=filled, fillcolor=lightblue]; | |
| B [label="Node B"]; | |
| C [label="Node C", shape=circle]; | |
| A -> B [label="Flow 1", arrowhead=vee]; | |
| B -> C [label="Flow 2"]; | |
| C -> A [label="Loop", style=dashed]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/tcsh -f | |
| \rm -f mygraph.png >& /dev/null | |
| if($#argv > 0 ) then | |
| if("-clean" == "$argv[1]") exit(0) | |
| endif | |
| dot2png.py mygraph.dot | |
| timeout 5 eog mygraph.png |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment