arvados-cli 0.1.20140110131136 → 0.1.20140110141515

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/arv-tag +232 -0
  3. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4b8da101b279224b702afe71e61f75db5afd4a8
4
- data.tar.gz: ffd6878e141e8c07129f15a682ed1876b8efba02
3
+ metadata.gz: f99e2294feefa5fd080e394da38de29f8393e9f8
4
+ data.tar.gz: ec1101e0bb738a3710ba4ca708e8030773c6591c
5
5
  SHA512:
6
- metadata.gz: be0a46d1631822b8edb04211014188fb8c0194fede50ff49078812c4360fccf910452b2c86057ba5030f6dc3dd0ed349b74cc9725f194396da90b95eaea363ce
7
- data.tar.gz: 9134c21d08a168363107a25f5a8cf1c3ea537cd707895d311ffcc65ebb66dc0b93363ce715dac814a5f19d6e454c468972675af903a0d5429afe6adc6481db43
6
+ metadata.gz: c045f37afa9245dec4c761b7d7ba5380ea68cd2a48f2cf4f8e59f2ac3a2fb529ce8f7cfe248b69bbf89ae74db0fe533dce284f50ea67aa6a09985b7efd2a0051
7
+ data.tar.gz: 4d5622d9b87430b4316032a43fffb5c930f3210d2c1dec472a2920450a9ac1b541841987d654371906268f59ac4a211001db1f24188c853ee4f8f11742b46ec4
data/bin/arv-tag ADDED
@@ -0,0 +1,232 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ # arv tag usage:
4
+ # arv tag add tag1 [tag2 ...] --object obj_uuid1 [--object obj_uuid2 ...]
5
+ # arv tag remove tag1 [tag2 ...] --object obj_uuid1 [--object obj_uuid2 ...]
6
+ # arv tag remove tag1 [tag2 ...] --all
7
+
8
+ def usage
9
+ abort "Usage:\n" +
10
+ "arv tag add tag1 [tag2 ...] --objects object_uuid1 [object_uuid2...]\n" +
11
+ "arv tag remove tag1 [tag2 ...] --objects object_uuid1 [object_uuid2...]\n" +
12
+ "arv tag remove --all\n"
13
+ end
14
+
15
+ def api_call(method, parameters:{}, request_body:{})
16
+ request_body[:api_token] = ENV['ARVADOS_API_TOKEN']
17
+ result = $client.execute(:api_method => method,
18
+ :parameters => parameters,
19
+ :body => request_body,
20
+ :authenticated => false)
21
+
22
+ begin
23
+ results = JSON.parse result.body
24
+ rescue JSON::ParserError => e
25
+ abort "Failed to parse server response:\n" + e.to_s
26
+ end
27
+
28
+ if results["errors"]
29
+ abort "Error: #{results["errors"][0]}"
30
+ end
31
+
32
+ return results
33
+ end
34
+
35
+ def tag_add(tag, obj_uuid)
36
+ return api_call($arvados.links.create,
37
+ request_body: {
38
+ :link => {
39
+ :name => tag,
40
+ :link_class => :tag,
41
+ :head_uuid => obj_uuid,
42
+ }
43
+ })
44
+ end
45
+
46
+ def tag_remove(tag, obj_uuids=nil)
47
+ # If we got a list of objects to untag, look up the uuids for the
48
+ # links that need to be deleted.
49
+ link_uuids = []
50
+ if obj_uuids
51
+ obj_uuids.each do |uuid|
52
+ link = api_call($arvados.links.list,
53
+ request_body: {
54
+ :where => {
55
+ :link_class => :tag,
56
+ :name => tag,
57
+ :head_uuid => uuid,
58
+ }
59
+ })
60
+ if link['items_available'] > 0
61
+ link_uuids.push link['items'][0]['uuid']
62
+ end
63
+ end
64
+ else
65
+ all_tag_links = api_call($arvados.links.list,
66
+ request_body: {
67
+ :where => {
68
+ :link_class => :tag,
69
+ :name => tag,
70
+ }
71
+ })
72
+ link_uuids = all_tag_links['items'].map { |obj| obj['uuid'] }
73
+ end
74
+
75
+ results = []
76
+ if link_uuids
77
+ link_uuids.each do |uuid|
78
+ results.push api_call($arvados.links.delete, parameters:{ :uuid => uuid })
79
+ end
80
+ else
81
+ $stderr.puts "no tags found to remove"
82
+ end
83
+
84
+ return {
85
+ 'kind' => 'arvados#linkList',
86
+ 'items_available' => results.length,
87
+ 'items' => results,
88
+ }
89
+ end
90
+
91
+ if RUBY_VERSION < '1.9.3' then
92
+ abort <<-EOS
93
+ #{$0.gsub(/^\.\//,'')} requires Ruby version 1.9.3 or higher.
94
+ EOS
95
+ end
96
+
97
+ $arvados_api_version = ENV['ARVADOS_API_VERSION'] || 'v1'
98
+ $arvados_api_host = ENV['ARVADOS_API_HOST'] or
99
+ abort "#{$0}: fatal: ARVADOS_API_HOST environment variable not set."
100
+ $arvados_api_token = ENV['ARVADOS_API_TOKEN'] or
101
+ abort "#{$0}: fatal: ARVADOS_API_TOKEN environment variable not set."
102
+ $arvados_api_host_insecure = ENV['ARVADOS_API_HOST_INSECURE'] == 'yes'
103
+
104
+ begin
105
+ require 'rubygems'
106
+ require 'google/api_client'
107
+ require 'json'
108
+ require 'pp'
109
+ require 'oj'
110
+ require 'trollop'
111
+ rescue LoadError
112
+ abort <<-EOS
113
+ #{$0}: fatal: some runtime dependencies are missing.
114
+ Try: gem install pp google-api-client json trollop
115
+ EOS
116
+ end
117
+
118
+ def debuglog(message, verbosity=1)
119
+ $stderr.puts "#{File.split($0).last} #{$$}: #{message}" if $debuglevel >= verbosity
120
+ end
121
+
122
+ module Kernel
123
+ def suppress_warnings
124
+ original_verbosity = $VERBOSE
125
+ $VERBOSE = nil
126
+ result = yield
127
+ $VERBOSE = original_verbosity
128
+ return result
129
+ end
130
+ end
131
+
132
+ if $arvados_api_host_insecure or $arvados_api_host.match /local/
133
+ # You probably don't care about SSL certificate checks if you're
134
+ # testing with a dev server.
135
+ suppress_warnings { OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE }
136
+ end
137
+
138
+ class Google::APIClient
139
+ def discovery_document(api, version)
140
+ api = api.to_s
141
+ return @discovery_documents["#{api}:#{version}"] ||=
142
+ begin
143
+ response = self.execute!(
144
+ :http_method => :get,
145
+ :uri => self.discovery_uri(api, version),
146
+ :authenticated => false
147
+ )
148
+ response.body.class == String ? JSON.parse(response.body) : response.body
149
+ end
150
+ end
151
+ end
152
+
153
+ global_opts = Trollop::options do
154
+ banner "arvados cli client"
155
+ opt :dry_run, "Don't actually do anything", :short => "-n"
156
+ opt :verbose, "Print some things on stderr", :short => "-v"
157
+ opt :uuid, "Return the UUIDs of the objects in the response, one per line (default)", :short => nil
158
+ opt :json, "Return the entire response received from the API server, as a JSON object", :short => "-j"
159
+ opt :human, "Return the response received from the API server, as a JSON object with whitespace added for human consumption", :short => "-h"
160
+ opt :pretty, "Synonym of --human", :short => nil
161
+ opt :yaml, "Return the response received from the API server, in YAML format", :short => "-y"
162
+ stop_on ['add', 'remove']
163
+ end
164
+
165
+ p = Trollop::Parser.new do
166
+ opt(:all,
167
+ "Remove this tag from all objects under your ownership. Only valid with `tag remove'.",
168
+ :short => :none)
169
+ opt(:object,
170
+ "The UUID of an object to which this tag operation should be applied.",
171
+ :type => :string,
172
+ :multi => true,
173
+ :short => :o)
174
+ end
175
+
176
+ $options = Trollop::with_standard_exception_handling p do
177
+ p.parse ARGV
178
+ end
179
+
180
+ if $options[:all] and ARGV[0] != 'remove'
181
+ usage
182
+ end
183
+
184
+ # Set up the API client.
185
+
186
+ $client ||= Google::APIClient.
187
+ new(:host => $arvados_api_host,
188
+ :application_name => File.split($0).last,
189
+ :application_version => $application_version.to_s)
190
+ $arvados = $client.discovered_api('arvados', $arvados_api_version)
191
+
192
+ results = []
193
+ cmd = ARGV.shift
194
+ case cmd
195
+ when 'add'
196
+ ARGV.each do |tag|
197
+ $options[:object].each do |obj|
198
+ results.push(tag_add(tag, obj))
199
+ end
200
+ end
201
+ when 'remove'
202
+ ARGV.each do |tag|
203
+ if $options[:all] then
204
+ results.push(tag_remove(tag))
205
+ else
206
+ results.push(tag_remove(tag, $options[:object]))
207
+ end
208
+ end
209
+ else
210
+ usage
211
+ end
212
+
213
+ if global_opts[:human] or global_opts[:pretty] then
214
+ puts Oj.dump(results, :indent => 1)
215
+ elsif global_opts[:yaml] then
216
+ puts results.to_yaml
217
+ elsif global_opts[:json] then
218
+ puts Oj.dump(results)
219
+ else
220
+ results.each do |r|
221
+ next if r == nil
222
+ if r["items"] and r["kind"].match /list$/i
223
+ r['items'].each do |i| puts i['uuid'] end
224
+ elsif r['uuid'].nil?
225
+ abort("Response did not include a uuid:\n" +
226
+ Oj.dump(r, :indent => 1) +
227
+ "\n")
228
+ else
229
+ puts r['uuid']
230
+ end
231
+ end
232
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arvados-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.20140110131136
4
+ version: 0.1.20140110141515
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arvados Authors
@@ -108,18 +108,20 @@ dependencies:
108
108
  - - ~>
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.8'
111
- description: This is the Arvados SDK CLI gem, git revision 6696af28df909c0eb45f6cee8e7a3fc1d5658104
111
+ description: This is the Arvados SDK CLI gem, git revision 83f85a702927b37236b88ab9633d8e0e918e1218
112
112
  email: gem-dev@clinicalfuture.com
113
113
  executables:
114
114
  - arv
115
115
  - arv-run-pipeline-instance
116
116
  - arv-crunch-job
117
+ - arv-tag
117
118
  extensions: []
118
119
  extra_rdoc_files: []
119
120
  files:
120
121
  - bin/arv
121
122
  - bin/arv-run-pipeline-instance
122
123
  - bin/arv-crunch-job
124
+ - bin/arv-tag
123
125
  - bin/crunch-job
124
126
  homepage: http://arvados.org
125
127
  licenses: