Processes graph description using an external software. This method is used to convert a graphviz format to an image. :param graph: GraphViz graph description :param prog: which graphviz program to use :param format: output type (svg, ps, gif, jpg, etc.), passed to dot's "-T"
(
graph, # type: str
prog=None, # type: Optional[str]
format=None, # type: Optional[str]
target=None, # type: Optional[Union[IO[bytes], str]]
type=None, # type: Optional[str]
string=None, # type: Optional[bool]
options=None # type: Optional[List[str]]
)
| 1000 | |
| 1001 | |
| 1002 | def do_graph( |
| 1003 | graph, # type: str |
| 1004 | prog=None, # type: Optional[str] |
| 1005 | format=None, # type: Optional[str] |
| 1006 | target=None, # type: Optional[Union[IO[bytes], str]] |
| 1007 | type=None, # type: Optional[str] |
| 1008 | string=None, # type: Optional[bool] |
| 1009 | options=None # type: Optional[List[str]] |
| 1010 | ): |
| 1011 | # type: (...) -> Optional[str] |
| 1012 | """Processes graph description using an external software. |
| 1013 | This method is used to convert a graphviz format to an image. |
| 1014 | |
| 1015 | :param graph: GraphViz graph description |
| 1016 | :param prog: which graphviz program to use |
| 1017 | :param format: output type (svg, ps, gif, jpg, etc.), passed to dot's "-T" |
| 1018 | option |
| 1019 | :param string: if not None, simply return the graph string |
| 1020 | :param target: filename or redirect. Defaults pipe to Imagemagick's |
| 1021 | display program |
| 1022 | :param options: options to be passed to prog |
| 1023 | """ |
| 1024 | |
| 1025 | if format is None: |
| 1026 | format = "svg" |
| 1027 | if string: |
| 1028 | return graph |
| 1029 | if type is not None: |
| 1030 | warnings.warn( |
| 1031 | "type is deprecated, and was renamed format", |
| 1032 | DeprecationWarning |
| 1033 | ) |
| 1034 | format = type |
| 1035 | if prog is None: |
| 1036 | prog = conf.prog.dot |
| 1037 | start_viewer = False |
| 1038 | if target is None: |
| 1039 | if WINDOWS: |
| 1040 | target = get_temp_file(autoext="." + format) |
| 1041 | start_viewer = True |
| 1042 | else: |
| 1043 | with ContextManagerSubprocess(conf.prog.display): |
| 1044 | target = subprocess.Popen([conf.prog.display], |
| 1045 | stdin=subprocess.PIPE).stdin |
| 1046 | if format is not None: |
| 1047 | format = "-T%s" % format |
| 1048 | if isinstance(target, str): |
| 1049 | if target.startswith('|'): |
| 1050 | target = subprocess.Popen(target[1:].lstrip(), shell=True, |
| 1051 | stdin=subprocess.PIPE).stdin |
| 1052 | elif target.startswith('>'): |
| 1053 | target = open(target[1:].lstrip(), "wb") |
| 1054 | else: |
| 1055 | target = open(os.path.abspath(target), "wb") |
| 1056 | target = cast(IO[bytes], target) |
| 1057 | proc = subprocess.Popen( |
| 1058 | "\"%s\" %s %s" % (prog, options or "", format or ""), |
| 1059 | shell=True, stdin=subprocess.PIPE, stdout=target, |
no test coverage detected