source: branches/newfiller/bin/install@ 2991

Last change on this file since 2991 was 1757, checked in by Kana Sugimoto, 14 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
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 = "/usr/bin/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 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)
46 else:
47 resolved.append(l)
48 return resolved, unresolved
49
50
51try:
52 opts, args = getopt.getopt(sys.argv[1:], "p:m:h",
53 ["exec-prefix=", "module-dir=", "help"])
54
55except getopt.GetoptError:
56 usage()
57 sys.exit(2)
58
59execprefix = dist.EXEC_PREFIX
60moduledir = dist.get_python_lib()
61sysmoduledir = moduledir
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)
79 v = os.path.expandvars(v)
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
85print "Looking fo all required libraries..."
86try:
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:
95 print "Skipping test. (%s)" % msg
96
97print 'Looking for dependent python modules...'
98try:
99 import matplotlib
100except ImportError:
101 print "Matplotlib not found"
102 sys.exit(1)
103if int(matplotlib.__version__.split(".")[1]) < 87:
104 print "Warning: matplotlib version < 0.87." \
105 "This might cause errors. Please upgrade."
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)
119try:
120 import IPython
121except ImportError:
122 print "IPython should be installed."
123 sys.exit(1)
124
125print " All required modules were found."
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)
134 print "Installing asap scripts in %s" % bindir
135 if moduledir != sysmoduledir:
136 import re
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)
150 shutil.copy2("bin/asap_update_data", bindir)
151 shutil.copy2("bin/asap2to3", bindir)
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."
155 print "Installation completed."
156except OSError, oe:
157 print oe
Note: See TracBrowser for help on using the repository browser.