#!/usr/bin/env python import subprocess import tempfile import os import shutil import sys # This script is called by ACEDB Pick_me_to_call records. # It copies the file to a temporary file in the current working directory, # and then runs the appropriate viewer. After viewing, the # temporary file is deleted. # $ACE_Viewer is the name of the program. # $1 is the file for the program to use. """ ensure that there are enough command line arguments to parse """ if len(sys.argv) < 2: print("Missing FILE parameter"); print(""); print("Usage: acePSviewer.py FILE"); exit(); """ get the FILE to open (the first command line argument) """ file_in = sys.argv[1] if not os.path.exists(file_in): print "File \"" + file_in + "\" not found!" #Choose a .pdf viewer if os.environ.get("ACE_PS_COMMAND"): ACE_PS_COMMAND = os.environ.get("ACE_PS_COMMAND") else: os.putenv("ACE_PS_COMMAND", "gv") ACE_PS_COMMAND = "gv" #print 'ACE_PS_COMMAND: ' + ACE_PS_COMMAND print "Copying " + file_in temp_file = tempfile.mkstemp("acedb_", ".ps") if temp_file and len(temp_file) > 1: shutil.copyfile(file_in, temp_file[1]) subprocess.call([ACE_PS_COMMAND, temp_file[1]]) os.remove(temp_file[1]) else: print "Error creating temp file"