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

Annotation of /trunk/pygtk/ascend.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2084 - (hide annotations) (download)
Thu Sep 24 07:39:14 2009 UTC (14 years, 6 months ago) by jpye
File size: 5961 byte(s)
Adding OSX readme file.
Folder background for use during dmg creation.
ASCENDLIBRARY and ASCENDSOLVERS always needed in Mac, because location of Application can vary.
1 johnpye 858 #!@PYTHON@
2 jpye 1615 # ^ python path substituted here is not depended-upon in Windows
3 johnpye 440
4 johnpye 1172 import os.path, sys, platform
5 johnpye 440
6 johnpye 1096 restart = 0
7    
8 jpye 2083 # 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 johnpye 1096
13 jpye 2083 # Note that as well as env vars, ASCEND PyGTK is also controllable using the
14 jpye 1463 # .ascend.ini file in the user's home directory.
15    
16 jpye 2083 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 jpye 1463 #-----------------------------------------------------------------------
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 jpye 2083 SEP = ":"
28     PYTHON="@PYTHON@"
29     GTKLIBS = "" # assume the GTK will be in the standard library path
30    
31 johnpye 1172 if platform.system()=="Windows":
32 jpye 2083 SEP=";"
33     LDPATHVAR = 'PATH'
34     PYTHON=os.path.join(sys.prefix,"pythonw.exe")
35    
36 jpye 1463 import _winreg as wreg
37     k = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, "SOFTWARE\ASCEND")
38    
39 jpye 2025 # on Windows, we should be able to *assume* relative paths...
40    
41 jpye 1463 # for some reason, QueryValue doesn't work on Py 2.4, need to use QueryValueEx.
42 jpye 1518 INSTALL_SOLVERS,t = wreg.QueryValueEx(k,"INSTALL_SOLVERS")
43     INSTALL_MODELS,t = wreg.QueryValueEx(k,"INSTALL_MODELS")
44 jpye 1463 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 jpye 1518 DEFAULT_ASCENDLIBRARY="%s;%s" % (INSTALL_SOLVERS,INSTALL_MODELS)
48 jpye 1463
49 jpye 2027 INSTALL_PYTHON = os.path.join(INSTALL_ASCDATA,"python")
50 jpye 1463 PYVERSION = "@PYVERSION@"
51 jpye 2083
52 jpye 2080 elif platform.system()=="Darwin":
53    
54 jpye 2083 LDPATHVAR = 'DYLD_LIBRARY_PATH'
55 jpye 2080
56 jpye 2083 # FIXME
57     #GTKLIBS="/Users/john/gtk/inst/lib"
58 jpye 2080
59 jpye 2083 INSTALL_LIB = path_absolute(".")
60     INSTALL_ASCDATA = path_absolute("Resources")
61 jpye 2084 INSTALL_MODELS = path_absolute("""@ASC_LIBRARY_REL_DIST@""")
62 jpye 2083 INSTALL_SOLVERS = path_absolute("""@ASC_SOLVERS_REL_DIST@""")
63     INSTALL_PYTHON = path_absolute("Python")
64 jpye 2084 DEFAULT_ASCENDLIBRARY="%s;%s" % (INSTALL_SOLVERS,INSTALL_MODELS)
65 johnpye 1172 else:
66 jpye 2083 LDPATHVAR = 'LD_LIBRARY_PATH'
67 jpye 2025
68     # FIXME for possible case of relative paths...
69    
70 jpye 1463 INSTALL_LIB="@INSTALL_LIB@"
71     INSTALL_ASCDATA="@INSTALL_ASCDATA@"
72 jpye 2034 INSTALL_MODELS = "@INSTALL_MODELS@"
73     INSTALL_SOLVERS = "@INSTALL_SOLVERS@"
74 jpye 2016 INSTALL_PYTHON = "@INSTALL_PYTHON@"
75 jpye 1463 DEFAULT_ASCENDLIBRARY="""@DEFAULT_ASCENDLIBRARY@"""
76 johnpye 1172
77 jpye 1463 #-----------------------------------------------------------------------
78    
79     if os.environ.get(LDPATHVAR):
80     LDPATH = os.environ.get(LDPATHVAR).split(SEP)
81 jpye 1365 else:
82 jpye 1463 LDPATH = []
83 jpye 1365
84 johnpye 1097 if not os.environ.get('ASC_GDB'):
85     # restarting messes up GDB so don't allow it
86 johnpye 1096
87 jpye 2083 if platform.system()=="Windows" :
88 jpye 1463 # Put INSTALL_LIB then GTK at start of path
89 jpye 2080 if GTKLIBS not in LDPATH:
90     restart = 1
91     if INSTALL_LIB not in LDPATH:
92     restart = 1
93 jpye 1463 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 johnpye 1096
103 jpye 1615 # if ASCENDLIBRARY has been specified, make sure it's including the Model Library
104 jpye 2084 if os.environ.get('ASCENDLIBRARY') or platform.system()=="Darwin":
105     if not 'ASCENDLIBRARY' in os.environ:
106     os.environ['ASCENDLIBRARY'] = ""
107 johnpye 1172 envmodels = [os.path.abspath(i) for i in os.environ['ASCENDLIBRARY'].split(SEP)]
108 jpye 1614 if not INSTALL_MODELS in envmodels:
109     envmodels.append(INSTALL_MODELS)
110 johnpye 1172 os.environ['ASCENDLIBRARY'] = SEP.join(envmodels)
111     restart = 1
112 jpye 1615
113     # if ASCENDSOLVERS has been specified, make sure it includes the standard solvers
114 jpye 2084 if os.environ.get('ASCENDSOLVERS') or platform.system()=="Darwin":
115     if not 'ASCENDSOLVERS' in os.environ:
116     os.environ['ASCENDSOLVERS'] = ""
117 jpye 1614 envsolvers = [os.path.abspath(i) for i in os.environ['ASCENDSOLVERS'].split(SEP)]
118     if not INSTALL_SOLVERS in envsolvers:
119     envsolvers.append(INSTALL_SOLVERS)
120     os.environ['ASCENDSOLVERS'] = SEP.join(envsolvers)
121 jpye 1504 restart = 1
122 johnpye 1172
123 jpye 1615 # don't need to restart process on Windows as env vars update immediately
124     if restart and platform.system()!="Windows":
125 johnpye 1097 print "Restarting with corrected environment..."
126 jpye 1616 if os.environ.get(LDPATHVAR):
127     print " %s = %s" % (LDPATHVAR,os.environ.get(LDPATHVAR))
128     if os.environ.get('ASCENDLIBRARY'):
129     print " ASCENDLIBRARY = %s" % os.environ.get('ASCENDLIBRARY')
130     if os.environ.get('ASCENDSOLVERS'):
131     print " ASCENDSOLVERS = %s" % os.environ.get('ASCENDSOLVERS')
132 johnpye 1097 script = os.path.join(sys.path[0],"ascend")
133 jpye 1463 print "PYTHON =",PYTHON
134     print "script =",script
135 jpye 1615 os.execve(PYTHON,[script] + sys.argv, os.environ)
136 johnpye 1096
137     print "Running with..."
138 jpye 1463 print " %s = %s" % (LDPATHVAR, os.environ.get(LDPATHVAR))
139 jpye 1467 print " sys.path = %s" % sys.path
140 johnpye 1097 print " argv = %s" % sys.argv
141 johnpye 1096
142 johnpye 858 if os.environ.get('ASCENDLIBRARY'):
143     ASCENDLIBRARY = os.environ.get('ASCENDLIBRARY')
144 jpye 1615 print " ASCENDLIBRARY = %s" % ASCENDLIBRARY
145 johnpye 440
146 jpye 1615 if os.environ.get('ASCENDSOLVERS'):
147     ASCENDSOLVERS = os.environ.get('ASCENDSOLVERS')
148     print " ASCENDSOLVERS = %s" % ASCENDLIBRARY
149    
150 johnpye 1096 print "sys.path[0] = %s" % sys.path[0]
151 johnpye 440
152 jpye 2016 if not INSTALL_PYTHON in sys.path:
153     print "Adding INSTALL_PYTHON=%s to python path" % INSTALL_PYTHON
154     sys.path.append(INSTALL_PYTHON)
155    
156 johnpye 858 if os.environ.get('OSTYPE')=='cygwin':
157     print "CYGWIN..."
158     elif os.environ.get('OSTYPE')=='msys':
159     print "MSYS..."
160 johnpye 440
161 jpye 1358 if os.environ.get('ASC_GDB'):
162     args = sys.argv
163     args.pop(0)
164 jpye 2033 cmd = ["gdb","--args","python",os.path.join(INSTALL_PYTHON,"gtkbrowser.py")]+args
165 jpye 1358 print cmd
166     os.execv("/usr/bin/gdb",cmd)
167 johnpye 858 else:
168 jpye 1358 import ascpy
169 jpye 1463 olddir = os.getcwd()
170 jpye 2073 print "CWD =",olddir
171 jpye 1463 os.chdir(INSTALL_ASCDATA)
172 jpye 1358 from gtkbrowser import *
173 jpye 1463 os.chdir(olddir)
174 jpye 1616 B = Browser(
175     librarypath=os.environ.get('ASCENDLIBRARY')
176     ,assetspath=os.path.join(INSTALL_ASCDATA,"glade")
177     )
178 jpye 1358 B.run()

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