manifests-vmc-plugin 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -128,6 +128,29 @@ VMC.Plugin(VMC::App) do
128
128
  puts "" unless simple_output?
129
129
  end
130
130
 
131
- push.call unless all_pushed
131
+ unless all_pushed
132
+ begin
133
+ push.call
134
+ ensure
135
+ meta = {
136
+ "name" => passed_value(:name) || args.first,
137
+ "framework" => passed_value(:framework),
138
+ "runtime" => passed_value(:runtime),
139
+ "memory" => passed_value(:memory),
140
+ "instances" => passed_value(:instances).to_i,
141
+ "url" => passed_value(:url)
142
+ }
143
+
144
+ unless manifest_file || meta.any? { |k, v| v.nil? }
145
+ puts ""
146
+
147
+ if ask("Save configuration?", :default => false)
148
+ File.open("manifest.yml", "w") do |io|
149
+ YAML.dump({"applications" => {options[:path] => meta}}, io)
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
132
155
  end
133
156
  end
@@ -1,3 +1,3 @@
1
1
  module VMCManifests
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -61,7 +61,7 @@ module VMCManifests
61
61
 
62
62
  # merge the manifest at `path' into the `child'
63
63
  def merge_parent(child, path)
64
- file = File.expand_path("../" + path, manifest_file)
64
+ file = File.expand_path(path, File.dirname(manifest_file))
65
65
  merge_manifest(child, build_manifest(file))
66
66
  end
67
67
 
@@ -196,7 +196,7 @@ module VMCManifests
196
196
  info["framework"] = info["framework"]["name"]
197
197
  end
198
198
 
199
- app = File.expand_path("../" + path, manifest_file)
199
+ app = File.expand_path(path, File.dirname(manifest_file))
200
200
  if find_path == app
201
201
  return toplevel_attributes.merge info
202
202
  end
@@ -225,7 +225,7 @@ module VMCManifests
225
225
  else
226
226
  # all apps in the manifest
227
227
  ordered_by_deps(all_apps).each do |path|
228
- app = File.expand_path("../" + path, manifest_file)
228
+ app = File.expand_path(path, File.dirname(manifest_file))
229
229
  info = app_info(app)
230
230
 
231
231
  with_app(app, info) do
@@ -268,22 +268,24 @@ module VMCManifests
268
268
  # sort applications in dependency order
269
269
  # e.g. if A depends on B, B will be listed before A
270
270
  def ordered_by_deps(apps, abspaths = nil, processed = Set[])
271
+ mandir = File.dirname(manifest_file)
272
+
271
273
  unless abspaths
272
274
  abspaths = {}
273
275
  apps.each do |p, i|
274
- ep = File.expand_path("../" + p, manifest_file)
276
+ ep = File.expand_path(p, mandir)
275
277
  abspaths[ep] = i
276
278
  end
277
279
  end
278
280
 
279
281
  ordered = []
280
282
  apps.each do |path, info|
281
- epath = File.expand_path("../" + path, manifest_file)
283
+ epath = File.expand_path(path, mandir)
282
284
 
283
285
  if deps = info["depends-on"]
284
286
  dep_apps = {}
285
287
  deps.each do |dep|
286
- edep = File.expand_path("../" + dep, manifest_file)
288
+ edep = File.expand_path(dep, mandir)
287
289
 
288
290
  raise "Circular dependency detected." if processed.include? edep
289
291
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manifests-vmc-plugin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-04 00:00:00 Z
18
+ date: 2012-06-06 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description:
@@ -30,7 +30,6 @@ extra_rdoc_files: []
30
30
  files:
31
31
  - Rakefile
32
32
  - lib/manifests-vmc-plugin/errors.rb
33
- - lib/manifests-vmc-plugin/manifest.rb
34
33
  - lib/manifests-vmc-plugin/plugin.rb
35
34
  - lib/manifests-vmc-plugin/version.rb
36
35
  - lib/manifests-vmc-plugin.rb
@@ -1,222 +0,0 @@
1
- require "yaml"
2
- require "set"
3
-
4
- module VMCManifests
5
- class Manifest
6
- def initialize(file)
7
- @file = file
8
- end
9
-
10
- def body
11
- @body ||= load
12
- end
13
-
14
- # load and resolve a given manifest file
15
- def load
16
- manifest = build_manifest(@file)
17
- resolve_manifest(manifest)
18
- manifest
19
- end
20
-
21
- def save(dest = @file)
22
- File.open(save_to, "w") do |io|
23
- YAML.dump(@body, io)
24
- end
25
- end
26
-
27
- MANIFEST_META = ["applications", "properties"]
28
-
29
- def toplevel_attributes
30
- info =
31
- body.reject do |k, _|
32
- MANIFEST_META.include? k
33
- end
34
-
35
- if info["framework"].is_a?(Hash)
36
- info["framework"] = info["framework"]["name"]
37
- end
38
-
39
- info
40
- end
41
-
42
- def app_info(find_path)
43
- return unless body["applications"]
44
-
45
- body["applications"].each do |path, info|
46
- if info["framework"].is_a?(Hash)
47
- info["framework"] = info["framework"]["name"]
48
- end
49
-
50
- app = File.expand_path("../" + path, manifest_file)
51
- if find_path == app
52
- return toplevel_attributes.merge info
53
- end
54
- end
55
-
56
- nil
57
- end
58
-
59
- # sort applications in dependency order
60
- # e.g. if A depends on B, B will be listed before A
61
- def applications(
62
- apps = body["applications"],
63
- abspaths = nil,
64
- processed = Set[])
65
- unless abspaths
66
- abspaths = {}
67
- apps.each do |p, i|
68
- ep = File.expand_path("../" + p, manifest_file)
69
- abspaths[ep] = i
70
- end
71
- end
72
-
73
- ordered = []
74
- apps.each do |path, info|
75
- epath = File.expand_path("../" + path, manifest_file)
76
-
77
- if deps = info["depends-on"]
78
- dep_apps = {}
79
- deps.each do |dep|
80
- edep = File.expand_path("../" + dep, manifest_file)
81
-
82
- raise CircularDependency.new(edep) if processed.include?(edep)
83
-
84
- dep_apps[dep] = abspaths[edep]
85
- end
86
-
87
- processed.add(epath)
88
-
89
- ordered += applications(dep_apps, abspaths, processed)
90
- ordered << path
91
- elsif not processed.include? epath
92
- ordered << path
93
- processed.add(epath)
94
- end
95
- end
96
-
97
- ordered
98
- end
99
-
100
- private
101
-
102
- # parse a manifest and merge with its inherited manifests
103
- def build_manifest(file)
104
- manifest = YAML.load_file file
105
-
106
- Array(manifest["inherit"]).each do |p|
107
- manifest = merge_parent(manifest, p)
108
- end
109
-
110
- manifest
111
- end
112
-
113
- # merge the manifest at `path' into the `child'
114
- def merge_parent(child, path)
115
- file = File.expand_path("../" + path, @file)
116
- deep_merge(child, build_manifest(file))
117
- end
118
-
119
- # resolve symbols in a manifest
120
- def resolve_manifest(manifest)
121
- if apps = manifest["applications"]
122
- apps.each_value do |v|
123
- resolve_lexically(v, [manifest])
124
- end
125
- end
126
-
127
- resolve_lexically(manifest, [manifest])
128
-
129
- nil
130
- end
131
-
132
- # resolve symbols, with hashes introducing new lexical symbols
133
- def resolve_lexically(val, ctx)
134
- case val
135
- when Hash
136
- val.each_value do |v|
137
- resolve_lexically(v, [val] + ctx)
138
- end
139
- when Array
140
- val.each do |v|
141
- resolve_lexically(v, ctx)
142
- end
143
- when String
144
- val.gsub!(/\$\{([[:alnum:]\-]+)\}/) do
145
- resolve_symbol($1, ctx)
146
- end
147
- end
148
-
149
- nil
150
- end
151
-
152
- # resolve a symbol to its value, and then resolve that value
153
- def resolve_symbol(sym, ctx)
154
- case sym
155
- when "target-url"
156
- target_url(ctx)
157
-
158
- when "target-base"
159
- target_url(ctx).sub(/^[^\.]+\./, "")
160
-
161
- when "random-word"
162
- "%04x" % [rand(0x0100000)]
163
-
164
- else
165
- found = find_symbol(sym, ctx)
166
-
167
- if found
168
- resolve_lexically(found, ctx)
169
- found
170
- else
171
- raise UnknownSymbol.new(sym)
172
- end
173
- end
174
- end
175
-
176
- # get the target url from either the manifest or the current client
177
- def target_url(ctx = [])
178
- find_symbol("target", ctx) || client_target
179
- end
180
-
181
- # search for a symbol introduced in the lexical context
182
- def find_symbol(sym, ctx)
183
- ctx.each do |h|
184
- if val = resolve_in(h, sym)
185
- return val
186
- end
187
- end
188
-
189
- nil
190
- end
191
-
192
- # find a value, searching in explicit properties first
193
- def resolve_in(hash, *where)
194
- find_in_hash(hash, ["properties"] + where) ||
195
- find_in_hash(hash, where)
196
- end
197
-
198
- # helper for following a path of values in a hash
199
- def find_in_hash(hash, where)
200
- what = hash
201
- where.each do |x|
202
- return nil unless what.is_a?(Hash)
203
- what = what[x]
204
- end
205
-
206
- what
207
- end
208
-
209
- # deep hash merge
210
- def deep_merge(child, parent)
211
- merge = proc do |_, old, new|
212
- if new.is_a?(Hash) and old.is_a?(Hash)
213
- old.merge(new, &merge)
214
- else
215
- new
216
- end
217
- end
218
-
219
- parent.merge(child, &merge)
220
- end
221
- end
222
- end