source: trunk/bin/install@ 1217

Last change on this file since 1217 was 1210, checked in by mar637, 18 years ago

Merge from Release2.1.0b tag

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