Mercurial > hg > config
view python/gview.py @ 803:70e9f82c2443
* prime actually doesnt work; if i had a decent CI for my own software, i would have known that; but i dont
* resource_filename.py even _says_ example in it. let us hope it is telling the truth
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Fri, 28 Oct 2016 17:00:37 -0700 |
parents | 5e8d3f68a997 |
children |
line wrap: on
line source
#!/usr/bin/env python # -*- coding: utf-8 -*- """ view graphviz files http://www.graphviz.org/ """ # imports import argparse import os import shlex import subprocess import sys import tempfile __all__ = ['main'] string = (str, unicode) class Parser(argparse.ArgumentParser): """CLI option parser""" def __init__(self): argparse.ArgumentParser.__init__(self, description=__doc__) self.add_argument('input', help='graphviz file to view') self.add_argument('-o', '--output', dest='output', help="path to save to") self.add_argument('-e', '--program', dest='program', default='fdp', help="GraphViz program to invoke [DEFAULT: %(default)s]") self.add_argument('-v', '--view', dest='viewer', default='feh -F', help="viewer") def main(args=sys.argv[1:]): """CLI""" # parse command line parser = Parser() options = parser.parse_args(args) # assert os.path.exists(options.input) output = options.output or tempfile.mktemp(suffix='.png') command = [options.program, options.input, '-Tpng', '-o', output] subprocess.check_call(command) assert os.path.exists(output) try: if options.viewer: viewer = shlex.split(options.viewer) subprocess.call(viewer + [output]) finally: if not options.output: os.remove(output) if __name__ == '__main__': main()