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(): |
---|
10 | print """Usage: |
---|
11 | ./install [-p <prefix for asap binary>] |
---|
12 | [-m <where to install python module>] |
---|
13 | [-h] this message |
---|
14 | """ |
---|
15 | |
---|
16 | try: |
---|
17 | opts, args = getopt.getopt(sys.argv[1:], "p:m:h", |
---|
18 | ["exec-prefix=", "module-dir=", "help"]) |
---|
19 | |
---|
20 | except getopt.GetoptError: |
---|
21 | usage() |
---|
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) |
---|
43 | v = os.path.expandvars(v) |
---|
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) |
---|
55 | if matplotlib.__version__.split(".")[1] < 87: |
---|
56 | print "Warning: matplotlib version < 0.87." \ |
---|
57 | "This might cause errors. Please upgrade." |
---|
58 | |
---|
59 | try: |
---|
60 | import matplotlib.backends.backend_tkagg |
---|
61 | except ImportError: |
---|
62 | print "Matplotlib doesn't have Tk support" |
---|
63 | sys.exit(1) |
---|
64 | try: |
---|
65 | import numpy |
---|
66 | except ImportError: |
---|
67 | try: |
---|
68 | import numarray |
---|
69 | except ImportError: |
---|
70 | print "You need to have either 'numpy' or 'numarray' installed." |
---|
71 | sys.exit(1) |
---|
72 | try: |
---|
73 | import IPython |
---|
74 | except ImportError: |
---|
75 | print "IPython should be installed." |
---|
76 | sys.exit(1) |
---|
77 | |
---|
78 | print "All required modules were found." |
---|
79 | moddir = os.path.join(moduledir, "asap") |
---|
80 | bindir = os.path.join(execprefix, "bin") |
---|
81 | try: |
---|
82 | if os.path.exists(moddir): |
---|
83 | print "Found previous installation of ASAP. Removing..." |
---|
84 | shutil.rmtree(moddir) |
---|
85 | print "Installing asap module in %s" % moddir |
---|
86 | shutil.copytree("asap", moddir) |
---|
87 | print "Installing asap startup script in %s" % bindir |
---|
88 | shutil.copy2("bin/asap", bindir) |
---|
89 | shutil.copytree("data", os.path.join(moddir,"data")) |
---|
90 | print "Installation completed." |
---|
91 | except OSError, oe: |
---|
92 | print oe |
---|