#!/usr/bin/env python
import sys,os

if len(sys.argv)<3:
  print "Usage: "+sys.argv[0]+ " info_file" + " rendered_file"
  print "eg. "+sys.argv[0]+" /home/myuser/CCP4_PROJECT/myfile-pov.py "+" myrenderedfile.png"
  print "The file with name similar to /home/myuser/CCP4_PROJECT/myfile-pov.py"
  print "is produced when you output a povray input file from ccp4mg."
  print "It contains information about what the text labels are and where to"
  print "position them."
  print "It will be found in your ccp4 project directory or the directory"
  print "you specified to save to if you are not using a project currently."
  print "The file with name similar to myrenderedfile.png (or myrenderedfile.bmp)"
  print "on Windows is the rendered image produced by PovRay."
  sys.exit()

if sys.path[0] == '':
  the_path = '.'
else:
  the_path =  sys.path[0]

the_path = the_path + '/../'

pypath = os.environ.get('PYTHONPATH','')
if pypath:
  pypath = os.path.join(the_path,'python/ui/') + ":" + os.path.join(the_path,'lib/') + ":" + pypath
else:
  pypath = os.path.join(the_path,'python/ui/') + ":" + os.path.join(the_path,'lib/')
os.environ['PYTHONPATH'] = pypath

if sys.platform.find('darwin')>=0:
  dlpath = os.environ.get('DYLD_LIBRARY_PATH','')
elif sys.platform.find('sunos')>=0:
  dlpath = os.environ.get('LIBPATH','')
else:
  dlpath = os.environ.get('LD_LIBRARY_PATH','')

if dlpath:
  dlpath = os.path.join(the_path,'lib/') + ":" + dlpath
else:
  dlpath = os.path.join(the_path,'lib/')
os.environ['LD_LIBRARY_PATH'] = dlpath
os.environ['DYLD_LIBRARY_PATH'] = dlpath
os.environ['LIBPATH'] = dlpath

path = os.environ.get('PATH','')
if path:
  path = os.path.join(the_path,'lib/') + ":" + os.path.join(the_path,'bin/') + ":" + os.path.join(the_path,'pythondist/bin/') + path
else:
  path = os.path.join(the_path,'lib/') + ":" + os.path.join(the_path,'bin/') + ":" + os.path.join(the_path,'pythondist/bin/')
os.environ['PATH'] = path

os.execvp("python",sys.argv) 
