arvados 0.1.20140909151622 → 0.1.20140910123800

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 +66 -11
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14c8142d52bb086071d797a71f30740d55e3b113
4
- data.tar.gz: b81833ea78e17af27936c1fafa0b4ede6f79e3f5
3
+ metadata.gz: 76f2025b289c3869d9ab13a42e3242c7eb4815ce
4
+ data.tar.gz: 6c12428dfab28718ee596af488dd46ff7398246e
5
5
  SHA512:
6
- metadata.gz: f6bb6fde478daa87acde8018ab55cf25ba809ae9fb313bac9b7bac86d9e2cf37bb09f249cfe65d30e66c4fc5c48c7d087eab88149074d3e1588fdbdab8bd05cd
7
- data.tar.gz: 56fff84e629e1a4c1eb5e6d95c486b673740c41204601f4239570719fa4cbd5d8b4207ef7346bfb07aa0fec67862d63749098b079875e2d6f80f5f4b6b9bd866
6
+ metadata.gz: 613ee75d6a08e13313b3ec83e34d8936a408c2c4b43a31f4d85de1895033010a3eb743b698c5eace067875456d47bf04fd54f23a9a11a363b1fba3ecefd0ff7d
7
+ data.tar.gz: dcad0bbab01458824d6d0792ffd1e4bc9442a69c6e46c9f6c28f7256e5532d8cf961287c5519b715d150f2d634368691fe52e388c355b94458ec2f2ef96639f7
data/lib/arvados/keep.rb CHANGED
@@ -94,9 +94,10 @@ module Keep
94
94
  # Class to parse a manifest text and provide common views of that data.
95
95
  def initialize(manifest_text)
96
96
  @text = manifest_text
97
+ @files = nil
97
98
  end
98
99
 
99
- def each_stream
100
+ def each_line
100
101
  return to_enum(__method__) unless block_given?
101
102
  @text.each_line do |line|
102
103
  tokens = line.split
@@ -110,17 +111,8 @@ module Keep
110
111
  end
111
112
  end
112
113
 
113
- def each_file
114
- return to_enum(__method__) unless block_given?
115
- each_stream do |streamname, blocklist, filelist|
116
- filelist.each do |filespec|
117
- start_pos, filesize, filename = filespec.split(':', 3)
118
- yield [streamname, filename, filesize.to_i]
119
- end
120
- end
121
- end
122
-
123
114
  def unescape(s)
115
+ # Parse backslash escapes in a Keep manifest stream or file name.
124
116
  s.gsub(/\\(\\|[0-7]{3})/) do |_|
125
117
  case $1
126
118
  when '\\'
@@ -130,5 +122,68 @@ module Keep
130
122
  end
131
123
  end
132
124
  end
125
+
126
+ def each_file_spec(speclist)
127
+ return to_enum(__method__, speclist) unless block_given?
128
+ speclist.each do |filespec|
129
+ start_pos, filesize, filename = filespec.split(':', 3)
130
+ yield [start_pos.to_i, filesize.to_i, filename]
131
+ end
132
+ end
133
+
134
+ def files
135
+ if @files.nil?
136
+ file_sizes = Hash.new(0)
137
+ each_line do |streamname, blocklist, filelist|
138
+ each_file_spec(filelist) do |_, filesize, filename|
139
+ file_sizes[[streamname, filename]] += filesize
140
+ end
141
+ end
142
+ @files = file_sizes.each_pair.map do |(streamname, filename), size|
143
+ [streamname, filename, size]
144
+ end
145
+ end
146
+ @files
147
+ end
148
+
149
+ def files_count(stop_after=nil)
150
+ # Return the number of files represented in this manifest.
151
+ # If stop_after is provided, files_count will read the manifest
152
+ # incrementally, and return immediately when it counts that number of
153
+ # files. This can help you avoid parsing the entire manifest if you
154
+ # just want to check if a small number of files are specified.
155
+ if stop_after.nil? or not @files.nil?
156
+ return files.size
157
+ end
158
+ seen_files = {}
159
+ each_line do |streamname, blocklist, filelist|
160
+ each_file_spec(filelist) do |_, _, filename|
161
+ seen_files[[streamname, filename]] = true
162
+ return stop_after if (seen_files.size >= stop_after)
163
+ end
164
+ end
165
+ seen_files.size
166
+ end
167
+
168
+ def exact_file_count?(want_count)
169
+ files_count(want_count + 1) == want_count
170
+ end
171
+
172
+ def minimum_file_count?(want_count)
173
+ files_count(want_count) >= want_count
174
+ end
175
+
176
+ def has_file?(want_stream, want_file=nil)
177
+ if want_file.nil?
178
+ want_stream, want_file = File.split(want_stream)
179
+ end
180
+ each_line do |stream_name, _, filelist|
181
+ if (stream_name == want_stream) and
182
+ each_file_spec(filelist).any? { |_, _, name| name == want_file }
183
+ return true
184
+ end
185
+ end
186
+ false
187
+ end
133
188
  end
134
189
  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.20140909151622
4
+ version: 0.1.20140910123800
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-09-09 00:00:00.000000000 Z
11
+ date: 2014-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client
@@ -86,7 +86,7 @@ dependencies:
86
86
  - - "<"
87
87
  - !ruby/object:Gem::Version
88
88
  version: 1.0.0
89
- description: This is the Arvados SDK gem, git revision b0440160e64caecbff160a26f62301dd15d84c7f
89
+ description: This is the Arvados SDK gem, git revision bafb417c531d6094697a13a7465313d1cc7c0bc9
90
90
  email: gem-dev@curoverse.com
91
91
  executables: []
92
92
  extensions: []