aws_s3_export 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +24 -2
- data/lib/aws_s3_export/config.rb +6 -1
- data/lib/aws_s3_export/export.rb +47 -1
- data/lib/aws_s3_export/version.rb +1 -1
- metadata +5 -5
data/README.md
CHANGED
@@ -17,7 +17,7 @@ Or install it yourself as:
|
|
17
17
|
|
18
18
|
## Usage
|
19
19
|
|
20
|
-
creat file export.rb and
|
20
|
+
creat file export.rb and paste code below:
|
21
21
|
|
22
22
|
#simple script for usage
|
23
23
|
require 'rubygems'
|
@@ -30,7 +30,29 @@ creat file export.rb and pust code below
|
|
30
30
|
s3.run
|
31
31
|
|
32
32
|
Run from console: $ ruby export.rb
|
33
|
-
And you should will see:
|
33
|
+
And you should will see something like this:
|
34
|
+
|
35
|
+
Work in .
|
36
|
+
Work in ..
|
37
|
+
Work in 1
|
38
|
+
File '1/large/IMG_0298.JPG' has saved
|
39
|
+
File '1/medium/IMG_0298.JPG' has savd
|
40
|
+
File '1/micro/IMG_0298.JPG' has saved
|
41
|
+
File '1/original/IMG_0298.JPG' has saved
|
42
|
+
File '1/slide_Show/IMG_0298.JPG' has saved
|
43
|
+
File '1/small/IMG_0298.JPG' has saved
|
44
|
+
File '1/small_149/IMG_0298.JPG' has saved
|
45
|
+
File '1/smaller/IMG_0298.JPG' has saved
|
46
|
+
Work in 11
|
47
|
+
File '11/large/IMG_3518.JPG' has saved
|
48
|
+
File '11/medium/IMG_3518.JPG' has saved
|
49
|
+
File '11/micro/IMG_3518.JPG' has saved
|
50
|
+
File '11/original/IMG_3518.JPG' has saved
|
51
|
+
File '11/slide_Show/IMG_3518.JPG' has saved
|
52
|
+
File '11/small/IMG_3518.JPG' has saved
|
53
|
+
|
54
|
+
If set prefix then in bucket you will have
|
55
|
+
prefix_name/1/large/IMG_0298.JPG
|
34
56
|
|
35
57
|
|
36
58
|
## Contributing
|
data/lib/aws_s3_export/config.rb
CHANGED
@@ -8,13 +8,16 @@ module AwsS3Export
|
|
8
8
|
# :bucket_name - name of bucket s3
|
9
9
|
# :access_key - access key id of s3
|
10
10
|
# :secret_access_key - secret access key of s3
|
11
|
+
# :rewrite_existing_files - if you want to rewrite set as true
|
12
|
+
# :acl - access controll like in http://docs.amazonwebservices.com/AWSRubySDK/latest/AWS/S3/S3Object.html#write-instance_method in aws-sdk
|
13
|
+
# default as public_read
|
11
14
|
#
|
12
15
|
# Get config for example the export_dir:
|
13
16
|
# s3_config.export_dir #=> /your/dir/
|
14
17
|
#
|
15
18
|
|
16
19
|
class Config
|
17
|
-
attr_reader :access_key, :secret_access_key, :export_dir, :bucket_name, :prefix
|
20
|
+
attr_reader :access_key, :secret_access_key, :export_dir, :bucket_name, :prefix, :rewrite_existing_files, :acl
|
18
21
|
|
19
22
|
def initialize(options = {})
|
20
23
|
validation_options.each do |o|
|
@@ -28,6 +31,8 @@ module AwsS3Export
|
|
28
31
|
@export_dir = options[:export_dir] || "./" # the current directory
|
29
32
|
@bucket_name = options[:bucket_name]
|
30
33
|
@prefix = options[:prefix] || ""
|
34
|
+
@rewrite_existing_files = options[:rewrite_existing_files] || false
|
35
|
+
@acl = options[:acl] || :public_read
|
31
36
|
end
|
32
37
|
|
33
38
|
private
|
data/lib/aws_s3_export/export.rb
CHANGED
@@ -1,4 +1,42 @@
|
|
1
1
|
module AwsS3Export
|
2
|
+
#
|
3
|
+
# creat file export.rb and paste code below:
|
4
|
+
|
5
|
+
# #simple script for usage
|
6
|
+
# require 'rubygems'
|
7
|
+
# require 'aws_s3_export'
|
8
|
+
|
9
|
+
# s3 = AwsS3Export::Export.new(:export_dir => 'a/directory/on/ours/computer', :bucket_name =>'your-bucket-name',
|
10
|
+
# :prefix => 'a/prefix/in/your/bucket', :access_key => "XXX",
|
11
|
+
# :secret_access_key => "XXX" )
|
12
|
+
|
13
|
+
# s3.run
|
14
|
+
|
15
|
+
# Run from console: $ ruby export.rb
|
16
|
+
# And you should will see something like this:
|
17
|
+
|
18
|
+
# Work in .
|
19
|
+
# Work in ..
|
20
|
+
# Work in 1
|
21
|
+
# File '1/large/IMG_0298.JPG' has saved
|
22
|
+
# File '1/medium/IMG_0298.JPG' has savd
|
23
|
+
# File '1/micro/IMG_0298.JPG' has saved
|
24
|
+
# File '1/original/IMG_0298.JPG' has saved
|
25
|
+
# File '1/slide_Show/IMG_0298.JPG' has saved
|
26
|
+
# File '1/small/IMG_0298.JPG' has saved
|
27
|
+
# File '1/small_149/IMG_0298.JPG' has saved
|
28
|
+
# File '1/smaller/IMG_0298.JPG' has saved
|
29
|
+
# Work in 11
|
30
|
+
# File '11/large/IMG_3518.JPG' has saved
|
31
|
+
# File '11/medium/IMG_3518.JPG' has saved
|
32
|
+
# File '11/micro/IMG_3518.JPG' has saved
|
33
|
+
# File '11/original/IMG_3518.JPG' has saved
|
34
|
+
# File '11/slide_Show/IMG_3518.JPG' has saved
|
35
|
+
# File '11/small/IMG_3518.JPG' has saved
|
36
|
+
|
37
|
+
# If set prefix then in bucket you will have
|
38
|
+
# prefix_name/1/large/IMG_0298.JPG
|
39
|
+
|
2
40
|
|
3
41
|
class Export
|
4
42
|
def initialize(options = {})
|
@@ -29,16 +67,24 @@ module AwsS3Export
|
|
29
67
|
|
30
68
|
private
|
31
69
|
def save_file(file)
|
70
|
+
|
32
71
|
if !@config.prefix.empty?
|
33
72
|
prefix = "#{@config.prefix}/"
|
34
73
|
else
|
35
74
|
prefix = ""
|
36
75
|
end
|
76
|
+
|
37
77
|
# Grab a reference to an object in the bucket with the name we require
|
38
78
|
object = @bucket.objects["#{prefix}#{file}"]
|
79
|
+
|
80
|
+
#overwrite file?
|
81
|
+
if object.exists? and !@config.rewrite_existing_files
|
82
|
+
puts "Skip writing file '#{file}'. If you want to rewrete file set option 'rewrite_existing_files' to true"
|
83
|
+
return
|
84
|
+
end
|
39
85
|
|
40
86
|
# Write a local file to the aforementioned object on S3
|
41
|
-
if object.write(:file => File.expand_path(
|
87
|
+
if object.write(:file => File.expand_path(file, @config.export_dir), :acl => @config.acl)
|
42
88
|
puts "File '#{file}' has saved"
|
43
89
|
else
|
44
90
|
puts "Somthing wrong! File '#{file}' not save"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws_s3_export
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alex Dmitriev
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-06-
|
18
|
+
date: 2012-06-04 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: aws-sdk
|