[1163] | 1 | #!/usr/bin/env python
|
---|
| 2 |
|
---|
| 3 | import distutils.sysconfig as dist
|
---|
| 4 | import shutil
|
---|
| 5 | import os
|
---|
| 6 | import sys
|
---|
| 7 | import getopt
|
---|
| 8 |
|
---|
| 9 | def 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] | 16 | def get_libs(lib='_asap.so'):
|
---|
| 17 | lddcommand = "/usr/bin/ldd"
|
---|
| 18 | lddopts = ""
|
---|
| 19 | if (sys.platform == "darwin"):
|
---|
| 20 | lddcommand = "otool"
|
---|
| 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 = []
|
---|
| 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 |
|
---|
[1163] | 37 | try:
|
---|
| 38 | opts, args = getopt.getopt(sys.argv[1:], "p:m:h",
|
---|
| 39 | ["exec-prefix=", "module-dir=", "help"])
|
---|
[1173] | 40 |
|
---|
[1163] | 41 | except getopt.GetoptError:
|
---|
[1172] | 42 | usage()
|
---|
[1163] | 43 | sys.exit(2)
|
---|
| 44 |
|
---|
| 45 | execprefix = dist.EXEC_PREFIX
|
---|
| 46 | moduledir = dist.get_python_lib()
|
---|
| 47 | for k, v in opts:
|
---|
| 48 | if k in ("-h", "--help"):
|
---|
| 49 | usage()
|
---|
| 50 | sys.exit()
|
---|
| 51 | if k in ("-p", "--exec-prefix"):
|
---|
| 52 | v = os.path.expanduser(v)
|
---|
| 53 | v = os.path.expandvars(v)
|
---|
| 54 | if not os.path.exists(v):
|
---|
| 55 | print "The specified exec directory %s doesn't exist" % v
|
---|
| 56 | sys.exit(1)
|
---|
| 57 | p = os.path.join(v,"bin")
|
---|
| 58 | if not os.path.exists(p):
|
---|
| 59 | print "The specified exec directory %s doesn't exist" % p
|
---|
| 60 | sys.exit(1)
|
---|
| 61 | execprefix = v
|
---|
| 62 | if k in ("-m", "--module-dir"):
|
---|
| 63 | v = os.path.expanduser(v)
|
---|
[1173] | 64 | v = os.path.expandvars(v)
|
---|
[1163] | 65 | if not os.path.exists(v):
|
---|
| 66 | print "The specified module directory %s doesn't exist" % v
|
---|
| 67 | sys.exit(1)
|
---|
| 68 | moduledir = v
|
---|
| 69 |
|
---|
[1181] | 70 | print "Looking fo all required libraries..."
|
---|
[1163] | 71 | try:
|
---|
[1181] | 72 | libs, missing = get_libs(lib="asap/_asap.so")
|
---|
| 73 | if len(missing):
|
---|
| 74 | print " The following libraries are missing:"
|
---|
| 75 | print missing
|
---|
| 76 | sys.exit(1)
|
---|
| 77 | else:
|
---|
| 78 | print " All required libraries are present."
|
---|
| 79 | except IOError,msg:
|
---|
| 80 | print msg+" Skipping test."
|
---|
| 81 |
|
---|
| 82 | print 'Looking for dependent python modules...'
|
---|
| 83 | try:
|
---|
[1163] | 84 | import matplotlib
|
---|
| 85 | except ImportError:
|
---|
| 86 | print "Matplotlib not found"
|
---|
| 87 | sys.exit(1)
|
---|
[1173] | 88 | if int(matplotlib.__version__.split(".")[1]) < 87:
|
---|
[1172] | 89 | print "Warning: matplotlib version < 0.87." \
|
---|
| 90 | "This might cause errors. Please upgrade."
|
---|
[1163] | 91 | try:
|
---|
| 92 | import matplotlib.backends.backend_tkagg
|
---|
| 93 | except ImportError:
|
---|
| 94 | print "Matplotlib doesn't have Tk support"
|
---|
| 95 | sys.exit(1)
|
---|
| 96 | try:
|
---|
| 97 | import numpy
|
---|
| 98 | except ImportError:
|
---|
| 99 | try:
|
---|
| 100 | import numarray
|
---|
| 101 | except ImportError:
|
---|
| 102 | print "You need to have either 'numpy' or 'numarray' installed."
|
---|
| 103 | sys.exit(1)
|
---|
[1172] | 104 | try:
|
---|
| 105 | import IPython
|
---|
| 106 | except ImportError:
|
---|
| 107 | print "IPython should be installed."
|
---|
| 108 | sys.exit(1)
|
---|
| 109 |
|
---|
[1181] | 110 | print " All required modules were found."
|
---|
[1163] | 111 | moddir = os.path.join(moduledir, "asap")
|
---|
| 112 | bindir = os.path.join(execprefix, "bin")
|
---|
| 113 | try:
|
---|
| 114 | if os.path.exists(moddir):
|
---|
| 115 | print "Found previous installation of ASAP. Removing..."
|
---|
| 116 | shutil.rmtree(moddir)
|
---|
| 117 | print "Installing asap module in %s" % moddir
|
---|
| 118 | shutil.copytree("asap", moddir)
|
---|
[1181] | 119 | print "Installing asap scripts in %s" % bindir
|
---|
[1163] | 120 | shutil.copy2("bin/asap", bindir)
|
---|
[1181] | 121 | shutil.copy2("bin/asap_update_data", bindir)
|
---|
[1195] | 122 | if not os.path.exists("asap/data/ephemerides"):
|
---|
| 123 | print "Warning - no data directory present"
|
---|
| 124 | print "Please run asap_update_data after the installation is completed."
|
---|
[1163] | 125 | print "Installation completed."
|
---|
| 126 | except OSError, oe:
|
---|
| 127 | print oe
|
---|