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