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

Diff of /trunk/pygtk/ascend.in

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1462 by jpye, Thu Mar 29 00:15:59 2007 UTC revision 1463 by jpye, Sun Jun 3 02:48:17 2007 UTC
# Line 4  import os.path, sys, platform Line 4  import os.path, sys, platform
4    
5  restart = 0  restart = 0
6    
7  # this script handles restarting ascend if it's invoked without the full  # This script handles restarting ascend if it's invoked without the full
8  # complement of env vars  # 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":  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=";"      SEP=";"
49        LDPATHVAR = 'PATH'
50  else:  else:
51        INSTALL_LIB="@INSTALL_LIB@"
52        INSTALL_ASCDATA="@INSTALL_ASCDATA@"
53        PYTHON="@PYTHON@"
54        DEFAULT_ASCENDLIBRARY="""@DEFAULT_ASCENDLIBRARY@"""
55      SEP=":"      SEP=":"
56        LDPATHVAR = 'LD_LIBRARY_PATH'
57        GTKLIBS = None # assume the GTK will be in the standard library path
58    
59  if os.environ.get('LD_LIBRARY_PATH'):  #-----------------------------------------------------------------------
60      LD_LIBRARY_PATH = os.environ.get('LD_LIBRARY_PATH').split(SEP)  
61    if os.environ.get(LDPATHVAR):
62        LDPATH = os.environ.get(LDPATHVAR).split(SEP)
63  else:  else:
64      #LD_LIBRARY_PATH = ['/usr/local/lib']      LDPATH = []
     LD_LIBRARY_PATH = []  
65    
66  if not os.environ.get('ASC_GDB'):  if not os.environ.get('ASC_GDB'):
67      # restarting messes up GDB so don't allow it      # restarting messes up GDB so don't allow it
     if "@INSTALL_LIB@"!="/usr/lib":  
           
         if not "@INSTALL_LIB@" in LD_LIBRARY_PATH:  
             LD_LIBRARY_PATH = ["@INSTALL_LIB@"] + LD_LIBRARY_PATH  
             os.environ['LD_LIBRARY_PATH'] = SEP.join(LD_LIBRARY_PATH)  
             restart = 1  
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      PYTHONPATH = os.environ.get("PYTHONPATH")      PYTHONPATH = os.environ.get("PYTHONPATH")
84      if not PYTHONPATH:      if not PYTHONPATH:
85          os.environ['PYTHONPATH'] = SEP.join(["@INSTALL_ASCDATA@"])          os.environ['PYTHONPATH'] = SEP.join([INSTALL_ASCDATA])
86          restart = 1          restart = 1
87      elif not "@INSTALL_ASCDATA@" in PYTHONPATH.split(SEP):      elif not INSTALL_ASCDATA in PYTHONPATH.split(SEP):
88          os.environ['PYTHONPATH'] = SEP.join(["@INSTALL_ASCDATA@"] + PYTHONPATH.split(SEP))          os.environ['PYTHONPATH'] = SEP.join([INSTALL_ASCDATA] + PYTHONPATH.split(SEP))
89          restart = 1          restart = 1
90    
91      if os.environ.get('ASCENDLIBRARY'):      if os.environ.get('ASCENDLIBRARY'):
92          envmodels = [os.path.abspath(i) for i in os.environ['ASCENDLIBRARY'].split(SEP)]          envmodels = [os.path.abspath(i) for i in os.environ['ASCENDLIBRARY'].split(SEP)]
93          ascmodels = os.path.abspath("@INSTALL_ASCDATA@/models")          ascmodels = os.path.abspath(INSTALL_ASCDATA+"/models")
94          if not ascmodels in envmodels:          if not ascmodels in envmodels:
95              envmodels.append(ascmodels)              envmodels.append(ascmodels)
96              os.environ['ASCENDLIBRARY'] = SEP.join(envmodels)              os.environ['ASCENDLIBRARY'] = SEP.join(envmodels)
# Line 45  if not os.environ.get('ASC_GDB'): Line 98  if not os.environ.get('ASC_GDB'):
98    
99      if restart:      if restart:
100          print "Restarting with corrected environment..."          print "Restarting with corrected environment..."
101          print "   LD_LIBRARY_PATH = %s" % os.environ.get('LD_LIBRARY_PATH')          print "   %s = %s" % (LDPATHVAR,os.environ.get(LDPATHVAR))
102          print "   PYTHONPATH = %s" % os.environ['PYTHONPATH']          print "   PYTHONPATH = %s" % os.environ['PYTHONPATH']
103          print "   ASCENDLIBRARY = %s" % os.environ.get('ASCENDLIBRARY')          print "   ASCENDLIBRARY = %s" % os.environ.get('ASCENDLIBRARY')
104          script = os.path.join(sys.path[0],"ascend")          script = os.path.join(sys.path[0],"ascend")
105          os.execv("@PYTHON@",[script] + sys.argv)          print "PYTHON =",PYTHON
106            print "script =",script
107            if platform.system()=="Windows":
108                print "DROPPING THROUGH"
109            else:
110                os.execve(PYTHON,[script] + sys.argv, os.environ)
111            
112    
113  print "Running with..."  print "Running with..."
114  print "   LD_LIBRARY_PATH = %s" % os.environ.get('LD_LIBRARY_PATH')  print "   %s = %s" % (LDPATHVAR, os.environ.get(LDPATHVAR))
115  print "   PYTHONPATH = %s" % os.environ.get('PYTHONPATH')  print "   PYTHONPATH = %s" % os.environ.get('PYTHONPATH')
116  print "   argv = %s" % sys.argv  print "   argv = %s" % sys.argv
117    
# Line 61  if os.environ.get('ASCENDLIBRARY'): Line 119  if os.environ.get('ASCENDLIBRARY'):
119      ASCENDLIBRARY = os.environ.get('ASCENDLIBRARY')      ASCENDLIBRARY = os.environ.get('ASCENDLIBRARY')
120      print "USING ASCENDLIBRARY=%s" % ASCENDLIBRARY      print "USING ASCENDLIBRARY=%s" % ASCENDLIBRARY
121  else:  else:
122      ASCENDLIBRARY = """@DEFAULT_ASCENDLIBRARY@"""      ASCENDLIBRARY = DEFAULT_ASCENDLIBRARY
123    
124  print "sys.path[0] = %s" % sys.path[0]  print "sys.path[0] = %s" % sys.path[0]
125    
126  if not "@INSTALL_ASCDATA@" in sys.path:  if not INSTALL_ASCDATA in sys.path:
127      print "Where is @INSTALL_ASCDATA@?"      print "Adding INSTALL_ASCDATA to python path?"
128      sys.path.append("@INSTALL_ASCDATA@")      sys.path.append(INSTALL_ASCDATA)
129    
130  if os.environ.get('OSTYPE')=='cygwin':  if os.environ.get('OSTYPE')=='cygwin':
131      print "CYGWIN..."      print "CYGWIN..."
# Line 77  elif os.environ.get('OSTYPE')=='msys': Line 135  elif os.environ.get('OSTYPE')=='msys':
135  if os.environ.get('ASC_GDB'):  if os.environ.get('ASC_GDB'):
136      args = sys.argv      args = sys.argv
137      args.pop(0)      args.pop(0)
138      cmd = ["gdb","--args","python",os.path.join("@INSTALL_ASCDATA@","gtkbrowser.py")]+args      cmd = ["gdb","--args","python",os.path.join(INSTALL_ASCDATA,"gtkbrowser.py")]+args
139      print cmd      print cmd
140      os.execv("/usr/bin/gdb",cmd)      os.execv("/usr/bin/gdb",cmd)
141  else:  else:
142      import ascpy      import ascpy
143        olddir = os.getcwd()
144        os.chdir(INSTALL_ASCDATA)
145      from gtkbrowser import *      from gtkbrowser import *
146      B = Browser()      os.chdir(olddir)
147        B = Browser(librarypath=ASCENDLIBRARY,assetspath=os.path.join(INSTALL_ASCDATA,"glade"))
148      B.run()      B.run()

Legend:
Removed from v.1462  
changed lines
  Added in v.1463

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