source: branches/Release2.1/bin/install@ 2442

Last change on this file since 2442 was 1220, checked in by mar637, 18 years ago

forgot a colon after if

  • Property svn:executable set to *
File size: 4.3 KB
Line 
1#!/usr/bin/env python
2
3import distutils.sysconfig as dist
4import shutil
5import os
6import sys
7import getopt
8
9def usage():
10 print """Usage:
11 ./install [-p <prefix for asap binary>]
12 [-m <where to install python module>]
13 [-h] this message
14 """
15
16def get_libs(lib='_asap.so'):
17 lddcommand = "/usr/bin/ldd"
18 lddopts = ""
19 if (sys.platform == "darwin"):
20 lddcommand = "otool"
21 lddopts = "-L"
22 if not os.path.isfile(lddcommand):
23 raise IOError("ldd/otool is not available")
24 if not os.path.exists(lib):
25 raise IOError("File %s not found" %lib)
26 p = os.popen(lddcommand+" "+lddopts+" "+lib)
27 resolved = []
28 unresolved = []
29 for l in p.readlines():
30 lsp = l.split()
31 # test this to avoid fails on linux_gate, which has no library
32 if len(lsp) >= 3:
33 if lsp[2] == "not":
34 unresolved.append(lsp[0])
35 else:
36 resolved.append(lsp[2])
37 return resolved, unresolved
38
39try:
40 opts, args = getopt.getopt(sys.argv[1:], "p:m:h",
41 ["exec-prefix=", "module-dir=", "help"])
42
43except getopt.GetoptError:
44 usage()
45 sys.exit(2)
46
47execprefix = dist.EXEC_PREFIX
48moduledir = dist.get_python_lib()
49sysmoduledir = moduledir
50for k, v in opts:
51 if k in ("-h", "--help"):
52 usage()
53 sys.exit()
54 if k in ("-p", "--exec-prefix"):
55 v = os.path.expanduser(v)
56 v = os.path.expandvars(v)
57 if not os.path.exists(v):
58 print "The specified exec directory %s doesn't exist" % v
59 sys.exit(1)
60 p = os.path.join(v,"bin")
61 if not os.path.exists(p):
62 print "The specified exec directory %s doesn't exist" % p
63 sys.exit(1)
64 execprefix = v
65 if k in ("-m", "--module-dir"):
66 v = os.path.expanduser(v)
67 v = os.path.expandvars(v)
68 if not os.path.exists(v):
69 print "The specified module directory %s doesn't exist" % v
70 sys.exit(1)
71 moduledir = v
72
73print "Looking fo all required libraries..."
74try:
75 libs, missing = get_libs(lib="asap/_asap.so")
76 if len(missing):
77 print " The following libraries are missing:"
78 print missing
79 sys.exit(1)
80 else:
81 print " All required libraries are present."
82except IOError,msg:
83 print "Skipping test. (%s)" % msg
84
85print 'Looking for dependent python modules...'
86try:
87 import matplotlib
88except ImportError:
89 print "Matplotlib not found"
90 sys.exit(1)
91if int(matplotlib.__version__.split(".")[1]) < 87:
92 print "Warning: matplotlib version < 0.87." \
93 "This might cause errors. Please upgrade."
94try:
95 import matplotlib.backends.backend_tkagg
96except ImportError:
97 print "Matplotlib doesn't have Tk support"
98 sys.exit(1)
99try:
100 import numpy
101except ImportError:
102 try:
103 import numarray
104 except ImportError:
105 print "You need to have either 'numpy' or 'numarray' installed."
106 sys.exit(1)
107try:
108 import IPython
109except ImportError:
110 print "IPython should be installed."
111 sys.exit(1)
112
113print " All required modules were found."
114moddir = os.path.join(moduledir, "asap")
115bindir = os.path.join(execprefix, "bin")
116try:
117 if os.path.exists(moddir):
118 print "Found previous installation of ASAP. Removing..."
119 shutil.rmtree(moddir)
120 print "Installing asap module in %s" % moddir
121 shutil.copytree("asap", moddir)
122 print "Installing asap scripts in %s" % bindir
123 if moduledir != sysmoduledir:
124 import sre
125 print "Changing asap startup script to use custom PYTHONPATH"
126 inf = file("bin/asap")
127 outf = file(os.path.join(bindir,"asap"), "w")
128 outline = "export PYTHONPATH=%s" % moduledir
129 regx = sre.compile("\*\*PYTHONPATH\*\*")
130 for line in inf.readlines():
131 if regx.search(line):
132 line = outline
133 outf.write(line)
134 outf.close()
135 os.chmod(os.path.join(bindir,"asap"), 0755)
136 else:
137 shutil.copy2("bin/asap", bindir)
138 shutil.copy2("bin/asap_update_data", bindir)
139 if not os.path.exists("asap/data/ephemerides"):
140 print "Warning - no data directory present"
141 print "Please run asap_update_data after the installation is completed."
142 print "Installation completed."
143except OSError, oe:
144 print oe
Note: See TracBrowser for help on using the repository browser.