arvados 0.1.20141114230720 → 0.1.20150116063758

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/lib/arvados/keep.rb +47 -26
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de05eab36f3416ca2dceb3609a5c04184d5f63e1
4
- data.tar.gz: 81e7fa1e333bea0f287475c957abc3766ddafa2d
3
+ metadata.gz: b3e69c326ebdfbd4759f072b1143baa76bb8f215
4
+ data.tar.gz: b17e6cbcd637f0cfbed773f71459344d21eaa9d1
5
5
  SHA512:
6
- metadata.gz: 8015c071b61d9647a7b921d72b49e60c2ca31f82d888e02254d54d8092ff961af5a718f845e58596ea4270f7897ea2c11df275fe893777cdbe02a3069a0fe25b
7
- data.tar.gz: 2314bfed614067fa48ccdf3d9cd6674cbf2e46dd9f0009c5ee063aaa33adf75bed7e202ec6cbd22c3ec1ea5690e29b827bc6efc11017446d0d091f8d0d417ffa
6
+ metadata.gz: cc23ff188453b70428cd851ce3d13e34973ed7e229f696ce9a413a1e3bdadeb1ffe84a30eeccf0c411e7b45f349d5378335c450a2b95e29864b6e9c828337359
7
+ data.tar.gz: d67bcfd4e0af3a717b4648608e7d5c91041fcb701499c0058eb3fdb0198341d54cef66637f3bb14bb3c5969d5866a7a2d3c5c304e8bb5c350058607eab6c73f1
data/lib/arvados/keep.rb CHANGED
@@ -18,12 +18,18 @@ module Keep
18
18
  # sign-timestamp ::= <8 lowercase hex digits>
19
19
  attr_reader :hash, :hints, :size
20
20
 
21
+ LOCATOR_REGEXP = /^([[:xdigit:]]{32})(\+([[:digit:]]+))?(\+([[:upper:]][[:alnum:]+@_-]*))?$/
22
+
21
23
  def initialize(hasharg, sizearg, hintarg)
22
24
  @hash = hasharg
23
25
  @size = sizearg
24
26
  @hints = hintarg
25
27
  end
26
28
 
29
+ def self.valid? tok
30
+ !!(LOCATOR_REGEXP.match tok)
31
+ end
32
+
27
33
  # Locator.parse returns a Locator object parsed from the string tok.
28
34
  # Returns nil if tok could not be parsed as a valid locator.
29
35
  def self.parse(tok)
@@ -41,7 +47,7 @@ module Keep
41
47
  raise ArgumentError.new "locator is nil or empty"
42
48
  end
43
49
 
44
- m = /^([[:xdigit:]]{32})(\+([[:digit:]]+))?(\+([[:upper:]][[:alnum:]+@_-]*))?$/.match(tok.strip)
50
+ m = LOCATOR_REGEXP.match(tok.strip)
45
51
  unless m
46
52
  raise ArgumentError.new "not a valid locator #{tok}"
47
53
  end
@@ -100,15 +106,21 @@ module Keep
100
106
  def each_line
101
107
  return to_enum(__method__) unless block_given?
102
108
  @text.each_line do |line|
103
- tokens = line.split
104
- next if tokens.empty?
105
- stream_name = unescape(tokens.shift)
106
- blocks = []
107
- while loc = Locator.parse(tokens.first)
108
- blocks << loc
109
- tokens.shift
109
+ stream_name = nil
110
+ block_tokens = []
111
+ file_tokens = []
112
+ line.scan /\S+/ do |token|
113
+ if stream_name.nil?
114
+ stream_name = unescape token
115
+ elsif file_tokens.empty? and Locator.valid? token
116
+ block_tokens << token
117
+ else
118
+ file_tokens << unescape(token)
119
+ end
110
120
  end
111
- yield [stream_name, blocks, tokens.map { |s| unescape(s) }]
121
+ # Ignore blank lines
122
+ next if stream_name.nil?
123
+ yield [stream_name, block_tokens, file_tokens]
112
124
  end
113
125
  end
114
126
 
@@ -124,21 +136,33 @@ module Keep
124
136
  end
125
137
  end
126
138
 
127
- def each_file_spec(speclist)
128
- return to_enum(__method__, speclist) unless block_given?
129
- speclist.each do |filespec|
130
- start_pos, filesize, filename = filespec.split(':', 3)
131
- yield [start_pos.to_i, filesize.to_i, filename]
139
+ def split_file_token token
140
+ start_pos, filesize, filename = token.split(':', 3)
141
+ [start_pos.to_i, filesize.to_i, filename]
142
+ end
143
+
144
+ def each_file_spec
145
+ return to_enum(__method__) unless block_given?
146
+ @text.each_line do |line|
147
+ stream_name = nil
148
+ in_file_tokens = false
149
+ line.scan /\S+/ do |token|
150
+ if stream_name.nil?
151
+ stream_name = unescape token
152
+ elsif in_file_tokens or not Locator.valid? token
153
+ in_file_tokens = true
154
+ yield [stream_name] + split_file_token(token)
155
+ end
156
+ end
132
157
  end
158
+ true
133
159
  end
134
160
 
135
161
  def files
136
162
  if @files.nil?
137
163
  file_sizes = Hash.new(0)
138
- each_line do |streamname, blocklist, filelist|
139
- each_file_spec(filelist) do |_, filesize, filename|
140
- file_sizes[[streamname, filename]] += filesize
141
- end
164
+ each_file_spec do |streamname, _, filesize, filename|
165
+ file_sizes[[streamname, filename]] += filesize
142
166
  end
143
167
  @files = file_sizes.each_pair.map do |(streamname, filename), size|
144
168
  [streamname, filename, size]
@@ -157,11 +181,9 @@ module Keep
157
181
  return files.size
158
182
  end
159
183
  seen_files = {}
160
- each_line do |streamname, blocklist, filelist|
161
- each_file_spec(filelist) do |_, _, filename|
162
- seen_files[[streamname, filename]] = true
163
- return stop_after if (seen_files.size >= stop_after)
164
- end
184
+ each_file_spec do |streamname, _, _, filename|
185
+ seen_files[[streamname, filename]] = true
186
+ return stop_after if (seen_files.size >= stop_after)
165
187
  end
166
188
  seen_files.size
167
189
  end
@@ -178,9 +200,8 @@ module Keep
178
200
  if want_file.nil?
179
201
  want_stream, want_file = File.split(want_stream)
180
202
  end
181
- each_line do |stream_name, _, filelist|
182
- if (stream_name == want_stream) and
183
- each_file_spec(filelist).any? { |_, _, name| name == want_file }
203
+ each_file_spec do |streamname, _, _, name|
204
+ if streamname == want_stream and name == want_file
184
205
  return true
185
206
  end
186
207
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arvados
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.20141114230720
4
+ version: 0.1.20150116063758
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-11-14 00:00:00.000000000 Z
11
+ date: 2015-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client
@@ -104,7 +104,7 @@ dependencies:
104
104
  - - "<"
105
105
  - !ruby/object:Gem::Version
106
106
  version: 1.0.0
107
- description: Arvados client library, git commit 6de0a4ab0323e69a5499e59af03c9c5e6125fed7
107
+ description: Arvados client library, git commit 3fec99e70492e163763ed185aafbf022bf5e16b7
108
108
  email: gem-dev@curoverse.com
109
109
  executables: []
110
110
  extensions: []