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

Contents of /trunk/pygtk/ascend.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2083 - (show annotations) (download)
Thu Sep 24 06:37:53 2009 UTC (11 years ago) by jpye
File size: 5682 byte(s)
Almost there... ASCEND.app runs OK from command line now, but errors from Finder.
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 launched 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 if os.path.isabs(p):
18 return p
19 else:
20 return os.path.join(sys.path[0],p)
21
22 #-----------------------------------------------------------------------
23 # Get locations of the installed files. On windows, these are defined in
24 # in the registry. On other systems, these are defined at compile time
25 # by @VARNAME@ substitution.
26
27 SEP = ":"
28 PYTHON="@PYTHON@"
29 GTKLIBS = "" # assume the GTK will be in the standard library path
30
31 if platform.system()=="Windows":
32 SEP=";"
33 LDPATHVAR = 'PATH'
34 PYTHON=os.path.join(sys.prefix,"pythonw.exe")
35
36 import _winreg as wreg
37 k = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, "SOFTWARE\ASCEND")
38
39 # on Windows, we should be able to *assume* relative paths...
40
41 # for some reason, QueryValue doesn't work on Py 2.4, need to use QueryValueEx.
42 INSTALL_SOLVERS,t = wreg.QueryValueEx(k,"INSTALL_SOLVERS")
43 INSTALL_MODELS,t = wreg.QueryValueEx(k,"INSTALL_MODELS")
44 INSTALL_LIB,t = wreg.QueryValueEx(k,"INSTALL_LIB")
45 INSTALL_ASCDATA,t = wreg.QueryValueEx(k,"INSTALL_ASCDATA")
46 GTKLIBS,t = wreg.QueryValueEx(k,"GTKLIBS");
47 DEFAULT_ASCENDLIBRARY="%s;%s" % (INSTALL_SOLVERS,INSTALL_MODELS)
48
49 INSTALL_PYTHON = os.path.join(INSTALL_ASCDATA,"python")
50 PYVERSION = "@PYVERSION@"
51
52 elif platform.system()=="Darwin":
53
54 LDPATHVAR = 'DYLD_LIBRARY_PATH'
55
56 # FIXME
57 #GTKLIBS="/Users/john/gtk/inst/lib"
58
59 INSTALL_LIB = path_absolute(".")
60 INSTALL_ASCDATA = path_absolute("Resources")
61 INSATLL_MODELS = path_absolute("""@ASC_LIBRARY_REL_DIST@""")
62 INSTALL_SOLVERS = path_absolute("""@ASC_SOLVERS_REL_DIST@""")
63 INSTALL_PYTHON = path_absolute("Python")
64
65 else:
66 LDPATHVAR = 'LD_LIBRARY_PATH'
67
68 # FIXME for possible case of relative paths...
69
70 INSTALL_LIB="@INSTALL_LIB@"
71 INSTALL_ASCDATA="@INSTALL_ASCDATA@"
72 INSTALL_MODELS = "@INSTALL_MODELS@"
73 INSTALL_SOLVERS = "@INSTALL_SOLVERS@"
74 INSTALL_PYTHON = "@INSTALL_PYTHON@"
75 DEFAULT_ASCENDLIBRARY="""@DEFAULT_ASCENDLIBRARY@"""
76
77 #-----------------------------------------------------------------------
78
79 if os.environ.get(LDPATHVAR):
80 LDPATH = os.environ.get(LDPATHVAR).split(SEP)
81 else:
82 LDPATH = []
83
84 if not os.environ.get('ASC_GDB'):
85 # restarting messes up GDB so don't allow it
86
87 if platform.system()=="Windows" :
88 # Put INSTALL_LIB then GTK at start of path
89 if GTKLIBS not in LDPATH:
90 restart = 1
91 if INSTALL_LIB not in LDPATH:
92 restart = 1
93 if GTKLIBS in LDPATH:
94 LDPATH.remove(GTKLIBS)
95 LDPATH=[INSTALL_LIB,GTKLIBS]+LDPATH
96 os.environ[LDPATHVAR] = SEP.join(LDPATH)
97 elif INSTALL_LIB != "/usr/lib" and not INSTALL_LIB in LDPATH:
98 # don't worry about GTK location; just ensure that LDPATH includes INSTALL_LIB
99 LDPATH = [INSTALL_LIB] + LDPATH
100 os.environ[LDPATHVAR] = SEP.join(LDPATH)
101 restart = 1
102
103 # if ASCENDLIBRARY has been specified, make sure it's including the Model Library
104 if os.environ.get('ASCENDLIBRARY'):
105 envmodels = [os.path.abspath(i) for i in os.environ['ASCENDLIBRARY'].split(SEP)]
106 if not INSTALL_MODELS in envmodels:
107 envmodels.append(INSTALL_MODELS)
108 os.environ['ASCENDLIBRARY'] = SEP.join(envmodels)
109 restart = 1
110
111 # if ASCENDSOLVERS has been specified, make sure it includes the standard solvers
112 if os.environ.get('ASCENDSOLVERS'):
113 envsolvers = [os.path.abspath(i) for i in os.environ['ASCENDSOLVERS'].split(SEP)]
114 if not INSTALL_SOLVERS in envsolvers:
115 envsolvers.append(INSTALL_SOLVERS)
116 os.environ['ASCENDSOLVERS'] = SEP.join(envsolvers)
117 restart = 1
118
119 # don't need to restart process on Windows as env vars update immediately
120 if restart and platform.system()!="Windows":
121 print "Restarting with corrected environment..."
122 if os.environ.get(LDPATHVAR):
123 print " %s = %s" % (LDPATHVAR,os.environ.get(LDPATHVAR))
124 if os.environ.get('ASCENDLIBRARY'):
125 print " ASCENDLIBRARY = %s" % os.environ.get('ASCENDLIBRARY')
126 if os.environ.get('ASCENDSOLVERS'):
127 print " ASCENDSOLVERS = %s" % os.environ.get('ASCENDSOLVERS')
128 script = os.path.join(sys.path[0],"ascend")
129 print "PYTHON =",PYTHON
130 print "script =",script
131 os.execve(PYTHON,[script] + sys.argv, os.environ)
132
133 print "Running with..."
134 print " %s = %s" % (LDPATHVAR, os.environ.get(LDPATHVAR))
135 print " sys.path = %s" % sys.path
136 print " argv = %s" % sys.argv
137
138 if os.environ.get('ASCENDLIBRARY'):
139 ASCENDLIBRARY = os.environ.get('ASCENDLIBRARY')
140 print " ASCENDLIBRARY = %s" % ASCENDLIBRARY
141
142 if os.environ.get('ASCENDSOLVERS'):
143 ASCENDSOLVERS = os.environ.get('ASCENDSOLVERS')
144 print " ASCENDSOLVERS = %s" % ASCENDLIBRARY
145
146 print "sys.path[0] = %s" % sys.path[0]
147
148 if not INSTALL_PYTHON in sys.path:
149 print "Adding INSTALL_PYTHON=%s to python path" % INSTALL_PYTHON
150 sys.path.append(INSTALL_PYTHON)
151
152 if os.environ.get('OSTYPE')=='cygwin':
153 print "CYGWIN..."
154 elif os.environ.get('OSTYPE')=='msys':
155 print "MSYS..."
156
157 if os.environ.get('ASC_GDB'):
158 args = sys.argv
159 args.pop(0)
160 cmd = ["gdb","--args","python",os.path.join(INSTALL_PYTHON,"gtkbrowser.py")]+args
161 print cmd
162 os.execv("/usr/bin/gdb",cmd)
163 else:
164 import ascpy
165 olddir = os.getcwd()
166 print "CWD =",olddir
167 os.chdir(INSTALL_ASCDATA)
168 from gtkbrowser import *
169 os.chdir(olddir)
170 B = Browser(
171 librarypath=os.environ.get('ASCENDLIBRARY')
172 ,assetspath=os.path.join(INSTALL_ASCDATA,"glade")
173 )
174 B.run()

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