Skip to content

Commit

Permalink
python: Allow ovs-flowviz to run without graphviz.
Browse files Browse the repository at this point in the history
The graphviz library has a large set of dependencies, and as such
it may be desireable to not install it by default.

Before this patch execution of ovs-flowviz would end in
ImportError when graphviz is unavailable.

Exit with a friendly message instead, allowing the user to consume
the parts of the program that do not depend on graphviz.

Signed-off-by: Frode Nordahl <[email protected]>
Signed-off-by: 0-day Robot <[email protected]>
  • Loading branch information
fnordahl authored and ovsrobot committed Dec 19, 2024
1 parent 7672707 commit 169f9ab
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion python/ovs/flowviz/odp/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,27 @@

""" Defines a Datapath Graph using graphviz. """
import colorsys
import graphviz
import os
import random
import sys

from ovs.flowviz.odp.html import HTMLTree, HTMLFormatter
from ovs.flowviz.odp.tree import FlowTree
from ovs.flowviz.process import FileProcessor

try:
import graphviz
except ImportError:
graphviz = None


class GraphProcessor(FileProcessor):
def __init__(self, opts):
if graphviz is None:
print("ERROR: The graph sub-command depends on the graphviz "
"Python library, which does not appear to be installed.",
file=sys.stderr)
sys.exit(os.EX_UNAVAILABLE)
super().__init__(opts, "odp")

def start_file(self, name, filename):
Expand Down

0 comments on commit 169f9ab

Please sign in to comment.