forked from cloudmesh/cloudmesh1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·146 lines (119 loc) · 4.04 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python
"""
Usage:
install -h | --help
install system
install requirements [-u]
install path
Description:
install system
install some important packages that are essential for
cloudmesh instalation. This command has to be called first.
Once you have installed the command more options will be
available.
install requirements [-u]
Installs the requirements in the order as given in the requirements.txt file.
if the -u option is specified each package is also updated.
install path
lists the available sys.path for debugging purposes.
"""
import time
from textwrap import dedent
from pprint import pprint
import os
import getopt
import sys
from cloudmesh_common.util import banner
from cloudmesh_install.util import get_system
def print_help():
deep_commands = ""
try:
from cloudmesh_install.install import install_command
deep_commands = dedent(install_command.__doc__)
except:
deep_commands = ""
documentation = __doc__.split("\n") + deep_commands.split("\n")
print "\n".join(documentation)
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
if (opts == [] and args == []):
banner("ERROR: no parameter defined")
print_help()
sys.exit(1)
except getopt.error, msg:
print msg
banner("for help use --help")
sys.exit(2)
# parse for help
for o, a in opts:
if o in ("-h", "--help"):
print_help()
sys.exit(0)
#
if "help" in args:
print_help()
sys.exit(0)
if "requirements" in args:
if "-u" in args or "--upgrade" in args:
upgrade = "--upgrade"
else:
upgrade = ""
try:
f = open('requirements.txt', 'rU')
for line in f:
line = line.rstrip()
if line.startswith("#"):
print line
else:
banner (line, c="-")
try:
os.system("pip install '{0}' {1}".format(line, upgrade))
except Exception, e:
print e
sys.exit(1)
except Exception, e:
print "ERROR: There is a problem"
print e
# In some linux distributions (Ubuntu, others?)
# fabric does not install properly until the
# preceeding requirements are in place.
# os.system("pip install fabric")
# To prevent errors building API docs, we need a
# cloudmesh.yaml and cloudmesh_server.yaml to exist.
# TODO: Why is this the case? Magic happening in imports?
# http://chrismorgan.info/blog/say-no-to-import-side-effects-in-python.html
os.system("bash -c 'mkdir -m 0700 -p ~/.futuregrid'")
os.system(
"bash -c 'test -f ~/.futuregrid/cloudmesh.yaml || touch ~/.futuregrid/cloudmesh.yaml'")
os.system(
"bash -c 'test -f ~/.futuregrid/cloudmesh_server.yaml || touch ~/.futuregrid/cloudmesh_server.yaml'")
sys.exit(0)
if "path" in args:
banner("sys.path", c="-")
pprint(sys.path)
banner("-")
sys.exit(0)
if "system" in args:
banner("system")
os_system = get_system()
try:
os.system("bin/prepare-%s.sh" % os_system)
except:
print "OS distribution not supported; please see documatation for manual installation instructions."
sys.exit(1)
sys.exit(0)
arguments = ' '.join(args)
banner(arguments)
try:
from cloudmesh_install.install import install_command
install_command(arguments)
except Exception, e:
print "ERROR: Your environment may not be properly configured."
print " Have you run the following command?"
print
print " install system"
print
print e
if __name__ == "__main__":
main()