ubalo 0.0.28 → 0.0.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/ubalo +6 -51
  2. data/lib/ubalo.rb +47 -77
  3. data/lib/ubalo/version.rb +1 -1
  4. metadata +12 -12
data/bin/ubalo CHANGED
@@ -85,24 +85,11 @@ end
85
85
  desc 'Display a list of available pods'
86
86
  command :pods do |c|
87
87
  c.action do |global_options,options,args|
88
- response = ubalo.pods
89
-
90
- puts "your pods:"
91
- your_pods = response.fetch('your_pods')
92
- if your_pods.empty?
93
- puts " (none)"
88
+ pods = ubalo.pods
89
+ if pods.empty?
90
+ $stderr.puts "You do not currently have any pods."
94
91
  else
95
- your_pods.each do |pod|
96
- puts Ubalo.format_pod(pod)
97
- end
98
- end
99
-
100
- puts "other pods:"
101
- other_pods = response.fetch('other_pods')
102
- if other_pods.empty?
103
- puts " (none)"
104
- else
105
- other_pods.each do |pod|
92
+ pods.each do |pod|
106
93
  puts Ubalo.format_pod(pod)
107
94
  end
108
95
  end
@@ -248,6 +235,8 @@ desc 'Push files to Ubalo'
248
235
  command :push do |c|
249
236
  c.action do |global_options,options,args|
250
237
  pod_url = local_config.fetch('pod_url')
238
+ pod = ubalo.create_or_update(pod_url)
239
+
251
240
  ubalo.push_files(pod_url)
252
241
  end
253
242
  end
@@ -276,40 +265,6 @@ command :login do |c|
276
265
  end
277
266
  end
278
267
 
279
- desc 'Remove saved username and password'
280
- command :logout do |c|
281
- c.action do |global_options,options,args|
282
- Ubalo.write_config(ubalo.base_url => nil)
283
- puts "Access details deleted."
284
- end
285
- end
286
-
287
- desc 'Publish a pod'
288
- arg_name '<pod name>'
289
- command :publish do |c|
290
- c.action do |global_options,options,args|
291
- pod_name = normalize_pod_name(args.shift)
292
-
293
- $stderr.print "Publishing #{pod_name}..."
294
- response = ubalo.publish(pod_name)
295
- $stderr.puts " done."
296
- $stderr.puts "Your pod is now available at #{response.fetch('url')}."
297
- end
298
- end
299
-
300
- desc 'Unpublish a pod'
301
- arg_name '<pod name>'
302
- command :unpublish do |c|
303
- c.action do |global_options,options,args|
304
- pod_name = normalize_pod_name(args.shift)
305
-
306
- $stderr.print "Unpublishing #{pod_name}..."
307
- response = ubalo.unpublish(pod_name)
308
- $stderr.puts " done."
309
- $stderr.puts "Your pod is now private."
310
- end
311
- end
312
-
313
268
  def unauthorized_command?(command)
314
269
  command && [:login, :help].include?(command.name)
315
270
  end
data/lib/ubalo.rb CHANGED
@@ -1,48 +1,20 @@
1
+ require 'fileutils'
1
2
  require 'time'
2
3
  require 'rest-client'
3
4
  require 'json'
4
- require 'open3'
5
5
  require 'pp'
6
6
 
7
7
  require 'zlib'
8
8
  require 'archive/tar/minitar'
9
9
  include Archive::Tar
10
10
 
11
- class String
12
- def lfit max_length
13
- if length - 3 <= max_length
14
- ljust(max_length)
15
- else
16
- "#{self[0,max_length-3]}..."
17
- end
18
- end
19
-
20
- def rfit max_length
21
- if length - 3 <= max_length
22
- rjust(max_length)
23
- else
24
- "#{self[0,max_length-3]}..."
25
- end
26
- end
27
-
28
- def indent amount=2
29
- each_line.map do |l|
11
+ def indent str, amount=2
12
+ if str
13
+ str.each_line.map do |l|
30
14
  " "*amount + l
31
15
  end.join
32
- end
33
- end
34
-
35
- class NilClass
36
- def lfit max_length
37
- "".lfit(max_length)
38
- end
39
-
40
- def rfit max_length
41
- "".rfit(max_length)
42
- end
43
-
44
- def indent amount
45
- "".indent(amount)
16
+ else
17
+ ""
46
18
  end
47
19
  end
48
20
 
@@ -73,10 +45,6 @@ class Ubalo
73
45
  end
74
46
 
75
47
  class << self
76
- def tgz_filename
77
- "ubalo-files.tar.gz"
78
- end
79
-
80
48
  def make_tgz file_list, tgz_name
81
49
  tgz = Zlib::GzipWriter.new(File.open(tgz_name, 'wb'))
82
50
  Minitar.pack(file_list, tgz)
@@ -103,16 +71,16 @@ class Ubalo
103
71
  end
104
72
  else
105
73
  puts "#{name}: (#{content_type})"
106
- puts data.indent
74
+ puts indent(data)
107
75
  end
108
76
  end
109
77
 
110
78
  def format_task task
111
- "#{task['label']} #{"(#{task['state']})".lfit(10)} - #{task['pod_name']} (#{time_ago_in_words task['submitted_at']})"
79
+ "#{task['label']} (#{task['state']}) - #{task['pod_name']} (#{time_ago_in_words task['submitted_at']})"
112
80
  end
113
81
 
114
82
  def format_pod pod
115
- " #{pod.fetch('fullname')}"
83
+ "#{pod.fetch('fullname')} (updated #{time_ago_in_words pod.fetch('updated_at')})"
116
84
  end
117
85
 
118
86
  private
@@ -203,23 +171,26 @@ class Ubalo
203
171
  post("#{base_url}/pods/#{pod_name}/tasks", params)
204
172
  end
205
173
 
206
- def wait_task(label, silent=false)
174
+ def poll_on(message)
207
175
  600.times do
208
- h = check_task(label)
209
- if h['state'] == 'exited'
210
- unless silent
211
- $stderr.puts " done."
212
- end
213
- return h
214
- end
215
- unless silent
216
- $stderr.print '.'
217
- $stderr.flush
176
+ if result = yield
177
+ $stderr.puts " done."
178
+ return result
218
179
  end
180
+ $stderr.print '.'
181
+ $stderr.flush
219
182
  sleep 0.5
220
183
  end
184
+
221
185
  $stderr.puts
222
- raise "timed-out waiting for task #{label}"
186
+ raise "timed-out polling on #{message}"
187
+ end
188
+
189
+ def wait_task(label)
190
+ poll_on("task #{label}") do
191
+ task = check_task(label)
192
+ task if task['state'] == 'exited'
193
+ end
223
194
  end
224
195
 
225
196
  def clone(pod_name)
@@ -246,12 +217,12 @@ class Ubalo
246
217
 
247
218
  if stdout = container_process['stdout'] and stdout.length > 0
248
219
  puts "stdout:"
249
- puts stdout.indent
220
+ puts indent(stdout)
250
221
  end
251
222
 
252
223
  if stderr = container_process['stderr'] and stderr.length > 0
253
224
  puts "stderr:"
254
- puts stderr.indent
225
+ puts indent(stderr)
255
226
  end
256
227
  end
257
228
 
@@ -294,7 +265,7 @@ class Ubalo
294
265
  ignore_patterns = []
295
266
  end
296
267
 
297
- ignore_patterns += %w{. .. .ubalo ubalo-files.tar.gz}
268
+ ignore_patterns += %w{. .. .ubalo}
298
269
 
299
270
  filenames = []
300
271
  Dir.glob('{.**,**}').each do |path|
@@ -303,40 +274,39 @@ class Ubalo
303
274
  filenames << path
304
275
  end
305
276
 
306
- begin
307
- Ubalo.make_tgz(filenames, Ubalo.tgz_filename)
308
- upload_tgz(pod_url, Ubalo.tgz_filename)
309
- ensure
310
- FileUtils.rm_f(Ubalo.tgz_filename)
277
+ Dir.mktmpdir do |dir|
278
+ tar_path = File.join(dir, "files.tar.gz")
279
+ Ubalo.make_tgz(filenames, tar_path)
280
+ upload_tgz(pod_url, tar_path)
281
+ end
282
+
283
+ print "Waiting on pod compilation.."
284
+ poll_on("compilation of pod at #{pod_url}") do
285
+ pod = get(pod_url)
286
+ pod if pod['state'] == 'compiled'
311
287
  end
312
288
  end
313
289
 
314
290
  def retrieve_files(destination_path, files_url)
315
- # First retrieve the S3 URL.
316
- RestClient.get(files_url) do |response|
317
- if response.code == 200
318
- File.open(File.join(destination_path, Ubalo.tgz_filename), "wb") do |f|
319
- f.write response
291
+ Dir.mktmpdir do |dir|
292
+ tar_path = File.join(dir, "files.tar.gz")
293
+ RestClient.get(files_url) do |response|
294
+ if response.code == 200
295
+ File.open(tar_path, "wb") do |f|
296
+ f.write response
297
+ end
298
+ Ubalo.extract_tgz(destination_path, tar_path)
299
+ else
300
+ raise UbaloMessage, "failed to download pod files"
320
301
  end
321
- Ubalo.extract_tgz(destination_path, Ubalo.tgz_filename)
322
- else
323
- raise UbaloMessage, "failed to download pod files"
324
302
  end
325
303
  end
326
304
  end
327
305
 
328
- def publish pod_name
329
- post("#{base_url}/pods/#{pod_name}/publish")
330
- end
331
-
332
306
  def delete_pod pod_name
333
307
  delete("#{base_url}/pods/#{pod_name}")
334
308
  end
335
309
 
336
- def unpublish pod_name
337
- post("#{base_url}/pods/#{pod_name}/unpublish")
338
- end
339
-
340
310
  private
341
311
 
342
312
  def add_headers headers
data/lib/ubalo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class Ubalo
2
2
  unless const_defined?('VERSION')
3
- VERSION = "0.0.28"
3
+ VERSION = "0.0.29"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ubalo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.28
4
+ version: 0.0.29
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-28 00:00:00.000000000 Z
12
+ date: 2012-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gli
16
- requirement: &70105707914620 !ruby/object:Gem::Requirement
16
+ requirement: &70258354451120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70105707914620
24
+ version_requirements: *70258354451120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: highline
27
- requirement: &70105707914160 !ruby/object:Gem::Requirement
27
+ requirement: &70258354448760 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70105707914160
35
+ version_requirements: *70258354448760
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: json
38
- requirement: &70105707827700 !ruby/object:Gem::Requirement
38
+ requirement: &70258354448020 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70105707827700
46
+ version_requirements: *70258354448020
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rest-client
49
- requirement: &70105707826560 !ruby/object:Gem::Requirement
49
+ requirement: &70258354445900 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.3
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70105707826560
57
+ version_requirements: *70258354445900
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: archive-tar-minitar
60
- requirement: &70105707825660 !ruby/object:Gem::Requirement
60
+ requirement: &70258354443860 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70105707825660
68
+ version_requirements: *70258354443860
69
69
  description: CLI and API client for Ubalo
70
70
  email: dev@ubalo.com
71
71
  executables: