-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder
executable file
·170 lines (132 loc) · 5.33 KB
/
builder
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/python
import argparse
from armonic.client.smart import Provide, smart_call
from armonic.utils import OsTypeAll
import armonic.common
import readline
import logging
import aeolus.builder
import aeolus.utils
import aeolus.common
import json
logger = logging.getLogger("aeolus." + __name__)
logging.getLogger("armonic").setLevel(logging.WARNING)
def user_input_choose_amongst(choices, prefix=''):
"""Ask the user if he confirm the msg question.
:rtype: True if user confirm, False if not"""
while True:
for i, c in enumerate(choices) :
print " %s%d) %s" % (prefix, i, c)
readline.set_startup_hook(lambda: readline.insert_text("0"))
answer = raw_input("%sChoice [0-%d]: " % (prefix, len(choices)-1))
readline.set_startup_hook()
try:
return choices[int(answer)]
except Exception as e:
print e
print "%sInvalid choice. Do it again!" % (prefix)
parser = argparse.ArgumentParser(prog='armonic-aeolus')
parser.add_argument('--os-type', choices=['mbs', 'debian', 'arch', 'any'], default=None, help="Manually specify an OsType. This is just used when no-remote is also set. If not set, the current OsType is used.")
parser.add_argument('--lifecycle-dir', '-l', type=str, action='append',
help="A lifecycle directory")
parser.add_argument('--lifecycle-repo', '-L', type=str, action='append',
help="A lifecycle repository")
parser.add_argument('--xpath', '-x', dest='xpath', type=str, default="//*",
help='A provide Xpath. If not specified, "//*" is used.')
parser.add_argument('-w', '--workspace', type=str, required=True)
parser.add_argument('--verbose', '-v', action='store_true', help="Verbose")
args = parser.parse_args()
if args.verbose:
logger.setLevel(logging.DEBUG)
directory_output = args.workspace
import armonic.serialize
import armonic.common
armonic.common.load_default_lifecycles()
if args.lifecycle_dir is not None:
for l in args.lifecycle_dir:
armonic.common.load_lifecycle(l)
if args.lifecycle_repo is not None:
for l in args.lifecycle_repo:
armonic.common.load_lifecycle_repository(l)
class MyProvide(Provide):
def on_manage(self, data):
self.manage = True
def do_validation(self):
return False
def do_lfm(self):
self.lfm = armonic.serialize.Serialize(OsTypeAll())
self.lfm_host = "all"
return False
def on_lfm(self, data):
pass
def call(provide):
bindings = []
initial = None
specialisation = []
multiplicity = {}
generator = smart_call(provide)
data = None
while True:
try:
provide, step, args = generator.send(data)
if isinstance(args, Exception):
raise args
data = None
except StopIteration:
break
if step == "multiplicity":
require = args
while True:
answer = raw_input("How many time to call %s? " % require.skel.provide_xpath)
try:
answer = int(answer)
break
except Exception as e:
print e
print provide.depth, "Invalid choice. Do it again!"
require.nargs = answer
if require.skel.type == 'external':
data = [None]
else:
data = 1
if step == "done":
if not provide.has_requirer():
initial = provide
# We get the name of the lifecycle which will be used as component name
p = provide.lfm.uri("//" + provide.xpath, relative=True, resource="provide")
for r in provide.remotes:
nargs = 1
try:
nargs = r.nargs
except AttributeError:
pass
binding = aeolus.builder.Binding(
aeolus.utils.get_provide_xpath(r[0].xpath),
r[0].provide.require.type,
r[0].provide.xpath,
nargs)
bindings.append(binding)
logger.info("Append binding:")
logger.info(binding)
specialisation.append((provide.generic_xpath, provide.xpath))
# To Create a section multiplicity.
#
# For each provide, and for each remote require of this
# provide, we get its xpath and the xpath of required
# provide.
#
# The multiplicicty section is a dict where keys are the
# xpath of a require.
# At each key is associated the xpath of the required provide.
for requires in provide.remotes:
xpath = requires.skel.xpath
multiplicity[xpath] = None
for r in requires:
multiplicity[xpath] = r.provide.xpath
if step == "specialize":
print "Please specialize xpath %s" % provide.generic_xpath
data = user_input_choose_amongst([a['xpath'] for a in args])
return (initial, bindings, specialisation, multiplicity)
provide = MyProvide(args.xpath)
Initial, Bindings, Specialisation, Multiplicity = call(provide)
aeolus.builder.generate_files(Initial, Bindings, Specialisation, Multiplicity, directory_output)