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

Contents of /trunk/pygtk/ascdev.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2434 - (show annotations) (download)
Sun Mar 27 01:31:57 2011 UTC (11 years, 3 months ago) by jpye
File size: 3404 byte(s)
Output also ASCENDSOLVERS.
1 #!@PYTHON@
2 # to debug this program using 'gdb', invoke 'ASC_GDB=1 ascdev'.
3
4 import os.path, sys, platform;
5
6 def add_at_start(envvar,pathcomponents):
7 """
8 Add path components at start of envvar, but only if they're not already in the path somewhere.
9 @return 1 if changes made, 0 otherwise
10 @TODO what about Windows path munging?
11 """
12
13 # convert pathcomponents to absolute paths
14 pathcomponents = [os.path.abspath(i) for i in pathcomponents]
15
16 if not os.environ.get(envvar):
17 # env var is not yet set; simply set it to requested value
18 v = SEP.join(pathcomponents)
19 print "CREATED %s=%s" % (envvar,v)
20 os.environ[envvar]=v
21 return 1
22
23 changed = 0
24 # convert what's in there to absolute paths for comparison
25 envvals = [os.path.abspath(i) for i in os.environ[envvar].split(SEP)]
26 oldenv = os.environ[envvar]
27 found = []
28 for p in reversed(pathcomponents):
29 if p not in envvals:
30 envvals.insert(0,p)
31 print "INSERTED into %s: %s"%(envvar,p)
32 changed = 1
33
34 # TODO if changes made, let's check for repeated path components and remove them (PyGTK All-in-one does this)
35
36 os.environ[envvar]=SEP.join(envvals)
37 if not changed:
38 print "VAR %s UNCHANGED" % envvar
39 else:
40 print "VAR %s CHANGED" % envvar
41 print "OLD %s = %s" % (envvar,oldenv)
42 print "NEW %s = %s" % (envvar,os.environ[envvar])
43
44 return changed
45
46 if __name__=='__main__':
47 sourceroot="@SOURCE_ROOT@"
48 script=os.path.join(sys.argv[0])
49
50 if platform.system()=="Windows":
51 LD_LIBRARY_PATH="PATH"
52 SEP = ";"
53 elif platform.system()=="Darwin":
54 LD_LIBRARY_PATH="DYLD_LIBRARY_PATH"
55 SEP = ":"
56 else:
57 LD_LIBRARY_PATH="LD_LIBRARY_PATH"
58 SEP = ":"
59
60 restart = []
61
62 # for Mac, add our local PyGTK libraries at start of Python path:
63 #if platform.system()=="Darwin":
64 # sys.path.insert(0,'dist/gtk.bundle/python')
65
66 # ensure that we have our 'models' dir in the ASCENDLIBRARY path
67 modeldirs = [os.path.join(sourceroot,"models")]
68 if add_at_start('ASCENDLIBRARY',modeldirs):
69 restart.append('ASCENDLIBRARY')
70
71 solverdir = os.path.join(sourceroot,"solvers")
72 solverdirs = [os.path.join(solverdir,d.lower()) for d in "@WITH_SOLVERS@".split(",")]
73 if add_at_start('ASCENDSOLVERS',solverdirs):
74 restart.append('ASCENDSOLVERS')
75
76 # ensure that we have our shared libraries in the LD_LIBRARY_PATH
77 libdirs = [sourceroot,os.path.join(sourceroot,"pygtk")]
78 if add_at_start(LD_LIBRARY_PATH,libdirs):
79 restart.append(LD_LIBRARY_PATH)
80
81 # ensure our pygtk dir is in the PYTHONPATH
82 pypath = [os.path.join(sourceroot,"ascxx")]
83 if add_at_start('PYTHONPATH',pypath):
84 restart.append('PYTHONPATH')
85
86 if restart:
87 print "\nRestarting with..."
88 for v in restart:
89 print " export %s=%s" % (v,os.environ[v])
90 if os.environ.get('ASC_GDB'):
91 print " via GDB..."
92 os.execvp("gdb",['--symbols=../@SHLIBPREFIX@ascend@SHLIBSUFFIX@','--args','@PYTHON@',script]+sys.argv[1:])
93 else:
94 print "PYTHON... ",script
95 sys.stdout.flush() # needed for rxvt on Windows
96 os.execvp('@PYTHON@',[script,script]+sys.argv[1:])
97 # the above calls don't return so we can forget about line of enqiry
98
99
100 print "\nRunning with..."
101 for v in [LD_LIBRARY_PATH,'ASCENDLIBRARY','ASCENDSOLVERS','PYTHONPATH','PATH']:
102 print " %s = %s" % (v,os.environ[v])
103
104 import ascpy
105 from gtkbrowser import *
106 assetspath = os.path.join(os.path.join(sourceroot,"pygtk"),"glade")
107 print "ASSETS PATH = %s" % assetspath
108 B = Browser(assetspath=assetspath)
109 B.run()

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