Mercurial > hg > config
comparison python/gview.py @ 690:5e8d3f68a997
shlex
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Mon, 02 Jun 2014 12:38:40 -0700 |
| parents | 34af6d5ac73c |
| children |
comparison
equal
deleted
inserted
replaced
| 686:34af6d5ac73c | 690:5e8d3f68a997 |
|---|---|
| 8 """ | 8 """ |
| 9 | 9 |
| 10 # imports | 10 # imports |
| 11 import argparse | 11 import argparse |
| 12 import os | 12 import os |
| 13 import shlex | |
| 13 import subprocess | 14 import subprocess |
| 14 import sys | 15 import sys |
| 15 import tempfile | 16 import tempfile |
| 16 | 17 |
| 17 __all__ = ['main'] | 18 __all__ = ['main'] |
| 26 self.add_argument('-o', '--output', dest='output', | 27 self.add_argument('-o', '--output', dest='output', |
| 27 help="path to save to") | 28 help="path to save to") |
| 28 self.add_argument('-e', '--program', dest='program', | 29 self.add_argument('-e', '--program', dest='program', |
| 29 default='fdp', | 30 default='fdp', |
| 30 help="GraphViz program to invoke [DEFAULT: %(default)s]") | 31 help="GraphViz program to invoke [DEFAULT: %(default)s]") |
| 31 self.add_argument('-v', '--view', dest='viewer', default='feh', | 32 self.add_argument('-v', '--view', dest='viewer', default='feh -F', |
| 32 help="viewer") | 33 help="viewer") |
| 33 | 34 |
| 34 | 35 |
| 35 def main(args=sys.argv[1:]): | 36 def main(args=sys.argv[1:]): |
| 36 """CLI""" | 37 """CLI""" |
| 50 subprocess.check_call(command) | 51 subprocess.check_call(command) |
| 51 assert os.path.exists(output) | 52 assert os.path.exists(output) |
| 52 | 53 |
| 53 try: | 54 try: |
| 54 if options.viewer: | 55 if options.viewer: |
| 55 subprocess.call([options.viewer, output]) | 56 viewer = shlex.split(options.viewer) |
| 57 subprocess.call(viewer + [output]) | |
| 56 finally: | 58 finally: |
| 57 if not options.output: | 59 if not options.output: |
| 58 os.remove(output) | 60 os.remove(output) |
| 59 | 61 |
| 60 | 62 |
