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

Contents of /trunk/pygtk/ascend.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1467 - (show annotations) (download)
Sun Jun 3 06:19:35 2007 UTC (15 years, 6 months ago) by jpye
File size: 4358 byte(s)
More work on Windows installer detection of PyGTK, PyCairo etc at install-time.
1 #!@PYTHON@
2
3 import os.path, sys, platform
4
5 restart = 0
6
7 # This script handles restarting ascend if it's invoked without the full
8 # complement of env vars. You can override values used by this script
9 # by setting the appropriate env vars before this script is run.
10
11 # Note that as well as env vars, ASCEND is also controllable using the
12 # .ascend.ini file in the user's home directory.
13
14 #-----------------------------------------------------------------------
15 # Get locations of the installed files. On windows, these are defined in
16 # in the registry. On other systems, these are defined at compile time
17 # by @VARNAME@ substitution.
18
19 if platform.system()=="Windows":
20 import _winreg as wreg
21 k = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, "SOFTWARE\ASCEND")
22 print k
23
24 # for some reason, QueryValue doesn't work on Py 2.4, need to use QueryValueEx.
25 DEFAULT_ASCENDLIBRARY,t = wreg.QueryValueEx(k,"INSTALL_MODELS")
26 INSTALL_LIB,t = wreg.QueryValueEx(k,"INSTALL_LIB")
27 INSTALL_ASCDATA,t = wreg.QueryValueEx(k,"INSTALL_ASCDATA")
28 GTKLIBS,t = wreg.QueryValueEx(k,"GTKLIBS");
29
30 PYVERSION = "@PYVERSION@"
31
32 k = wreg.OpenKey(wreg.HKEY_CURRENT_USER,"SOFTWARE\Python\PythonCore\%s\InstallPath" % PYVERSION)
33 pypath,t = wreg.QueryValueEx(k,"")
34 if pypath == '':
35 k = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE,"SOFTWARE\Python\PythonCore\%s\InstallPath" % PYVERSION)
36 pypath,t = wreg.QueryValueEx(k,"")
37 if pypath == '':
38 import winsound
39 winsound.MessageBeep(MB_ICONEXCLAMATION)
40 print "Unable to locate Python install path"
41 sys.exit(1)
42
43 print "pypath =",pypath
44
45 PYTHON=os.path.join(pypath,"pythonw.exe")
46
47 print "PYTHON =",PYTHON
48 SEP=";"
49 LDPATHVAR = 'PATH'
50 else:
51 INSTALL_LIB="@INSTALL_LIB@"
52 INSTALL_ASCDATA="@INSTALL_ASCDATA@"
53 PYTHON="@PYTHON@"
54 DEFAULT_ASCENDLIBRARY="""@DEFAULT_ASCENDLIBRARY@"""
55 SEP=":"
56 LDPATHVAR = 'LD_LIBRARY_PATH'
57 GTKLIBS = None # assume the GTK will be in the standard library path
58
59 #-----------------------------------------------------------------------
60
61 if os.environ.get(LDPATHVAR):
62 LDPATH = os.environ.get(LDPATHVAR).split(SEP)
63 else:
64 LDPATH = []
65
66 if not os.environ.get('ASC_GDB'):
67 # restarting messes up GDB so don't allow it
68
69 if platform.system()=="Windows":
70 # Put INSTALL_LIB then GTK at start of path
71 if GTKLIBS in LDPATH:
72 LDPATH.remove(GTKLIBS)
73 LDPATH=[INSTALL_LIB,GTKLIBS]+LDPATH
74 os.environ[LDPATHVAR] = SEP.join(LDPATH)
75 restart = 1
76
77 elif INSTALL_LIB != "/usr/lib" and not INSTALL_LIB in LDPATH:
78 # don't worry about GTK location; just ensure that LDPATH includes INSTALL_LIB
79 LDPATH = [INSTALL_LIB] + LDPATH
80 os.environ[LDPATHVAR] = SEP.join(LDPATH)
81 restart = 1
82
83 if os.environ.get('ASCENDLIBRARY'):
84 envmodels = [os.path.abspath(i) for i in os.environ['ASCENDLIBRARY'].split(SEP)]
85 ascmodels = os.path.abspath(INSTALL_ASCDATA+"/models")
86 if not ascmodels in envmodels:
87 envmodels.append(ascmodels)
88 os.environ['ASCENDLIBRARY'] = SEP.join(envmodels)
89 restart = 1
90
91 if restart:
92 print "Restarting with corrected environment..."
93 print " %s = %s" % (LDPATHVAR,os.environ.get(LDPATHVAR))
94 print " ASCENDLIBRARY = %s" % os.environ.get('ASCENDLIBRARY')
95 script = os.path.join(sys.path[0],"ascend")
96 print "PYTHON =",PYTHON
97 print "script =",script
98 if platform.system()=="Windows":
99 print "DROPPING THROUGH"
100 else:
101 os.execve(PYTHON,[script] + sys.argv, os.environ)
102
103
104 print "Running with..."
105 print " %s = %s" % (LDPATHVAR, os.environ.get(LDPATHVAR))
106 print " sys.path = %s" % sys.path
107 print " argv = %s" % sys.argv
108
109 if os.environ.get('ASCENDLIBRARY'):
110 ASCENDLIBRARY = os.environ.get('ASCENDLIBRARY')
111 print "USING ASCENDLIBRARY=%s" % ASCENDLIBRARY
112 else:
113 ASCENDLIBRARY = DEFAULT_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