ubalo 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/ubalo +7 -11
  2. data/lib/ubalo.rb +44 -14
  3. metadata +10 -10
data/bin/ubalo CHANGED
@@ -381,17 +381,15 @@ command :clear_keys do |c|
381
381
  end
382
382
  end
383
383
 
384
- desc 'Modify a pod'
385
- arg_name '<pod name>'
384
+ desc 'Edit your environment'
386
385
  command :edit do |c|
387
386
  c.action do |global_options,options,args|
388
- pod_name = normalize_pod_name(args.shift)
389
- ubalo.ssh(pod_name)
387
+ username = args.first || local_username
388
+ ubalo.ssh(username)
390
389
  end
391
390
  end
392
391
 
393
- desc 'Copy files to or from a pod environ'
394
- arg_name '<pod name>'
392
+ desc 'Copy files to or from your environment'
395
393
  command :cp do |c|
396
394
  c.desc 'copy recursively'
397
395
  c.switch :r
@@ -400,13 +398,11 @@ command :cp do |c|
400
398
  opts = ""
401
399
  opts << " -r" if options.r
402
400
 
403
- environ = nil
404
- scp_args = args.join(" ").gsub(/[\w-]+(?=:)/) do |pod_name|
405
- ssh_path, environ = ubalo.ssh_path(normalize_pod_name(pod_name))
406
- "#{ssh_path}"
401
+ scp_args = args.join(" ").gsub(/ubalo(?=:)/) do
402
+ ubalo.ssh_path
407
403
  end
408
404
 
409
- ubalo.scp(environ, opts, scp_args)
405
+ ubalo.scp(local_username, opts, scp_args)
410
406
  end
411
407
  end
412
408
 
data/lib/ubalo.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'time'
1
2
  require 'rest-client'
2
3
  require 'json'
3
4
  require 'open3'
@@ -52,7 +53,7 @@ end
52
53
  class Ubalo
53
54
  class << self
54
55
  def format_task task
55
- "#{task['label']} #{"(#{task['state']})".lfit(10)} - #{task['pod_name']} (#{task['submitted_at_in_words']} ago)"
56
+ "#{task['label']} #{"(#{task['state']})".lfit(10)} - #{task['pod_name']} (#{time_ago_in_words task['submitted_at']})"
56
57
  end
57
58
 
58
59
  def format_pod pod, with_username
@@ -63,6 +64,30 @@ class Ubalo
63
64
  end
64
65
  " #{name} - #{pod['language']}"
65
66
  end
67
+
68
+ private
69
+ def pluralize count, word
70
+ if count == 1
71
+ "#{count} #{word}"
72
+ else
73
+ "#{count} #{word}s"
74
+ end
75
+ end
76
+
77
+ def time_ago_in_words time
78
+ seconds = Time.now - Time.parse(time)
79
+ case
80
+ when seconds < 60
81
+ "#{pluralize seconds.floor, "second"} ago"
82
+ when seconds/60 < 60
83
+ "#{pluralize (seconds/60).floor, "minute"} ago"
84
+ when seconds/60/60 < 24
85
+ "#{pluralize (seconds/60/60).floor, "hour"} ago"
86
+ else
87
+ "#{pluralize (seconds/60/60/24).floor, "day"} ago"
88
+ end
89
+ end
90
+
66
91
  end
67
92
 
68
93
  attr_reader :base_url
@@ -149,29 +174,28 @@ class Ubalo
149
174
  post(:upload_code, {:pod_name => name, :code => code})
150
175
  end
151
176
 
152
- def ssh_path(name)
153
- h = get(:ssh_path, :pod_name => name)
154
- [h['ssh_path'], h['environ_fullname']]
177
+ def ssh_path
178
+ h = get(:ssh_path)
179
+ h.fetch('ssh_path')
155
180
  end
156
181
 
157
182
  def pods
158
183
  get(:pods)
159
184
  end
160
185
 
161
- def ssh(pod_name)
162
- ssh_path, environ = ssh_path(pod_name)
163
- puts "Opening an ssh connection to edit the '#{environ}' environment for the '#{pod_name}' pod."
164
- ssh_command = "ssh -o SendEnv='UBALO_ENVIRON TERM' -tq #{ssh_path}"
165
- Process.spawn({'UBALO_ENVIRON' => environ}, ssh_command)
186
+ def ssh(username)
187
+ puts "Opening an ssh connection to edit the environment belonging to #{username}."
188
+ ssh_command = "ssh -o SendEnv='UBALO_DISTRIBUTION_OWNER TERM' -tq #{ssh_path}"
189
+ Process.spawn({'UBALO_DISTRIBUTION_OWNER' => username}, ssh_command)
166
190
  pid, status = Process.wait2
167
191
  unless status.success?
168
192
  abort "Error running ssh"
169
193
  end
170
194
  end
171
195
 
172
- def scp(environ, opts, args)
173
- scp_command = "scp -o SendEnv=UBALO_ENVIRON #{opts} #{args}"
174
- Process.spawn({'UBALO_ENVIRON' => environ}, scp_command)
196
+ def scp(username, opts, args)
197
+ scp_command = "scp -o SendEnv=UBALO_DISTRIBUTION_OWNER #{opts} #{args}"
198
+ Process.spawn({'UBALO_DISTRIBUTION_OWNER' => username}, scp_command)
175
199
  pid, status = Process.wait2
176
200
  unless status.success?
177
201
  abort "Error running cp"
@@ -190,7 +214,13 @@ class Ubalo
190
214
  puts " pod: #{result['pod_name']}"
191
215
  puts " arg: #{result['arg']}"
192
216
  puts " state: #{result['state']}"
193
- puts "status: #{result['status']}" if result['status']
217
+ case result['exit_type']
218
+ when 'exited'
219
+ puts "status: #{result['exit_result']}"
220
+ when 'terminated'
221
+ puts "terminated with signal: #{result['exit_result']}"
222
+ end
223
+
194
224
  if result['stdout']
195
225
  puts "stdout:"
196
226
  puts result['stdout'].indent
@@ -221,7 +251,7 @@ class Ubalo
221
251
  def push pod_url, contents
222
252
  url_post("#{pod_url}/api/push", :contents => contents)
223
253
  end
224
-
254
+
225
255
  def pull pod_url
226
256
  url_get("#{pod_url}/api/pull")['contents']
227
257
  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.15
4
+ version: 0.0.16
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: 2011-12-16 00:00:00.000000000Z
12
+ date: 2012-01-03 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gli
16
- requirement: &70291514610660 !ruby/object:Gem::Requirement
16
+ requirement: &70254281845560 !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: *70291514610660
24
+ version_requirements: *70254281845560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: highline
27
- requirement: &70291514610200 !ruby/object:Gem::Requirement
27
+ requirement: &70254281845120 !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: *70291514610200
35
+ version_requirements: *70254281845120
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: json
38
- requirement: &70291514609780 !ruby/object:Gem::Requirement
38
+ requirement: &70254281844640 !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: *70291514609780
46
+ version_requirements: *70254281844640
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rest-client
49
- requirement: &70291514609280 !ruby/object:Gem::Requirement
49
+ requirement: &70254281844000 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 1.6.3
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70291514609280
57
+ version_requirements: *70254281844000
58
58
  description: CLI and API client for Ubalo
59
59
  email: dev@ubalo.com
60
60
  executables: