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

Contents of /trunk/pygtk/ascend.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1614 - (show annotations) (download)
Mon Sep 3 06:54:37 2007 UTC (12 years, 3 months ago) by jpye
File size: 4545 byte(s)
Added 'ascend.bat' to Windows installer output for easier command-line use.
Added note about possible colour output in Windows command prompt.
Some work on command-line detection of ASCENDLIBRARY and ASCENDSOLVERS env vars. Ongoing.
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 PYTHON="@PYTHON@"
46 DEFAULT_ASCENDLIBRARY="""@DEFAULT_ASCENDLIBRARY@"""
47 SEP=":"
48 LDPATHVAR = 'LD_LIBRARY_PATH'
49 GTKLIBS = None # assume the GTK will be in the standard library path
50
51 #-----------------------------------------------------------------------
52
53 if os.environ.get(LDPATHVAR):
54 LDPATH = os.environ.get(LDPATHVAR).split(SEP)
55 else:
56 LDPATH = []
57
58 if not os.environ.get('ASC_GDB'):
59 # restarting messes up GDB so don't allow it
60
61 if platform.system()=="Windows":
62 # Put INSTALL_LIB then GTK at start of path
63 if GTKLIBS in LDPATH:
64 LDPATH.remove(GTKLIBS)
65 LDPATH=[INSTALL_LIB,GTKLIBS]+LDPATH
66 os.environ[LDPATHVAR] = SEP.join(LDPATH)
67 restart = 1
68
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 os.environ.get('ASCENDLIBRARY'):
76 envmodels = [os.path.abspath(i) for i in os.environ['ASCENDLIBRARY'].split(SEP)]
77 if not INSTALL_MODELS in envmodels:
78 envmodels.append(INSTALL_MODELS)
79 os.environ['ASCENDLIBRARY'] = SEP.join(envmodels)
80 restart = 1
81
82 if os.environ.get('ASCENDSOLVERS'):
83 envsolvers = [os.path.abspath(i) for i in os.environ['ASCENDSOLVERS'].split(SEP)]
84 if not INSTALL_SOLVERS in envsolvers:
85 envsolvers.append(INSTALL_SOLVERS)
86 os.environ['ASCENDSOLVERS'] = SEP.join(envsolvers)
87 restart = 1
88
89 if restart:
90 print "Restarting with corrected environment..."
91 print " %s = %s" % (LDPATHVAR,os.environ.get(LDPATHVAR))
92 print " ASCENDLIBRARY = %s" % os.environ.get('ASCENDLIBRARY')
93 print " ASCENDSOLVERS = %s" % os.environ.get('ASCENDSOLVERS')
94 script = os.path.join(sys.path[0],"ascend")
95 print "PYTHON =",PYTHON
96 print "script =",script
97 if platform.system()=="Windows":
98 print "DROPPING THROUGH"
99 else:
100 os.execve(PYTHON,[script] + sys.argv, os.environ)
101
102
103 print "Running with..."
104 print " %s = %s" % (LDPATHVAR, os.environ.get(LDPATHVAR))
105 print " sys.path = %s" % sys.path
106 print " argv = %s" % sys.argv
107
108 if os.environ.get('ASCENDLIBRARY'):
109 ASCENDLIBRARY = os.environ.get('ASCENDLIBRARY')
110 print "USING ASCENDLIBRARY=%s" % ASCENDLIBRARY
111 else:
112 ASCENDLIBRARY = DEFAULT_ASCENDLIBRARY
113 print "default ASCENDLIBRARY=%s" % ASCENDLIBRARY
114
115 print "sys.path[0] = %s" % sys.path[0]
116
117 if not INSTALL_ASCDATA in sys.path:
118 print "Adding INSTALL_ASCDATA to python path?"
119 sys.path.append(INSTALL_ASCDATA)
120
121 if os.environ.get('OSTYPE')=='cygwin':
122 print "CYGWIN..."
123 elif os.environ.get('OSTYPE')=='msys':
124 print "MSYS..."
125
126 if os.environ.get('ASC_GDB'):
127 args = sys.argv
128 args.pop(0)
129 cmd = ["gdb","--args","python",os.path.join(INSTALL_ASCDATA,"gtkbrowser.py")]+args
130 print cmd
131 os.execv("/usr/bin/gdb",cmd)
132 else:
133 import ascpy
134 olddir = os.getcwd()
135 os.chdir(INSTALL_ASCDATA)
136 from gtkbrowser import *
137 os.chdir(olddir)
138 B = Browser(librarypath=ASCENDLIBRARY,assetspath=os.path.join(INSTALL_ASCDATA,"glade"))
139 B.run()

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