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

Contents of /trunk/pygtk/ascend.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2073 - (show annotations) (download)
Thu Sep 3 13:23:46 2009 UTC (12 years, 11 months ago) by jpye
File size: 5113 byte(s)
Some efforts towards a Bundle for an installer for ASCEND on OS X.
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 # on Windows, we should be able to *assume* relative paths...
26
27 # for some reason, QueryValue doesn't work on Py 2.4, need to use QueryValueEx.
28 INSTALL_SOLVERS,t = wreg.QueryValueEx(k,"INSTALL_SOLVERS")
29 INSTALL_MODELS,t = wreg.QueryValueEx(k,"INSTALL_MODELS")
30 INSTALL_LIB,t = wreg.QueryValueEx(k,"INSTALL_LIB")
31 INSTALL_ASCDATA,t = wreg.QueryValueEx(k,"INSTALL_ASCDATA")
32 GTKLIBS,t = wreg.QueryValueEx(k,"GTKLIBS");
33 DEFAULT_ASCENDLIBRARY="%s;%s" % (INSTALL_SOLVERS,INSTALL_MODELS)
34
35 INSTALL_PYTHON = os.path.join(INSTALL_ASCDATA,"python")
36 PYVERSION = "@PYVERSION@"
37 PYTHON=os.path.join(sys.prefix,"pythonw.exe")
38
39 print "PYTHON =",PYTHON
40 SEP=";"
41 LDPATHVAR = 'PATH'
42 else:
43
44 # FIXME for possible case of relative paths...
45
46 INSTALL_LIB="@INSTALL_LIB@"
47 INSTALL_ASCDATA="@INSTALL_ASCDATA@"
48 INSTALL_MODELS = "@INSTALL_MODELS@"
49 INSTALL_SOLVERS = "@INSTALL_SOLVERS@"
50 INSTALL_PYTHON = "@INSTALL_PYTHON@"
51 PYTHON="@PYTHON@"
52 DEFAULT_ASCENDLIBRARY="""@DEFAULT_ASCENDLIBRARY@"""
53 SEP=":"
54 LDPATHVAR = 'LD_LIBRARY_PATH'
55 GTKLIBS = None # assume the GTK will be in the standard library path
56
57 #-----------------------------------------------------------------------
58
59 if os.environ.get(LDPATHVAR):
60 LDPATH = os.environ.get(LDPATHVAR).split(SEP)
61 else:
62 LDPATH = []
63
64 if not os.environ.get('ASC_GDB'):
65 # restarting messes up GDB so don't allow it
66
67 if platform.system()=="Windows":
68 # Put INSTALL_LIB then GTK at start of path
69 if GTKLIBS in LDPATH:
70 LDPATH.remove(GTKLIBS)
71 LDPATH=[INSTALL_LIB,GTKLIBS]+LDPATH
72 os.environ[LDPATHVAR] = SEP.join(LDPATH)
73 restart = 1
74 elif INSTALL_LIB != "/usr/lib" and not INSTALL_LIB in LDPATH:
75 # don't worry about GTK location; just ensure that LDPATH includes INSTALL_LIB
76 LDPATH = [INSTALL_LIB] + LDPATH
77 os.environ[LDPATHVAR] = SEP.join(LDPATH)
78 restart = 1
79
80 # if ASCENDLIBRARY has been specified, make sure it's including the Model Library
81 if os.environ.get('ASCENDLIBRARY'):
82 envmodels = [os.path.abspath(i) for i in os.environ['ASCENDLIBRARY'].split(SEP)]
83 if not INSTALL_MODELS in envmodels:
84 envmodels.append(INSTALL_MODELS)
85 os.environ['ASCENDLIBRARY'] = SEP.join(envmodels)
86 restart = 1
87
88 # if ASCENDSOLVERS has been specified, make sure it includes the standard solvers
89 if os.environ.get('ASCENDSOLVERS'):
90 envsolvers = [os.path.abspath(i) for i in os.environ['ASCENDSOLVERS'].split(SEP)]
91 if not INSTALL_SOLVERS in envsolvers:
92 envsolvers.append(INSTALL_SOLVERS)
93 os.environ['ASCENDSOLVERS'] = SEP.join(envsolvers)
94 restart = 1
95
96 # don't need to restart process on Windows as env vars update immediately
97 if restart and platform.system()!="Windows":
98 print "Restarting with corrected environment..."
99 if os.environ.get(LDPATHVAR):
100 print " %s = %s" % (LDPATHVAR,os.environ.get(LDPATHVAR))
101 if os.environ.get('ASCENDLIBRARY'):
102 print " ASCENDLIBRARY = %s" % os.environ.get('ASCENDLIBRARY')
103 if os.environ.get('ASCENDSOLVERS'):
104 print " ASCENDSOLVERS = %s" % os.environ.get('ASCENDSOLVERS')
105 script = os.path.join(sys.path[0],"ascend")
106 print "PYTHON =",PYTHON
107 print "script =",script
108 os.execve(PYTHON,[script] + sys.argv, os.environ)
109
110 print "Running with..."
111 print " %s = %s" % (LDPATHVAR, os.environ.get(LDPATHVAR))
112 print " sys.path = %s" % sys.path
113 print " argv = %s" % sys.argv
114
115 if os.environ.get('ASCENDLIBRARY'):
116 ASCENDLIBRARY = os.environ.get('ASCENDLIBRARY')
117 print " ASCENDLIBRARY = %s" % ASCENDLIBRARY
118
119 if os.environ.get('ASCENDSOLVERS'):
120 ASCENDSOLVERS = os.environ.get('ASCENDSOLVERS')
121 print " ASCENDSOLVERS = %s" % ASCENDLIBRARY
122
123 print "sys.path[0] = %s" % sys.path[0]
124
125 if not INSTALL_PYTHON in sys.path:
126 print "Adding INSTALL_PYTHON=%s to python path" % INSTALL_PYTHON
127 sys.path.append(INSTALL_PYTHON)
128
129 if os.environ.get('OSTYPE')=='cygwin':
130 print "CYGWIN..."
131 elif os.environ.get('OSTYPE')=='msys':
132 print "MSYS..."
133
134 if os.environ.get('ASC_GDB'):
135 args = sys.argv
136 args.pop(0)
137 cmd = ["gdb","--args","python",os.path.join(INSTALL_PYTHON,"gtkbrowser.py")]+args
138 print cmd
139 os.execv("/usr/bin/gdb",cmd)
140 else:
141 import ascpy
142 olddir = os.getcwd()
143 print "CWD =",olddir
144 os.chdir(INSTALL_ASCDATA)
145 from gtkbrowser import *
146 os.chdir(olddir)
147 B = Browser(
148 librarypath=os.environ.get('ASCENDLIBRARY')
149 ,assetspath=os.path.join(INSTALL_ASCDATA,"glade")
150 )
151 B.run()

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