arvados-cli 0.1.20141010134550 → 0.1.20141014153331
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/arv +182 -63
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4d8052affebd48f1d77d61bd70dba5f93963eb6
|
4
|
+
data.tar.gz: 192d67d32736a74c3e6db81f8dde6cbdf1780b88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe4b9d47027b58979ff8ec74bad832ae3e7c2824ce3a08b315b0db912d72cf1f7b064b2f38975ae6d25bb6b743e45c5bd94ef021c183e9baf770e74e1feace92
|
7
|
+
data.tar.gz: 9811ea9a89dccfa5d544a3bc45c58e86d49d6f64ff2d2ca2589028cbbc359267e1f3153d6631190ad30c6b817590cf8069287b8b0961988757da996f0e274dc4
|
data/bin/arv
CHANGED
@@ -23,6 +23,7 @@ begin
|
|
23
23
|
require 'oj'
|
24
24
|
require 'active_support/inflector'
|
25
25
|
require 'yaml'
|
26
|
+
require 'tempfile'
|
26
27
|
rescue LoadError
|
27
28
|
abort <<-EOS
|
28
29
|
|
@@ -112,10 +113,14 @@ def init_config
|
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
115
|
-
subcommands = %w(keep pipeline tag ws
|
116
|
+
subcommands = %w(create edit keep pipeline tag ws)
|
116
117
|
|
117
118
|
def check_subcommands client, arvados, subcommand, global_opts, remaining_opts
|
118
119
|
case subcommand
|
120
|
+
when 'create'
|
121
|
+
arv_create client, arvados, global_opts, remaining_opts
|
122
|
+
when 'edit'
|
123
|
+
arv_edit client, arvados, global_opts, remaining_opts
|
119
124
|
when 'keep'
|
120
125
|
@sub = remaining_opts.shift
|
121
126
|
if ['get', 'put', 'ls', 'normalize'].index @sub then
|
@@ -146,8 +151,6 @@ def check_subcommands client, arvados, subcommand, global_opts, remaining_opts
|
|
146
151
|
exec `which arv-tag`.strip, *remaining_opts
|
147
152
|
when 'ws'
|
148
153
|
exec `which arv-ws`.strip, *remaining_opts
|
149
|
-
when 'edit'
|
150
|
-
arv_edit client, arvados, global_opts, remaining_opts
|
151
154
|
end
|
152
155
|
end
|
153
156
|
|
@@ -156,6 +159,67 @@ def arv_edit_save_tmp tmp
|
|
156
159
|
puts "Saved contents to " + tmp.path + ".saved"
|
157
160
|
end
|
158
161
|
|
162
|
+
def command_exists?(command)
|
163
|
+
ENV['PATH'].split(':').each {|folder| File.executable?(File.join(folder, command))}
|
164
|
+
end
|
165
|
+
|
166
|
+
def run_editor tmp_file, global_opts
|
167
|
+
need_edit = true
|
168
|
+
while need_edit
|
169
|
+
pid = Process::fork
|
170
|
+
if pid.nil?
|
171
|
+
editor = nil
|
172
|
+
[ENV["VISUAL"], ENV["EDITOR"], "nano", "vi"].each do |e|
|
173
|
+
editor ||= e if e and command_exists? e
|
174
|
+
end
|
175
|
+
if editor.nil?
|
176
|
+
puts "Could not find any editor to use, please set $VISUAL or $EDITOR to your desired editor."
|
177
|
+
exit 1
|
178
|
+
end
|
179
|
+
exec editor, tmp_file.path
|
180
|
+
else
|
181
|
+
Process.wait pid
|
182
|
+
end
|
183
|
+
|
184
|
+
if $?.exitstatus == 0
|
185
|
+
tmp_file.open
|
186
|
+
newcontent = tmp_file.read()
|
187
|
+
|
188
|
+
newobj = {}
|
189
|
+
begin
|
190
|
+
case global_opts[:format]
|
191
|
+
when 'json'
|
192
|
+
newobj = Oj.load(newcontent)
|
193
|
+
when 'yaml'
|
194
|
+
newobj = YAML.load(newcontent)
|
195
|
+
end
|
196
|
+
need_edit = false
|
197
|
+
rescue Exception => e
|
198
|
+
n = 1
|
199
|
+
newcontent.each_line do |line|
|
200
|
+
puts "#{n.to_s.rjust 4} #{line}"
|
201
|
+
n += 1
|
202
|
+
end
|
203
|
+
puts "Parse error! " + e.to_s
|
204
|
+
puts "\nTry again (y/n)? "
|
205
|
+
yn = "X"
|
206
|
+
while not ["y", "Y", "n", "N"].include?(yn)
|
207
|
+
yn = $stdin.read 1
|
208
|
+
end
|
209
|
+
if yn == 'n' or yn == 'N'
|
210
|
+
arv_edit_save_tmp tmp_file
|
211
|
+
abort
|
212
|
+
end
|
213
|
+
end
|
214
|
+
else
|
215
|
+
puts "Editor exited with status #{$?.exitstatus}"
|
216
|
+
exit $?.exitstatus
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
newobj
|
221
|
+
end
|
222
|
+
|
159
223
|
def arv_edit client, arvados, global_opts, remaining_opts
|
160
224
|
uuid = remaining_opts.shift
|
161
225
|
if uuid.nil? or uuid == "-h" or uuid == "--help"
|
@@ -224,60 +288,11 @@ def arv_edit client, arvados, global_opts, remaining_opts
|
|
224
288
|
content = results.to_yaml
|
225
289
|
end
|
226
290
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
tmp.write(content)
|
231
|
-
tmp.close
|
232
|
-
|
233
|
-
need_edit = true
|
234
|
-
|
235
|
-
while need_edit
|
236
|
-
pid = Process::fork
|
237
|
-
if pid.nil?
|
238
|
-
editor ||= ENV["VISUAL"]
|
239
|
-
editor ||= ENV["EDITOR"]
|
240
|
-
editor ||= "nano"
|
241
|
-
exec editor, tmp.path
|
242
|
-
else
|
243
|
-
Process.wait pid
|
244
|
-
end
|
245
|
-
|
246
|
-
if $?.exitstatus == 0
|
247
|
-
tmp.open
|
248
|
-
newcontent = tmp.read()
|
291
|
+
tmp_file = Tempfile.new([uuid, "." + global_opts[:format]])
|
292
|
+
tmp_file.write(content)
|
293
|
+
tmp_file.close
|
249
294
|
|
250
|
-
|
251
|
-
begin
|
252
|
-
case global_opts[:format]
|
253
|
-
when 'json'
|
254
|
-
newobj = Oj.load(newcontent)
|
255
|
-
when 'yaml'
|
256
|
-
newobj = YAML.load(newcontent)
|
257
|
-
end
|
258
|
-
need_edit = false
|
259
|
-
rescue Exception => e
|
260
|
-
puts "Parse error! " + e.to_s
|
261
|
-
n = 1
|
262
|
-
newcontent.each_line do |line|
|
263
|
-
puts "#{n.to_s.rjust 4} #{line}"
|
264
|
-
n += 1
|
265
|
-
end
|
266
|
-
puts "\nTry again (y/n)? "
|
267
|
-
yn = "X"
|
268
|
-
while not ["y", "Y", "n", "N"].include?(yn)
|
269
|
-
yn = $stdin.read 1
|
270
|
-
end
|
271
|
-
if yn == 'n' or yn == 'N'
|
272
|
-
arv_edit_save_tmp tmp
|
273
|
-
abort
|
274
|
-
end
|
275
|
-
end
|
276
|
-
else
|
277
|
-
puts "Editor exited with status #{$?.exitstatus}"
|
278
|
-
exit $?.exitstatus
|
279
|
-
end
|
280
|
-
end
|
295
|
+
newobj = run_editor tmp_file, global_opts
|
281
296
|
|
282
297
|
begin
|
283
298
|
if newobj != results
|
@@ -296,13 +311,14 @@ def arv_edit client, arvados, global_opts, remaining_opts
|
|
296
311
|
puts "Error communicating with server, error was #{e}"
|
297
312
|
puts "Update body was:"
|
298
313
|
puts dumped
|
299
|
-
arv_edit_save_tmp
|
314
|
+
arv_edit_save_tmp tmp_file
|
300
315
|
abort
|
301
316
|
end
|
302
317
|
|
303
318
|
begin
|
304
319
|
results = JSON.parse result.body
|
305
320
|
rescue JSON::ParserError => e
|
321
|
+
arv_edit_save_tmp tmp_file
|
306
322
|
abort "Failed to parse server response:\n" + e.to_s
|
307
323
|
end
|
308
324
|
|
@@ -310,14 +326,114 @@ def arv_edit client, arvados, global_opts, remaining_opts
|
|
310
326
|
puts "Update failed. Server responded #{result.response.status}: #{results['errors']} "
|
311
327
|
puts "Update body was:"
|
312
328
|
puts dumped
|
313
|
-
arv_edit_save_tmp
|
329
|
+
arv_edit_save_tmp tmp_file
|
314
330
|
abort
|
315
331
|
end
|
316
332
|
else
|
317
333
|
puts "Object is unchanged, did not update."
|
318
334
|
end
|
319
335
|
ensure
|
320
|
-
|
336
|
+
tmp_file.close(true)
|
337
|
+
end
|
338
|
+
|
339
|
+
exit 0
|
340
|
+
end
|
341
|
+
|
342
|
+
def arv_create client, arvados, global_opts, remaining_opts
|
343
|
+
types = resource_types(arvados.discovery_document)
|
344
|
+
create_opts = Trollop::options do
|
345
|
+
opt :project_uuid, "Project uuid in which to create the object", :type => :string
|
346
|
+
stop_on resource_types(arvados.discovery_document)
|
347
|
+
end
|
348
|
+
|
349
|
+
object_type = remaining_opts.shift
|
350
|
+
if object_type.nil?
|
351
|
+
abort "Missing resource type, must be one of #{types.join ', '}"
|
352
|
+
end
|
353
|
+
|
354
|
+
rsc = arvados.discovery_document["resources"].keys.select { |k| object_type == k.singularize }
|
355
|
+
if rsc.empty?
|
356
|
+
abort "Could not determine resource type #{object_type}"
|
357
|
+
end
|
358
|
+
rsc = rsc.first
|
359
|
+
|
360
|
+
discovered_params = arvados.discovery_document["resources"][rsc]["methods"]["create"]["parameters"]
|
361
|
+
method_opts = Trollop::options do
|
362
|
+
banner head_banner
|
363
|
+
banner "Usage: arv create [--project-uuid] #{object_type} [create parameters]"
|
364
|
+
banner ""
|
365
|
+
banner "This method supports the following parameters:"
|
366
|
+
banner ""
|
367
|
+
discovered_params.each do |k,v|
|
368
|
+
opts = Hash.new()
|
369
|
+
opts[:type] = v["type"].to_sym if v.include?("type")
|
370
|
+
if [:datetime, :text, :object, :array].index opts[:type]
|
371
|
+
opts[:type] = :string # else trollop bork
|
372
|
+
end
|
373
|
+
opts[:default] = v["default"] if v.include?("default")
|
374
|
+
opts[:default] = v["default"].to_i if opts[:type] == :integer
|
375
|
+
opts[:default] = to_boolean(v["default"]) if opts[:type] == :boolean
|
376
|
+
opts[:required] = true if v.include?("required") and v["required"]
|
377
|
+
description = ''
|
378
|
+
description = ' ' + v["description"] if v.include?("description")
|
379
|
+
opt k.to_sym, description, opts
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
|
384
|
+
newobj = {}
|
385
|
+
if create_opts[:project_uuid]
|
386
|
+
newobj["owner_uuid"] = create_opts[:project_uuid]
|
387
|
+
end
|
388
|
+
|
389
|
+
case global_opts[:format]
|
390
|
+
when 'json'
|
391
|
+
content = Oj.dump(newobj, :indent => 1)
|
392
|
+
when 'yaml'
|
393
|
+
content = newobj.to_yaml
|
394
|
+
end
|
395
|
+
|
396
|
+
tmp_file = Tempfile.new(["", ".#{global_opts[:format]}"])
|
397
|
+
tmp_file.write(content)
|
398
|
+
tmp_file.close
|
399
|
+
|
400
|
+
newobj = run_editor tmp_file, global_opts
|
401
|
+
|
402
|
+
begin
|
403
|
+
api_method = 'arvados.' + rsc + '.create'
|
404
|
+
dumped = Oj.dump(newobj)
|
405
|
+
|
406
|
+
result = client.execute(:api_method => eval(api_method),
|
407
|
+
:parameters => method_opts,
|
408
|
+
:body_object => {object_type => newobj},
|
409
|
+
:authenticated => false,
|
410
|
+
:headers => {
|
411
|
+
authorization: 'OAuth2 '+ENV['ARVADOS_API_TOKEN']
|
412
|
+
})
|
413
|
+
|
414
|
+
begin
|
415
|
+
results = JSON.parse result.body
|
416
|
+
rescue JSON::ParserError => e
|
417
|
+
arv_edit_save_tmp tmp_file
|
418
|
+
abort "Failed to parse server response:\n" + e.to_s
|
419
|
+
end
|
420
|
+
|
421
|
+
if result.response.status != 200
|
422
|
+
puts "Create failed. Server responded #{result.response.status}: #{results['errors']} "
|
423
|
+
puts "Create body was:"
|
424
|
+
puts dumped
|
425
|
+
arv_edit_save_tmp tmp_file
|
426
|
+
abort
|
427
|
+
end
|
428
|
+
|
429
|
+
begin
|
430
|
+
puts "Created object #{results['uuid']}"
|
431
|
+
rescue
|
432
|
+
arv_edit_save_tmp tmp_file
|
433
|
+
abort "Unexpected response:\n#{results}"
|
434
|
+
end
|
435
|
+
ensure
|
436
|
+
tmp_file.close(true)
|
321
437
|
end
|
322
438
|
|
323
439
|
exit 0
|
@@ -361,13 +477,16 @@ def help_resources(option_parser, discovery_document, resource)
|
|
361
477
|
exit 255
|
362
478
|
end
|
363
479
|
|
364
|
-
def
|
480
|
+
def resource_types discovery_document
|
365
481
|
resource_types = Array.new()
|
366
482
|
discovery_document["resources"].each do |k,v|
|
367
483
|
resource_types << k.singularize
|
368
484
|
end
|
485
|
+
resource_types
|
486
|
+
end
|
369
487
|
|
370
|
-
|
488
|
+
def parse_arguments(discovery_document, subcommands)
|
489
|
+
resources_and_subcommands = resource_types(discovery_document) + subcommands
|
371
490
|
|
372
491
|
option_parser = Trollop::Parser.new do
|
373
492
|
version __FILE__
|
@@ -396,7 +515,7 @@ def parse_arguments(discovery_document, subcommands)
|
|
396
515
|
banner "Additional options:"
|
397
516
|
|
398
517
|
conflicts :short, :format
|
399
|
-
stop_on
|
518
|
+
stop_on resources_and_subcommands
|
400
519
|
end
|
401
520
|
|
402
521
|
global_opts = Trollop::with_standard_exception_handling option_parser do
|
@@ -416,7 +535,7 @@ def parse_arguments(discovery_document, subcommands)
|
|
416
535
|
resource = ARGV.shift
|
417
536
|
|
418
537
|
if not subcommands.include? resource
|
419
|
-
if not
|
538
|
+
if not resources_and_subcommands.include?(resource)
|
420
539
|
puts "Resource or subcommand '#{resource}' is not recognized.\n\n" if !resource.nil?
|
421
540
|
help_resources(option_parser, discovery_document, resource)
|
422
541
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arvados-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.20141014153331
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arvados Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: arvados
|
@@ -178,7 +178,7 @@ dependencies:
|
|
178
178
|
- - "<"
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: 1.0.0
|
181
|
-
description: Arvados command line tools, git commit
|
181
|
+
description: Arvados command line tools, git commit debedb222cfea4bfc4519032cad8475858e04034
|
182
182
|
email: gem-dev@curoverse.com
|
183
183
|
executables:
|
184
184
|
- arv
|