[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 |
|
---|
| 16 | try:
|
---|
| 17 | opts, args = getopt.getopt(sys.argv[1:], "p:m:h",
|
---|
| 18 | ["exec-prefix=", "module-dir=", "help"])
|
---|
[1173] | 19 |
|
---|
[1163] | 20 | except getopt.GetoptError:
|
---|
[1172] | 21 | usage()
|
---|
[1163] | 22 | sys.exit(2)
|
---|
| 23 |
|
---|
| 24 | execprefix = dist.EXEC_PREFIX
|
---|
| 25 | moduledir = dist.get_python_lib()
|
---|
| 26 | for k, v in opts:
|
---|
| 27 | if k in ("-h", "--help"):
|
---|
| 28 | usage()
|
---|
| 29 | sys.exit()
|
---|
| 30 | if k in ("-p", "--exec-prefix"):
|
---|
| 31 | v = os.path.expanduser(v)
|
---|
| 32 | v = os.path.expandvars(v)
|
---|
| 33 | if not os.path.exists(v):
|
---|
| 34 | print "The specified exec directory %s doesn't exist" % v
|
---|
| 35 | sys.exit(1)
|
---|
| 36 | p = os.path.join(v,"bin")
|
---|
| 37 | if not os.path.exists(p):
|
---|
| 38 | print "The specified exec directory %s doesn't exist" % p
|
---|
| 39 | sys.exit(1)
|
---|
| 40 | execprefix = v
|
---|
| 41 | if k in ("-m", "--module-dir"):
|
---|
| 42 | v = os.path.expanduser(v)
|
---|
[1173] | 43 | v = os.path.expandvars(v)
|
---|
[1163] | 44 | if not os.path.exists(v):
|
---|
| 45 | print "The specified module directory %s doesn't exist" % v
|
---|
| 46 | sys.exit(1)
|
---|
| 47 | moduledir = v
|
---|
| 48 |
|
---|
| 49 | print 'Looking for dependent modules...'
|
---|
| 50 | try:
|
---|
| 51 | import matplotlib
|
---|
| 52 | except ImportError:
|
---|
| 53 | print "Matplotlib not found"
|
---|
| 54 | sys.exit(1)
|
---|
[1173] | 55 | if int(matplotlib.__version__.split(".")[1]) < 87:
|
---|
[1172] | 56 | print "Warning: matplotlib version < 0.87." \
|
---|
| 57 | "This might cause errors. Please upgrade."
|
---|
[1163] | 58 | try:
|
---|
| 59 | import matplotlib.backends.backend_tkagg
|
---|
| 60 | except ImportError:
|
---|
| 61 | print "Matplotlib doesn't have Tk support"
|
---|
| 62 | sys.exit(1)
|
---|
| 63 | try:
|
---|
| 64 | import numpy
|
---|
| 65 | except ImportError:
|
---|
| 66 | try:
|
---|
| 67 | import numarray
|
---|
| 68 | except ImportError:
|
---|
| 69 | print "You need to have either 'numpy' or 'numarray' installed."
|
---|
| 70 | sys.exit(1)
|
---|
[1172] | 71 | try:
|
---|
| 72 | import IPython
|
---|
| 73 | except ImportError:
|
---|
| 74 | print "IPython should be installed."
|
---|
| 75 | sys.exit(1)
|
---|
| 76 |
|
---|
| 77 | print "All required modules were found."
|
---|
[1163] | 78 | moddir = os.path.join(moduledir, "asap")
|
---|
| 79 | bindir = os.path.join(execprefix, "bin")
|
---|
| 80 | try:
|
---|
| 81 | if os.path.exists(moddir):
|
---|
| 82 | print "Found previous installation of ASAP. Removing..."
|
---|
| 83 | shutil.rmtree(moddir)
|
---|
| 84 | print "Installing asap module in %s" % moddir
|
---|
| 85 | shutil.copytree("asap", moddir)
|
---|
| 86 | print "Installing asap startup script in %s" % bindir
|
---|
| 87 | shutil.copy2("bin/asap", bindir)
|
---|
| 88 | shutil.copytree("data", os.path.join(moddir,"data"))
|
---|
| 89 | print "Installation completed."
|
---|
| 90 | except OSError, oe:
|
---|
| 91 | print oe
|
---|