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

Contents of /trunk/pygtk/ascend.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2016 - (show annotations) (download)
Tue Apr 28 09:30:57 2009 UTC (10 years, 11 months ago) by jpye
File size: 5089 byte(s)
Trying to fix up ASCEND for change of model library location to /usr/lib/ascend/models.
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 INSTALL_PYTHON = "@INSTALL_PYTHON@"
46 PYTHON="@PYTHON@"
47 DEFAULT_ASCENDLIBRARY="""@DEFAULT_ASCENDLIBRARY@"""
48 SEP=":"
49 LDPATHVAR = 'LD_LIBRARY_PATH'
50 GTKLIBS = None # assume the GTK will be in the standard library path
51
52 #-----------------------------------------------------------------------
53
54 if os.environ.get(LDPATHVAR):
55 LDPATH = os.environ.get(LDPATHVAR).split(SEP)
56 else:
57 LDPATH = []
58
59 if not os.environ.get('ASC_GDB'):
60 # restarting messes up GDB so don't allow it
61
62 if platform.system()=="Windows":
63 # Put INSTALL_LIB then GTK at start of path
64 if GTKLIBS in LDPATH:
65 LDPATH.remove(GTKLIBS)
66 LDPATH=[INSTALL_LIB,GTKLIBS]+LDPATH
67 os.environ[LDPATHVAR] = SEP.join(LDPATH)
68 restart = 1
69 elif INSTALL_LIB != "/usr/lib" and not INSTALL_LIB in LDPATH:
70 # don't worry about GTK location; just ensure that LDPATH includes INSTALL_LIB
71 LDPATH = [INSTALL_LIB] + LDPATH
72 os.environ[LDPATHVAR] = SEP.join(LDPATH)
73 restart = 1
74
75 # if ASCENDLIBRARY has been specified, make sure it's including the Model Library
76 if os.environ.get('ASCENDLIBRARY'):
77 envmodels = [os.path.abspath(i) for i in os.environ['ASCENDLIBRARY'].split(SEP)]
78 if not INSTALL_MODELS in envmodels:
79 envmodels.append(INSTALL_MODELS)
80 os.environ['ASCENDLIBRARY'] = SEP.join(envmodels)
81 restart = 1
82
83 # if ASCENDSOLVERS has been specified, make sure it includes the standard solvers
84 if os.environ.get('ASCENDSOLVERS'):
85 envsolvers = [os.path.abspath(i) for i in os.environ['ASCENDSOLVERS'].split(SEP)]
86 if not INSTALL_SOLVERS in envsolvers:
87 envsolvers.append(INSTALL_SOLVERS)
88 os.environ['ASCENDSOLVERS'] = SEP.join(envsolvers)
89 restart = 1
90
91 # don't need to restart process on Windows as env vars update immediately
92 if restart and platform.system()!="Windows":
93 print "Restarting with corrected environment..."
94 if os.environ.get(LDPATHVAR):
95 print " %s = %s" % (LDPATHVAR,os.environ.get(LDPATHVAR))
96 if os.environ.get('ASCENDLIBRARY'):
97 print " ASCENDLIBRARY = %s" % os.environ.get('ASCENDLIBRARY')
98 if os.environ.get('ASCENDSOLVERS'):
99 print " ASCENDSOLVERS = %s" % os.environ.get('ASCENDSOLVERS')
100 script = os.path.join(sys.path[0],"ascend")
101 print "PYTHON =",PYTHON
102 print "script =",script
103 os.execve(PYTHON,[script] + sys.argv, os.environ)
104
105 print "Running with..."
106 print " %s = %s" % (LDPATHVAR, os.environ.get(LDPATHVAR))
107 print " sys.path = %s" % sys.path
108 print " argv = %s" % sys.argv
109
110 if os.environ.get('ASCENDLIBRARY'):
111 ASCENDLIBRARY = os.environ.get('ASCENDLIBRARY')
112 print " ASCENDLIBRARY = %s" % ASCENDLIBRARY
113
114 if os.environ.get('ASCENDSOLVERS'):
115 ASCENDSOLVERS = os.environ.get('ASCENDSOLVERS')
116 print " ASCENDSOLVERS = %s" % ASCENDLIBRARY
117
118 print "sys.path[0] = %s" % sys.path[0]
119
120 if not INSTALL_ASCDATA in sys.path:
121 print "Adding INSTALL_ASCDATA to python pathh"
122 sys.path.append(INSTALL_ASCDATA)
123
124 if not INSTALL_PYTHON in sys.path:
125 print "Adding INSTALL_PYTHON=%s to python path" % INSTALL_PYTHON
126 sys.path.append(INSTALL_PYTHON)
127
128 if os.environ.get('OSTYPE')=='cygwin':
129 print "CYGWIN..."
130 elif os.environ.get('OSTYPE')=='msys':
131 print "MSYS..."
132
133 if os.environ.get('ASC_GDB'):
134 args = sys.argv
135 args.pop(0)
136 cmd = ["gdb","--args","python",os.path.join(INSTALL_ASCDATA,"gtkbrowser.py")]+args
137 print cmd
138 os.execv("/usr/bin/gdb",cmd)
139 else:
140 import ascpy
141 olddir = os.getcwd()
142 os.chdir(INSTALL_ASCDATA)
143 from gtkbrowser import *
144 os.chdir(olddir)
145 B = Browser(
146 librarypath=os.environ.get('ASCENDLIBRARY')
147 ,assetspath=os.path.join(INSTALL_ASCDATA,"glade")
148 )
149 B.run()

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