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

Contents of /trunk/pygtk/ascend.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2144 - (show annotations) (download)
Wed Dec 23 13:04:19 2009 UTC (14 years, 6 months ago) by jpye
File size: 7485 byte(s)
More on mac issues.
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 launches ASCEND, after first ensuring that all necessary
9 # variables are present in the 'environment', and adding them and
10 # restarting the process if necessary. You can override values for these
11 # env vars by setting them before this script is run.
12
13 # Note that as well as env vars, ASCEND PyGTK is also controllable using the
14 # .ascend.ini file in the user's home directory.
15
16 def path_absolute(p):
17 """utility function for dealing with paths on Mac platform."""
18 if os.path.isabs(p):
19 return p
20 else:
21 return os.path.join(sys.path[0],p)
22
23 #-----------------------------------------------------------------------
24 # Get locations of the installed files. On windows, these are defined in
25 # in the registry. On other systems, these are defined at compile time
26 # by @VARNAME@ substitution.
27
28 SEP = ":"
29 PYTHON="@PYTHON@"
30 GTKLIBPATH = None # assume that GTK will be in the standard library path
31
32 if platform.system()=="Windows":
33 SEP=";"
34 LDPATHVAR = 'PATH'
35 PYTHON=os.path.join(sys.prefix,"pythonw.exe")
36
37 import _winreg as wreg
38 k = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, "SOFTWARE\ASCEND")
39
40 # on Windows, we should be able to *assume* relative paths...
41
42 # for some reason, QueryValue doesn't work on Py 2.4, need to use QueryValueEx.
43 INSTALL_SOLVERS,t = wreg.QueryValueEx(k,"INSTALL_SOLVERS")
44 INSTALL_MODELS,t = wreg.QueryValueEx(k,"INSTALL_MODELS")
45 INSTALL_LIB,t = wreg.QueryValueEx(k,"INSTALL_LIB")
46 INSTALL_ASCDATA,t = wreg.QueryValueEx(k,"INSTALL_ASCDATA")
47 GTKLIBPATH,t = wreg.QueryValueEx(k,"GTKLIBS");
48 DEFAULT_ASCENDLIBRARY="%s;%s" % (INSTALL_SOLVERS,INSTALL_MODELS)
49
50 INSTALL_PYTHON = os.path.join(INSTALL_ASCDATA,"python")
51 PYVERSION = "@PYVERSION@"
52
53 elif platform.system()=="Darwin":
54
55 LDPATHVAR = 'DYLD_LIBRARY_PATH'
56
57 GTKLIBPATH=[path_absolute("PyGTK.bundle/lib")]
58
59 INSTALL_LIB = path_absolute(".")
60 INSTALL_ASCDATA = path_absolute("Resources")
61 INSTALL_MODELS = path_absolute("""@ASC_LIBRARY_REL_DIST@""")
62 INSTALL_SOLVERS = path_absolute("""@ASC_SOLVERS_REL_DIST@""")
63 INSTALL_PYTHON = path_absolute("Python")
64 DEFAULT_ASCENDLIBRARY="%s;%s" % (INSTALL_SOLVERS,INSTALL_MODELS)
65
66 INSTALL_PYGTK = path_absolute("PyGTK.bundle/python")
67 print "Adding %s to python path" % INSTALL_PYGTK
68 sys.path.insert(0,INSTALL_PYGTK)
69
70 else:
71 LDPATHVAR = 'LD_LIBRARY_PATH'
72
73 # FIXME for possible case of relative paths...
74
75 INSTALL_LIB="@INSTALL_LIB@"
76 INSTALL_ASCDATA="@INSTALL_ASCDATA@"
77 INSTALL_MODELS = "@INSTALL_MODELS@"
78 INSTALL_SOLVERS = "@INSTALL_SOLVERS@"
79 INSTALL_PYTHON = "@INSTALL_PYTHON@"
80 DEFAULT_ASCENDLIBRARY="""@DEFAULT_ASCENDLIBRARY@"""
81
82 #-----------------------------------------------------------------------
83
84 if os.environ.get(LDPATHVAR):
85 LDPATH = os.environ.get(LDPATHVAR).split(SEP)
86 else:
87 LDPATH = []
88
89 if not os.environ.get('ASC_GDB'):
90 # restarting messes up GDB so don't allow it
91
92 if platform.system()=="Windows":
93 # Put INSTALL_LIB then GTK at start of path
94 if GTKLIBPATH not in LDPATH:
95 restart = 1
96 if INSTALL_LIB not in LDPATH:
97 restart = 1
98 if GTKLIBPATH in LDPATH:
99 LDPATH.remove(GTKLIBPATH)
100 LDPATH=[INSTALL_LIB,GTKLIBPATH]+LDPATH
101 os.environ[LDPATHVAR] = SEP.join(LDPATH)
102 elif INSTALL_LIB != "/usr/lib" and not INSTALL_LIB in LDPATH:
103 # don't worry about GTK location; just ensure that LDPATH includes INSTALL_LIB
104 LDPATH = [INSTALL_LIB] + GTKLIBPATH + LDPATH
105 os.environ[LDPATHVAR] = SEP.join(LDPATH)
106 restart = 1
107
108 if platform.system()=="Darwin":
109 if not 'GTK_PATH' in os.environ:
110 os.environ['XDG_DATA_HOME']=os.path.expanduser('~/.local/share')
111 # os.environ['XDG_CONFIG_HOME']=os.path.expanduser('~/.config')
112 # os.environ['XDG_CACHE_HOME']=os.path.expanduser('~/.cache')
113 # os.environ['XDG_CONFIG_DIRS']='/sw/etc/xdg'
114 # os.environ['XML_CATALOG_FILES']='/sw/etc/xml/catalog'
115 os.environ['XDG_DATA_DIRS']="../PyGTK.bundle/share"
116
117 bundle_res = os.path.normpath(path_absolute("../"))
118 print "BUNDLE_RES =", bundle_res
119 bundle_etc = os.path.join(bundle_res,"etc")
120 os.environ['GTK_DATA_PREFIX'] = bundle_res
121 os.environ['GTK_EXE_PREFIX'] = bundle_res
122 os.environ['GTK_PATH'] = bundle_res
123 os.environ['GTK2_RC_FILES'] = os.path.join(bundle_etc,"gtk-2.0/gtkrc")
124 os.environ['GTK_IM_MODULE_FILE']=os.path.join(bundle_etc,"gtk-2.0/gtk.immodules")
125 os.environ['GTK_PIXBUF_MODULE_FILE']=os.path.join(bundle_etc,"gtk-2.0/gdk-pixbuf.loaders")
126 #os.environ['PANGO_RC_FILE']=os.path.join(bundle_etc,"pango/pangorc")
127
128 restart = 1
129
130 # if not 'PWD' in os.environ:
131 # os.environ['PWD']=os.path.dirname(sys.executable)
132 # restart = 1
133 #
134 # if not '_' in os.environ:
135 # os.environ['_']=sys.executable
136 # restart = 1
137
138 # if ASCENDLIBRARY has been specified, make sure it's including the Model Library
139 if os.environ.get('ASCENDLIBRARY') or platform.system()=="Darwin":
140 if not 'ASCENDLIBRARY' in os.environ:
141 os.environ['ASCENDLIBRARY'] = ""
142 envmodels = [os.path.abspath(i) for i in os.environ['ASCENDLIBRARY'].split(SEP)]
143 if not INSTALL_MODELS in envmodels:
144 envmodels.append(INSTALL_MODELS)
145 os.environ['ASCENDLIBRARY'] = SEP.join(envmodels)
146 restart = 1
147
148 # if ASCENDSOLVERS has been specified, make sure it includes the standard solvers
149 if os.environ.get('ASCENDSOLVERS') or platform.system()=="Darwin":
150 if not 'ASCENDSOLVERS' in os.environ:
151 os.environ['ASCENDSOLVERS'] = ""
152 envsolvers = [os.path.abspath(i) for i in os.environ['ASCENDSOLVERS'].split(SEP)]
153 if not INSTALL_SOLVERS in envsolvers:
154 envsolvers.append(INSTALL_SOLVERS)
155 os.environ['ASCENDSOLVERS'] = SEP.join(envsolvers)
156 restart = 1
157
158 # don't need to restart process on Windows as env vars update immediately
159 if restart and platform.system()!="Windows":
160 print "Restarting with corrected environment..."
161 if os.environ.get(LDPATHVAR):
162 print " %s = %s" % (LDPATHVAR,os.environ.get(LDPATHVAR))
163 if os.environ.get('ASCENDLIBRARY'):
164 print " ASCENDLIBRARY = %s" % os.environ.get('ASCENDLIBRARY')
165 if os.environ.get('ASCENDSOLVERS'):
166 print " ASCENDSOLVERS = %s" % os.environ.get('ASCENDSOLVERS')
167 script = os.path.join(sys.path[0],"ascend")
168 print "PYTHON =",PYTHON
169 print "script =",script
170 os.execve(PYTHON,[script] + sys.argv, os.environ)
171
172 print "Running with..."
173 print " %s = %s" % (LDPATHVAR, os.environ.get(LDPATHVAR))
174 print " sys.path = %s" % sys.path
175 print " argv = %s" % sys.argv
176 for e in os.environ:
177 print " %s = %s" % (e, os.environ[e])
178
179 if os.environ.get('ASCENDLIBRARY'):
180 ASCENDLIBRARY = os.environ.get('ASCENDLIBRARY')
181 print " ASCENDLIBRARY = %s" % ASCENDLIBRARY
182
183 if os.environ.get('ASCENDSOLVERS'):
184 ASCENDSOLVERS = os.environ.get('ASCENDSOLVERS')
185 print " ASCENDSOLVERS = %s" % ASCENDLIBRARY
186
187 print "sys.path[0] = %s" % sys.path[0]
188
189 if not INSTALL_PYTHON in sys.path:
190 print "Adding INSTALL_PYTHON=%s to python path" % INSTALL_PYTHON
191 sys.path.append(INSTALL_PYTHON)
192
193 if os.environ.get('OSTYPE')=='cygwin':
194 print "CYGWIN..."
195 elif os.environ.get('OSTYPE')=='msys':
196 print "MSYS..."
197
198 if os.environ.get('ASC_GDB'):
199 args = sys.argv
200 args.pop(0)
201 cmd = ["gdb","--args","python",os.path.join(INSTALL_PYTHON,"gtkbrowser.py")]+args
202 print cmd
203 os.execv("/usr/bin/gdb",cmd)
204 else:
205 import ascpy
206 olddir = os.getcwd()
207 print "CWD =",olddir
208 os.chdir(INSTALL_ASCDATA)
209 from gtkbrowser import *
210 os.chdir(olddir)
211 B = Browser(
212 librarypath=os.environ.get('ASCENDLIBRARY')
213 ,assetspath=os.path.join(INSTALL_ASCDATA,"glade")
214 )
215 B.run()

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