| 1 |
#!@PYTHON@ |
| 2 |
# ^ python path substituted here is not depended-upon in Windows |
| 3 |
|
| 4 |
import os.path, sys, platform |
| 5 |
|
| 6 |
restart = 0 |
| 7 |
|
| 8 |
# This script handles restarting ascend if it's invoked without the full |
| 9 |
# complement of env vars. You can override values used by this script |
| 10 |
# by setting the appropriate env vars before this script is run. |
| 11 |
|
| 12 |
# Note that as well as env vars, ASCEND is also controllable using the |
| 13 |
# .ascend.ini file in the user's home directory. |
| 14 |
|
| 15 |
#----------------------------------------------------------------------- |
| 16 |
# Get locations of the installed files. On windows, these are defined in |
| 17 |
# in the registry. On other systems, these are defined at compile time |
| 18 |
# by @VARNAME@ substitution. |
| 19 |
|
| 20 |
if platform.system()=="Windows": |
| 21 |
import _winreg as wreg |
| 22 |
k = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, "SOFTWARE\ASCEND") |
| 23 |
print k |
| 24 |
|
| 25 |
# for some reason, QueryValue doesn't work on Py 2.4, need to use QueryValueEx. |
| 26 |
INSTALL_SOLVERS,t = wreg.QueryValueEx(k,"INSTALL_SOLVERS") |
| 27 |
INSTALL_MODELS,t = wreg.QueryValueEx(k,"INSTALL_MODELS") |
| 28 |
INSTALL_LIB,t = wreg.QueryValueEx(k,"INSTALL_LIB") |
| 29 |
INSTALL_ASCDATA,t = wreg.QueryValueEx(k,"INSTALL_ASCDATA") |
| 30 |
GTKLIBS,t = wreg.QueryValueEx(k,"GTKLIBS"); |
| 31 |
DEFAULT_ASCENDLIBRARY="%s;%s" % (INSTALL_SOLVERS,INSTALL_MODELS) |
| 32 |
|
| 33 |
PYVERSION = "@PYVERSION@" |
| 34 |
|
| 35 |
PYTHON=os.path.join(sys.prefix,"pythonw.exe") |
| 36 |
|
| 37 |
print "PYTHON =",PYTHON |
| 38 |
SEP=";" |
| 39 |
LDPATHVAR = 'PATH' |
| 40 |
else: |
| 41 |
INSTALL_LIB="@INSTALL_LIB@" |
| 42 |
INSTALL_ASCDATA="@INSTALL_ASCDATA@" |
| 43 |
INSTALL_MODELS = os.path.abspath(INSTALL_ASCDATA+"/models") |
| 44 |
INSTALL_SOLVERS = os.path.abspath(INSTALL_ASCDATA+"/solvers") |
| 45 |
PYTHON="@PYTHON@" |
| 46 |
DEFAULT_ASCENDLIBRARY="""@DEFAULT_ASCENDLIBRARY@""" |
| 47 |
SEP=":" |
| 48 |
LDPATHVAR = 'LD_LIBRARY_PATH' |
| 49 |
GTKLIBS = None # assume the GTK will be in the standard library path |
| 50 |
|
| 51 |
#----------------------------------------------------------------------- |
| 52 |
|
| 53 |
if os.environ.get(LDPATHVAR): |
| 54 |
LDPATH = os.environ.get(LDPATHVAR).split(SEP) |
| 55 |
else: |
| 56 |
LDPATH = [] |
| 57 |
|
| 58 |
if not os.environ.get('ASC_GDB'): |
| 59 |
# restarting messes up GDB so don't allow it |
| 60 |
|
| 61 |
if platform.system()=="Windows": |
| 62 |
# Put INSTALL_LIB then GTK at start of path |
| 63 |
if GTKLIBS in LDPATH: |
| 64 |
LDPATH.remove(GTKLIBS) |
| 65 |
LDPATH=[INSTALL_LIB,GTKLIBS]+LDPATH |
| 66 |
os.environ[LDPATHVAR] = SEP.join(LDPATH) |
| 67 |
restart = 1 |
| 68 |
elif INSTALL_LIB != "/usr/lib" and not INSTALL_LIB in LDPATH: |
| 69 |
# don't worry about GTK location; just ensure that LDPATH includes INSTALL_LIB |
| 70 |
LDPATH = [INSTALL_LIB] + LDPATH |
| 71 |
os.environ[LDPATHVAR] = SEP.join(LDPATH) |
| 72 |
restart = 1 |
| 73 |
|
| 74 |
# if ASCENDLIBRARY has been specified, make sure it's including the Model Library |
| 75 |
if os.environ.get('ASCENDLIBRARY'): |
| 76 |
envmodels = [os.path.abspath(i) for i in os.environ['ASCENDLIBRARY'].split(SEP)] |
| 77 |
if not INSTALL_MODELS in envmodels: |
| 78 |
envmodels.append(INSTALL_MODELS) |
| 79 |
os.environ['ASCENDLIBRARY'] = SEP.join(envmodels) |
| 80 |
restart = 1 |
| 81 |
|
| 82 |
# if ASCENDSOLVERS has been specified, make sure it includes the standard solvers |
| 83 |
if os.environ.get('ASCENDSOLVERS'): |
| 84 |
envsolvers = [os.path.abspath(i) for i in os.environ['ASCENDSOLVERS'].split(SEP)] |
| 85 |
if not INSTALL_SOLVERS in envsolvers: |
| 86 |
envsolvers.append(INSTALL_SOLVERS) |
| 87 |
os.environ['ASCENDSOLVERS'] = SEP.join(envsolvers) |
| 88 |
restart = 1 |
| 89 |
|
| 90 |
# don't need to restart process on Windows as env vars update immediately |
| 91 |
if restart and platform.system()!="Windows": |
| 92 |
print "Restarting with corrected environment..." |
| 93 |
if os.environ.get(LDPATHVAR): |
| 94 |
print " %s = %s" % (LDPATHVAR,os.environ.get(LDPATHVAR)) |
| 95 |
if os.environ.get('ASCENDLIBRARY'): |
| 96 |
print " ASCENDLIBRARY = %s" % os.environ.get('ASCENDLIBRARY') |
| 97 |
if os.environ.get('ASCENDSOLVERS'): |
| 98 |
print " ASCENDSOLVERS = %s" % os.environ.get('ASCENDSOLVERS') |
| 99 |
script = os.path.join(sys.path[0],"ascend") |
| 100 |
print "PYTHON =",PYTHON |
| 101 |
print "script =",script |
| 102 |
os.execve(PYTHON,[script] + sys.argv, os.environ) |
| 103 |
|
| 104 |
print "Running with..." |
| 105 |
print " %s = %s" % (LDPATHVAR, os.environ.get(LDPATHVAR)) |
| 106 |
print " sys.path = %s" % sys.path |
| 107 |
print " argv = %s" % sys.argv |
| 108 |
|
| 109 |
if os.environ.get('ASCENDLIBRARY'): |
| 110 |
ASCENDLIBRARY = os.environ.get('ASCENDLIBRARY') |
| 111 |
print " ASCENDLIBRARY = %s" % ASCENDLIBRARY |
| 112 |
|
| 113 |
if os.environ.get('ASCENDSOLVERS'): |
| 114 |
ASCENDSOLVERS = os.environ.get('ASCENDSOLVERS') |
| 115 |
print " ASCENDSOLVERS = %s" % ASCENDLIBRARY |
| 116 |
|
| 117 |
print "sys.path[0] = %s" % sys.path[0] |
| 118 |
|
| 119 |
if not INSTALL_ASCDATA in sys.path: |
| 120 |
print "Adding INSTALL_ASCDATA to python path?" |
| 121 |
sys.path.append(INSTALL_ASCDATA) |
| 122 |
|
| 123 |
if os.environ.get('OSTYPE')=='cygwin': |
| 124 |
print "CYGWIN..." |
| 125 |
elif os.environ.get('OSTYPE')=='msys': |
| 126 |
print "MSYS..." |
| 127 |
|
| 128 |
if os.environ.get('ASC_GDB'): |
| 129 |
args = sys.argv |
| 130 |
args.pop(0) |
| 131 |
cmd = ["gdb","--args","python",os.path.join(INSTALL_ASCDATA,"gtkbrowser.py")]+args |
| 132 |
print cmd |
| 133 |
os.execv("/usr/bin/gdb",cmd) |
| 134 |
else: |
| 135 |
import ascpy |
| 136 |
olddir = os.getcwd() |
| 137 |
os.chdir(INSTALL_ASCDATA) |
| 138 |
from gtkbrowser import * |
| 139 |
os.chdir(olddir) |
| 140 |
B = Browser( |
| 141 |
librarypath=os.environ.get('ASCENDLIBRARY') |
| 142 |
,assetspath=os.path.join(INSTALL_ASCDATA,"glade") |
| 143 |
) |
| 144 |
B.run() |