/[ascend]/trunk/pygtk/ascend.in
ViewVC logotype

Contents of /trunk/pygtk/ascend.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1615 - (show annotations) (download)
Mon Sep 3 12:40:36 2007 UTC (12 years, 10 months ago) by jpye
File size: 4754 byte(s)
Support for ASCENDLIBRARY in Windows registry.
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 print " %s = %s" % (LDPATHVAR,os.environ.get(LDPATHVAR))
94 print " ASCENDLIBRARY = %s" % os.environ.get('ASCENDLIBRARY')
95 print " ASCENDSOLVERS = %s" % os.environ.get('ASCENDSOLVERS')
96 script = os.path.join(sys.path[0],"ascend")
97 print "PYTHON =",PYTHON
98 print "script =",script
99 os.execve(PYTHON,[script] + sys.argv, os.environ)
100
101 print "Running with..."
102 print " %s = %s" % (LDPATHVAR, os.environ.get(LDPATHVAR))
103 print " sys.path = %s" % sys.path
104 print " argv = %s" % sys.argv
105
106 if os.environ.get('ASCENDLIBRARY'):
107 ASCENDLIBRARY = os.environ.get('ASCENDLIBRARY')
108 print " ASCENDLIBRARY = %s" % ASCENDLIBRARY
109
110 if os.environ.get('ASCENDSOLVERS'):
111 ASCENDSOLVERS = os.environ.get('ASCENDSOLVERS')
112 print " ASCENDSOLVERS = %s" % ASCENDLIBRARY
113
114 print "sys.path[0] = %s" % sys.path[0]
115
116 if not INSTALL_ASCDATA in sys.path:
117 print "Adding INSTALL_ASCDATA to python path?"
118 sys.path.append(INSTALL_ASCDATA)
119
120 if os.environ.get('OSTYPE')=='cygwin':
121 print "CYGWIN..."
122 elif os.environ.get('OSTYPE')=='msys':
123 print "MSYS..."
124
125 if os.environ.get('ASC_GDB'):
126 args = sys.argv
127 args.pop(0)
128 cmd = ["gdb","--args","python",os.path.join(INSTALL_ASCDATA,"gtkbrowser.py")]+args
129 print cmd
130 os.execv("/usr/bin/gdb",cmd)
131 else:
132 import ascpy
133 olddir = os.getcwd()
134 os.chdir(INSTALL_ASCDATA)
135 from gtkbrowser import *
136 os.chdir(olddir)
137 B = Browser(assetspath=os.path.join(INSTALL_ASCDATA,"glade"))
138 B.run()

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22