

def _present_graph(dot_filename, filename=None):
    'Present a .dot file to the user in the requested fashion.\n\n    If ``filename`` is provided, runs ``dot`` to convert the .dot file\n    into the desired format, determined by the filename extension.\n\n    If ``filename`` is not provided, tries to launch ``xdot``, a\n    graphical .dot file viewer.  If ``xdot`` is not present on the system,\n    converts the graph to a PNG.\n    '
    if (filename == dot_filename):
        return
    if ((not filename) and _program_in_path('xdot')):
        print('Spawning graph viewer (xdot)')
        subprocess.Popen(['xdot', dot_filename], close_fds=True)
    elif _program_in_path('dot'):
        if (not filename):
            print('Graph viewer (xdot) not found, generating a png instead')
            filename = (dot_filename[:(- 4)] + '.png')
        (stem, ext) = os.path.splitext(filename)
        cmd = ['dot', ('-T' + ext[1:]), ('-o' + filename), dot_filename]
        dot = subprocess.Popen(cmd, close_fds=False)
        dot.wait()
        if (dot.returncode != 0):
            print(('dot failed (exit code %d) while executing "%s"' % (dot.returncode, ' '.join(cmd))))
        else:
            print(('Image generated as %s' % filename))
    elif (not filename):
        print('Graph viewer (xdot) and image renderer (dot) not found, not doing anything else')
    else:
        print('Image renderer (dot) not found, not doing anything else')

dataset/ETHPy150Open Exa-Networks/exabgp/lib/exabgp/dep/objgraph.py _present_graph/original