sluice 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ Version 0.0.5 (2012-12-30)
2
+ --------------------------
3
+ Added option to flatten recursive paths
4
+
5
+ Version 0.0.4 (2012-11-09)
6
+ --------------------------
7
+ Fixed nasty bug where the retry code wasn't working
8
+
1
9
  Version 0.0.3 (2012-11-07)
2
10
  --------------------------
3
11
  Added parallel file download
@@ -122,10 +122,11 @@ module Sluice
122
122
  # +to_location+:: S3Location to copy files to
123
123
  # +match_regex+:: a regex string to match the files to copy
124
124
  # +alter_filename_lambda+:: lambda to alter the written filename
125
- def copy_files(s3, from_location, to_location, match_regex='.+', alter_filename_lambda=false)
125
+ # +flatten+:: strips off any sub-folders below the from_location
126
+ def copy_files(s3, from_location, to_location, match_regex='.+', alter_filename_lambda=false, flatten=false)
126
127
 
127
128
  puts " copying files from #{from_location} to #{to_location}"
128
- process_files(:copy, s3, from_location, match_regex, to_location, alter_filename_lambda)
129
+ process_files(:copy, s3, from_location, match_regex, to_location, alter_filename_lambda, flatten)
129
130
  end
130
131
  module_function :copy_files
131
132
 
@@ -137,10 +138,11 @@ module Sluice
137
138
  # +to+:: S3Location to move files to
138
139
  # +match_regex+:: a regex string to match the files to move
139
140
  # +alter_filename_lambda+:: lambda to alter the written filename
140
- def move_files(s3, from_location, to_location, match_regex='.+', alter_filename_lambda=false)
141
+ # +flatten+:: strips off any sub-folders below the from_location
142
+ def move_files(s3, from_location, to_location, match_regex='.+', alter_filename_lambda=false, flatten=false)
141
143
 
142
144
  puts " moving files from #{from_location} to #{to_location}"
143
- process_files(:move, s3, from_location, match_regex, to_location, alter_filename_lambda)
145
+ process_files(:move, s3, from_location, match_regex, to_location, alter_filename_lambda, flatten)
144
146
  end
145
147
  module_function :move_files
146
148
 
@@ -178,7 +180,8 @@ module Sluice
178
180
  # +match_regex+:: a regex string to match the files to process
179
181
  # +to_loc_or_dir+:: S3Location or local directory to process files to
180
182
  # +alter_filename_lambda+:: lambda to alter the written filename
181
- def process_files(operation, s3, from_location, match_regex='.+', to_loc_or_dir=nil, alter_filename_lambda=false)
183
+ # +flatten+:: strips off any sub-folders below the from_location
184
+ def process_files(operation, s3, from_location, match_regex='.+', to_loc_or_dir=nil, alter_filename_lambda=false, flatten=false)
182
185
 
183
186
  # Validate that the file operation makes sense
184
187
  case operation
@@ -269,13 +272,13 @@ module Sluice
269
272
  source = "#{from_location.bucket}/#{file.key}"
270
273
  case operation
271
274
  when :download
272
- target = name_file(file.key, filename, from_location.dir_as_path, to_loc_or_dir)
275
+ target = name_file(file.key, filename, from_location.dir_as_path, to_loc_or_dir, flatten)
273
276
  puts " DOWNLOAD #{source} +-> #{target}"
274
277
  when :move
275
- target = name_file(file.key, filename, from_location.dir_as_path, to_loc_or_dir.dir_as_path)
278
+ target = name_file(file.key, filename, from_location.dir_as_path, to_loc_or_dir.dir_as_path, flatten)
276
279
  puts " MOVE #{source} -> #{to_loc_or_dir.bucket}/#{target}"
277
280
  when :copy
278
- target = name_file(file.key, filename, from_location.dir_as_path, to_loc_or_dir.dir_as_path)
281
+ target = name_file(file.key, filename, from_location.dir_as_path, to_loc_or_dir.dir_as_path, flatten)
279
282
  puts " COPY #{source} +-> #{to_loc_or_dir.bucket}/#{target}"
280
283
  when :delete
281
284
  # No target
@@ -355,27 +358,33 @@ module Sluice
355
358
  # +new_filename+:: Replace the filename in the path with this
356
359
  # +remove_path+:: If this is set, strip this from the front of the path
357
360
  # +add_path+:: If this is set, add this to the front of the path
361
+ # +flatten+:: strips off any sub-folders below the from_location
358
362
  #
359
363
  # TODO: this really needs unit tests
360
- def name_file(filepath, new_filename, remove_path=nil, add_path=nil)
364
+ def name_file(filepath, new_filename, remove_path=nil, add_path=nil, flatten=false)
361
365
 
362
366
  # First, replace the filename in filepath with new one
363
367
  dirname = File.dirname(filepath)
364
368
  new_filepath = (dirname == '.') ? new_filename : dirname + '/' + new_filename
365
369
 
366
370
  # Nothing more to do
367
- return new_filepath if remove_path.nil?
368
-
369
- # If we have a 'remove_path', it must be found at
370
- # the start of the path.
371
- # If it's not, you're probably using name_file()
372
- # wrong.
373
- if !filepath.start_with?(remove_path)
374
- raise StorageOperationError, "name_file failed. Filepath '#{filepath}' does not start with '#{remove_path}'"
375
- end
376
-
377
- # Okay, let's remove the filepath
378
- shortened_filepath = new_filepath[remove_path.length()..-1]
371
+ return new_filepath if remove_path.nil? and add_path.nil? and not flatten
372
+
373
+ shortened_filepath = if flatten
374
+ # Let's revert to just the filename
375
+ new_filename
376
+ else
377
+ # If we have a 'remove_path', it must be found at
378
+ # the start of the path.
379
+ # If it's not, you're probably using name_file()
380
+ # wrong.
381
+ if !filepath.start_with?(remove_path)
382
+ raise StorageOperationError, "name_file failed. Filepath '#{filepath}' does not start with '#{remove_path}'"
383
+ end
384
+
385
+ # Okay, let's remove the filepath
386
+ new_filepath[remove_path.length()..-1]
387
+ end
379
388
 
380
389
  # Nothing more to do
381
390
  return shortened_filepath if add_path.nil?
data/lib/sluice.rb CHANGED
@@ -19,5 +19,5 @@ require 'sluice/storage/s3'
19
19
 
20
20
  module Sluice
21
21
  NAME = "sluice"
22
- VERSION = "0.0.4"
22
+ VERSION = "0.0.5"
23
23
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sluice
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Dean
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-11-09 00:00:00 Z
19
+ date: 2012-12-30 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: fog