source: branches/alma/bin/install@ 2708

Last change on this file since 2708 was 1757, checked in by Kana Sugimoto, 15 years ago

New Development: Yes

JIRA Issue: Yes (CAS-2211)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: ASAP 3.0.0 interface changes

Test Programs:

Put in Release Notes: Yes

Module(s): all the CASA sd tools and tasks are affected.

Description: Merged ATNF-ASAP 3.0.0 developments to CASA (alma) branch.

Note you also need to update casa/code/atnf.


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