s3-batch 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/bin/s3-batch +11 -0
- data/lib/s3-batch/version.rb +5 -0
- data/lib/s3-batch.rb +133 -0
- data/s3-batch.gemspec +23 -0
- metadata +99 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/s3-batch
ADDED
data/lib/s3-batch.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'aws'
|
3
|
+
|
4
|
+
module S3
|
5
|
+
end
|
6
|
+
|
7
|
+
class S3::Batch < Thor
|
8
|
+
|
9
|
+
require "s3-batch/version"
|
10
|
+
|
11
|
+
include Thor::Actions
|
12
|
+
|
13
|
+
class_options :'bucket' => :string
|
14
|
+
class_options :'access-key-id' => :string
|
15
|
+
class_options :'secret-access-key' => :string
|
16
|
+
class_options :'location' => :string
|
17
|
+
class_options :'acl' => :string
|
18
|
+
|
19
|
+
desc "upload [DIR]", "Upload many files to S3"
|
20
|
+
def upload(dir=nil)
|
21
|
+
@root = dir
|
22
|
+
bucket
|
23
|
+
|
24
|
+
files_to_upload.each do |file|
|
25
|
+
puts "Uploading: #{file}"
|
26
|
+
object = bucket.objects[file]
|
27
|
+
|
28
|
+
if object.exists?
|
29
|
+
puts "[SKIP] File exists."
|
30
|
+
next
|
31
|
+
end
|
32
|
+
|
33
|
+
object.write(
|
34
|
+
:file => File.join(@root, file),
|
35
|
+
:acl => acl,
|
36
|
+
:storage_class => :standard,
|
37
|
+
:cache_control => 'max-age=315360000')
|
38
|
+
|
39
|
+
puts "[DONE] File uploaded."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
attr_reader :root
|
46
|
+
|
47
|
+
def files_to_upload
|
48
|
+
@files_to_upload ||= begin
|
49
|
+
files = []
|
50
|
+
@root = File.expand_path(@root || '.')
|
51
|
+
Dir.glob(@root+'/**/*').each do |path|
|
52
|
+
next unless File.file?(path)
|
53
|
+
files << path[(@root.size + 1)..-1]
|
54
|
+
end
|
55
|
+
files
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def s3
|
60
|
+
@s3 ||= AWS::S3.new(
|
61
|
+
:access_key_id => access_key_id,
|
62
|
+
:secret_access_key => secret_access_key,
|
63
|
+
:s3_endpoint => s3_endpoint
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
def bucket
|
68
|
+
@bucket ||= begin
|
69
|
+
bucket = s3.buckets[bucket_name]
|
70
|
+
unless bucket.exists?
|
71
|
+
puts "Creating bucket: #{bucket_name}"
|
72
|
+
bucket = s3.buckets.create(bucket_name,
|
73
|
+
:location_constraint => location_constraint,
|
74
|
+
:acl => acl)
|
75
|
+
end
|
76
|
+
bucket
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def bucket_name
|
81
|
+
@bucket_name ||= begin
|
82
|
+
options[:'bucket'] || ask('Bucket:')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def access_key_id
|
87
|
+
@access_key_id ||= begin
|
88
|
+
options[:'access-key-id'] || ask('Access Key ID:')
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def secret_access_key
|
93
|
+
@secret_access_key ||= begin
|
94
|
+
options[:'secret-access-key'] || ask('Secret Access Key:')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def location
|
99
|
+
@location ||= begin
|
100
|
+
v = options[:'location'] || ask('Location [EU-WEST]:')
|
101
|
+
v = 'EU-WEST' if v.empty?
|
102
|
+
v
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def acl
|
107
|
+
@acl ||= begin
|
108
|
+
v = options[:'acl'] || ask('ACL [PUBLIC-READ]:')
|
109
|
+
v = 'PUBLIC-READ' if v.empty?
|
110
|
+
v.downcase.gsub('-', '_').to_sym
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def s3_endpoint
|
115
|
+
{
|
116
|
+
'US-EAST' => 's3.amazonaws.com',
|
117
|
+
'US-WEST' => 's3-us-west-1.amazonaws.com',
|
118
|
+
'EU-WEST' => 's3-eu-west-1.amazonaws.com',
|
119
|
+
'AP-SOUTHEAST' => 's3-ap-southeast-1.amazonaws.com',
|
120
|
+
'AP-NORTHEAST' => 's3-ap-northeast-1.amazonaws.com'
|
121
|
+
}[location]
|
122
|
+
end
|
123
|
+
|
124
|
+
def location_constraint
|
125
|
+
{
|
126
|
+
'US-EAST' => nil,
|
127
|
+
'US-WEST' => 'us-west-1',
|
128
|
+
'EU-WEST' => 'EU',
|
129
|
+
'AP-SOUTHEAST' => 'ap-southeast-1',
|
130
|
+
'AP-NORTHEAST' => 'ap-northeast-1'
|
131
|
+
}[location]
|
132
|
+
end
|
133
|
+
end
|
data/s3-batch.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "s3-batch/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "s3-batch"
|
7
|
+
s.version = S3::Batch::VERSION
|
8
|
+
s.authors = ["Simon Menke"]
|
9
|
+
s.email = ["simon.menke@gmail.com"]
|
10
|
+
s.homepage = "http://github.com/fd"
|
11
|
+
s.summary = %q{Upload a batch of files to S3}
|
12
|
+
s.description = %q{Upload a batch of files to S3.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "s3-batch"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_runtime_dependency "aws-sdk"
|
22
|
+
s.add_runtime_dependency "thor"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: s3-batch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Simon Menke
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-29 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: aws-sdk
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: thor
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
description: Upload a batch of files to S3.
|
49
|
+
email:
|
50
|
+
- simon.menke@gmail.com
|
51
|
+
executables:
|
52
|
+
- s3-batch
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- .gitignore
|
59
|
+
- Gemfile
|
60
|
+
- Rakefile
|
61
|
+
- bin/s3-batch
|
62
|
+
- lib/s3-batch.rb
|
63
|
+
- lib/s3-batch/version.rb
|
64
|
+
- s3-batch.gemspec
|
65
|
+
homepage: http://github.com/fd
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project: s3-batch
|
94
|
+
rubygems_version: 1.8.6
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Upload a batch of files to S3
|
98
|
+
test_files: []
|
99
|
+
|