| [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() | 
|---|
| [1219] | 31 | # test this to avoid fails on linux_gate, which has no library | 
|---|
| [1220] | 32 | if len(lsp) >= 3: | 
|---|
| [1219] | 33 | if lsp[2] == "not": | 
|---|
|  | 34 | unresolved.append(lsp[0]) | 
|---|
|  | 35 | else: | 
|---|
|  | 36 | resolved.append(lsp[2]) | 
|---|
| [1181] | 37 | return resolved, unresolved | 
|---|
|  | 38 |  | 
|---|
| [1163] | 39 | try: | 
|---|
|  | 40 | opts, args = getopt.getopt(sys.argv[1:], "p:m:h", | 
|---|
|  | 41 | ["exec-prefix=", "module-dir=", "help"]) | 
|---|
| [1173] | 42 |  | 
|---|
| [1163] | 43 | except getopt.GetoptError: | 
|---|
| [1172] | 44 | usage() | 
|---|
| [1163] | 45 | sys.exit(2) | 
|---|
|  | 46 |  | 
|---|
|  | 47 | execprefix = dist.EXEC_PREFIX | 
|---|
|  | 48 | moduledir = dist.get_python_lib() | 
|---|
| [1209] | 49 | sysmoduledir = moduledir | 
|---|
| [1163] | 50 | for k, v in opts: | 
|---|
|  | 51 | if k in ("-h", "--help"): | 
|---|
|  | 52 | usage() | 
|---|
|  | 53 | sys.exit() | 
|---|
|  | 54 | if k in ("-p", "--exec-prefix"): | 
|---|
|  | 55 | v = os.path.expanduser(v) | 
|---|
|  | 56 | v = os.path.expandvars(v) | 
|---|
|  | 57 | if not os.path.exists(v): | 
|---|
|  | 58 | print "The specified exec directory %s doesn't exist" % v | 
|---|
|  | 59 | sys.exit(1) | 
|---|
|  | 60 | p = os.path.join(v,"bin") | 
|---|
|  | 61 | if not os.path.exists(p): | 
|---|
|  | 62 | print "The specified exec directory %s doesn't exist" % p | 
|---|
|  | 63 | sys.exit(1) | 
|---|
|  | 64 | execprefix = v | 
|---|
|  | 65 | if k in ("-m", "--module-dir"): | 
|---|
|  | 66 | v = os.path.expanduser(v) | 
|---|
| [1173] | 67 | v = os.path.expandvars(v) | 
|---|
| [1163] | 68 | if not os.path.exists(v): | 
|---|
|  | 69 | print "The specified module directory %s doesn't exist" % v | 
|---|
|  | 70 | sys.exit(1) | 
|---|
|  | 71 | moduledir = v | 
|---|
|  | 72 |  | 
|---|
| [1181] | 73 | print "Looking fo all required libraries..." | 
|---|
| [1163] | 74 | try: | 
|---|
| [1181] | 75 | libs, missing = get_libs(lib="asap/_asap.so") | 
|---|
|  | 76 | if len(missing): | 
|---|
|  | 77 | print " The following libraries are missing:" | 
|---|
|  | 78 | print missing | 
|---|
|  | 79 | sys.exit(1) | 
|---|
|  | 80 | else: | 
|---|
|  | 81 | print "   All required libraries are present." | 
|---|
|  | 82 | except IOError,msg: | 
|---|
| [1219] | 83 | print "Skipping test. (%s)" % msg | 
|---|
| [1181] | 84 |  | 
|---|
|  | 85 | print 'Looking for dependent python modules...' | 
|---|
|  | 86 | try: | 
|---|
| [1163] | 87 | import matplotlib | 
|---|
|  | 88 | except ImportError: | 
|---|
|  | 89 | print "Matplotlib not found" | 
|---|
|  | 90 | sys.exit(1) | 
|---|
| [1173] | 91 | if int(matplotlib.__version__.split(".")[1]) < 87: | 
|---|
| [1172] | 92 | print "Warning: matplotlib version < 0.87." \ | 
|---|
|  | 93 | "This might cause errors. Please upgrade." | 
|---|
| [1163] | 94 | try: | 
|---|
|  | 95 | import matplotlib.backends.backend_tkagg | 
|---|
|  | 96 | except ImportError: | 
|---|
|  | 97 | print "Matplotlib doesn't have Tk support" | 
|---|
|  | 98 | sys.exit(1) | 
|---|
|  | 99 | try: | 
|---|
|  | 100 | import numpy | 
|---|
|  | 101 | except ImportError: | 
|---|
|  | 102 | try: | 
|---|
|  | 103 | import numarray | 
|---|
|  | 104 | except ImportError: | 
|---|
|  | 105 | print "You need to have either 'numpy' or 'numarray' installed." | 
|---|
|  | 106 | sys.exit(1) | 
|---|
| [1172] | 107 | try: | 
|---|
|  | 108 | import IPython | 
|---|
|  | 109 | except ImportError: | 
|---|
|  | 110 | print "IPython should be installed." | 
|---|
|  | 111 | sys.exit(1) | 
|---|
|  | 112 |  | 
|---|
| [1181] | 113 | print "   All required modules were found." | 
|---|
| [1163] | 114 | moddir = os.path.join(moduledir, "asap") | 
|---|
|  | 115 | bindir =  os.path.join(execprefix, "bin") | 
|---|
|  | 116 | try: | 
|---|
|  | 117 | if os.path.exists(moddir): | 
|---|
|  | 118 | print "Found previous installation of ASAP. Removing..." | 
|---|
|  | 119 | shutil.rmtree(moddir) | 
|---|
|  | 120 | print "Installing asap module in %s" % moddir | 
|---|
|  | 121 | shutil.copytree("asap", moddir) | 
|---|
| [1181] | 122 | print "Installing asap  scripts in %s" % bindir | 
|---|
| [1209] | 123 | if moduledir != sysmoduledir: | 
|---|
|  | 124 | import sre | 
|---|
|  | 125 | print "Changing asap startup script to use custom PYTHONPATH" | 
|---|
|  | 126 | inf = file("bin/asap") | 
|---|
|  | 127 | outf = file(os.path.join(bindir,"asap"), "w") | 
|---|
|  | 128 | outline = "export PYTHONPATH=%s" % moduledir | 
|---|
|  | 129 | regx = sre.compile("\*\*PYTHONPATH\*\*") | 
|---|
|  | 130 | for line in inf.readlines(): | 
|---|
|  | 131 | if regx.search(line): | 
|---|
|  | 132 | line = outline | 
|---|
|  | 133 | outf.write(line) | 
|---|
|  | 134 | outf.close() | 
|---|
|  | 135 | os.chmod(os.path.join(bindir,"asap"), 0755) | 
|---|
|  | 136 | else: | 
|---|
|  | 137 | shutil.copy2("bin/asap", bindir) | 
|---|
| [1181] | 138 | shutil.copy2("bin/asap_update_data", bindir) | 
|---|
| [1195] | 139 | if not os.path.exists("asap/data/ephemerides"): | 
|---|
|  | 140 | print "Warning - no data directory present" | 
|---|
|  | 141 | print "Please run asap_update_data after the installation is completed." | 
|---|
| [1163] | 142 | print "Installation completed." | 
|---|
|  | 143 | except OSError, oe: | 
|---|
|  | 144 | print oe | 
|---|