s3_uploader 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -4
- data/lib/s3_uploader/s3_uploader.rb +13 -7
- data/lib/s3_uploader/version.rb +1 -1
- data/lib/s3_uploader.rb +1 -0
- data/spec/s3uploader_spec.rb +28 -14
- data/spec/spec_helper.rb +3 -0
- metadata +8 -8
data/README.md
CHANGED
@@ -28,16 +28,19 @@ Or install it yourself as:
|
|
28
28
|
## Usage
|
29
29
|
|
30
30
|
S3Uploader.upload_directory('/tmp/test', 'mybucket',
|
31
|
-
{ :s3_key => YOUR_KEY,
|
32
|
-
:
|
31
|
+
{ :s3_key => YOUR_KEY,
|
32
|
+
:s3_secret => YOUR_SECRET_KEY,
|
33
|
+
:destination_dir => 'test/',
|
34
|
+
:region => 'eu-west-1',
|
35
|
+
:threads => 4 })
|
33
36
|
|
34
|
-
If no keys are provided, it uses S3_KEY and S3_SECRET environment variables.
|
37
|
+
If no keys are provided, it uses S3_KEY and S3_SECRET environment variables. us-east-1 is the default region.
|
35
38
|
|
36
39
|
S3Uploader.upload_directory('/tmp/test', 'mybucket', { :destination_dir => 'test/', :threads => 4 })
|
37
40
|
|
38
41
|
Or as a command line binary
|
39
42
|
|
40
|
-
s3uploader -k YOUR_KEY -s YOUR_SECRET_KEY -d test/ -t 4 /tmp/test mybucket
|
43
|
+
s3uploader -r eu-west-1 -k YOUR_KEY -s YOUR_SECRET_KEY -d test/ -t 4 /tmp/test mybucket
|
41
44
|
|
42
45
|
Again, it uses S3_KEY and S3_SECRET environment variables if non provided in parameters.
|
43
46
|
|
@@ -9,6 +9,8 @@ module S3Uploader
|
|
9
9
|
:region => 'us-east-1'
|
10
10
|
}.merge(options)
|
11
11
|
|
12
|
+
log = options[:logger] || Logger.new(STDOUT)
|
13
|
+
|
12
14
|
raise 'Source must be a directory' unless File.directory?(source)
|
13
15
|
|
14
16
|
source = source.chop if source.end_with?('/')
|
@@ -21,12 +23,16 @@ module S3Uploader
|
|
21
23
|
files << f
|
22
24
|
end
|
23
25
|
|
24
|
-
connection
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
if options[:connection]
|
27
|
+
connection = options[:connection]
|
28
|
+
else
|
29
|
+
connection = Fog::Storage.new({
|
30
|
+
:provider => 'AWS',
|
31
|
+
:aws_access_key_id => options[:s3_key],
|
32
|
+
:aws_secret_access_key => options[:s3_secret],
|
33
|
+
:region => options[:region]
|
34
|
+
})
|
35
|
+
end
|
30
36
|
|
31
37
|
directory = connection.directories.new(:key => bucket)
|
32
38
|
|
@@ -45,7 +51,7 @@ module S3Uploader
|
|
45
51
|
file = files.pop
|
46
52
|
key = file.gsub(source, '')[1..-1]
|
47
53
|
dest = "#{options[:destination_dir]}#{key}"
|
48
|
-
|
54
|
+
log.info("[#{file_number}/#{total_files}] Uploading #{key} to s3://#{bucket}/#{dest}")
|
49
55
|
|
50
56
|
directory.files.create(
|
51
57
|
:key => dest,
|
data/lib/s3_uploader/version.rb
CHANGED
data/lib/s3_uploader.rb
CHANGED
data/spec/s3uploader_spec.rb
CHANGED
@@ -3,28 +3,42 @@ require 'spec_helper'
|
|
3
3
|
describe S3Uploader do
|
4
4
|
before :all do
|
5
5
|
Fog.mock!
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
|
7
|
+
@connection = Fog::Storage.new({
|
8
|
+
:provider => 'AWS',
|
9
|
+
:aws_access_key_id => '11111111111',
|
10
|
+
:aws_secret_access_key => 'XXXXXXXXXXXXXXXXXXXXXXXXXXX'
|
11
|
+
})
|
12
|
+
|
13
|
+
@connection.directories.create(
|
14
|
+
:key => 'mybucket',
|
15
|
+
:public => true
|
16
|
+
)
|
17
|
+
|
18
|
+
@tmp_directory = File.join(Dir.tmpdir, 'test_s3_uploader')
|
19
|
+
create_test_files(@tmp_directory, 10)
|
20
|
+
create_test_files(File.join(@tmp_directory, 'subdir1'), 5)
|
21
|
+
@logger = Logger.new(StringIO.new)
|
9
22
|
end
|
10
23
|
|
11
24
|
it "should upload all files in a directory" do
|
12
|
-
|
25
|
+
|
26
|
+
@logger.should_receive(:info).exactly(15).times.with(/Uploading/)
|
27
|
+
|
28
|
+
S3Uploader.upload_directory(@tmp_directory, 'mybucket',
|
29
|
+
{ :destination_dir => 'test1/',
|
30
|
+
:logger => @logger,
|
31
|
+
:connection => @connection
|
32
|
+
})
|
33
|
+
|
13
34
|
end
|
14
35
|
|
15
|
-
after :all do
|
16
|
-
FileUtils.rm @base_test_directory
|
17
|
-
end
|
18
36
|
end
|
19
37
|
|
20
38
|
def create_test_files(directory, number_of_files)
|
21
39
|
FileUtils.mkdir_p directory
|
22
|
-
|
23
|
-
$stdout = File.new( '/dev/null', 'w' )
|
24
40
|
|
25
41
|
number_of_files.times do |i|
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
$stdout = STDOUT
|
30
|
-
end
|
42
|
+
Open3.popen3('dd if=/dev/zero of=#{directory}/file#{i}.txt count=1024 bs=1024')
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3_uploader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152669100 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152669100
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152668680 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152668680
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152668260 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152668260
|
47
47
|
description: S3 multithreaded directory uploader
|
48
48
|
email:
|
49
49
|
- chrishein@gmail.com
|