#!/usr/bin/env python3 import birchscript import os import os.path import subprocess import sys # For systems on which there is no PostScript viewer (an increasing # number of systems), this script runs ps2pdf and then opens the # PDF viewer to view the PDF file. After viewing, the # temporary file is deleted. # $ACE_Viewer is the name of the program. # $1 is the file for the program to use. #Choose a PDF viewer """ ensure that there are enough command line arguments to parse """ if len(sys.argv) < 2: print("Missing FILE parameter"); print(""); print("Usage: PStoPDFviewer.py FILE"); exit(); ACE_PDF_COMMAND = 'gv' if os.environ.has_key("ACE_PDF_COMMAND"): ACE_PDF_COMMAND = os.environ.get("ACE_PDF_COMMAND") else: os.putenv('ACE_PDF_COMMAND', 'gv') INFILE = str(sys.argv[1]) print('Converting ' + INFILE + ' to PDF...') TEMPF = 'PStoPDFviewer_' + str(os.getpid()) + '.pdf' subprocess.call(['ps2pdf', INFILE, TEMPF]) #ls -l ./$tempfile if os.path.exists(TEMPF): birchscript.Cleanrun([[ACE_PDF_COMMAND, TEMPF]], [TEMPF], True)