simple_s3 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/lib/simple_s3/version.rb +3 -0
- data/lib/simple_s3.rb +61 -0
- data/simple_s3.gemspec +23 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/lib/simple_s3.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'aws/s3'
|
2
|
+
require 'find'
|
3
|
+
|
4
|
+
module SimpleS3
|
5
|
+
class S3
|
6
|
+
|
7
|
+
attr_accessor :verbose
|
8
|
+
|
9
|
+
def initialize(access_key, secret_key)
|
10
|
+
connect! access_key, secret_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def store(local, remote_dir, bucket, options = {})
|
14
|
+
# TODO better error handling
|
15
|
+
return unless File.exists?(local)
|
16
|
+
|
17
|
+
paths = File.directory?(local) ? paths = paths(local) : paths = [local]
|
18
|
+
paths.each do |path|
|
19
|
+
destination = remote_path_for(path, remote_dir, options[:baseline])
|
20
|
+
unless AWS::S3::S3Object.exists?(destination, bucket) || options[:test]
|
21
|
+
log "Storing #{destination}" if verbose
|
22
|
+
|
23
|
+
AWS::S3::S3Object.store(destination, open(path), bucket)
|
24
|
+
if options[:delete_source] && AWS::S3::S3Object.exists?(destination, bucket)
|
25
|
+
File.delete(path)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# given a path, e.g. test/unit/ or /test/unit/file.rb, and a remote
|
34
|
+
# root, e.g. backup/files/, generates a remote path like
|
35
|
+
# /backup/files/test/unit
|
36
|
+
def remote_path_for(path, remote, baseline)
|
37
|
+
dest_path = baseline ? File.basename(path) : path
|
38
|
+
(remote + '/' + dest_path).gsub(/\/+/, '/')
|
39
|
+
end
|
40
|
+
|
41
|
+
def paths(local)
|
42
|
+
paths = []
|
43
|
+
Find.find(local) do |path|
|
44
|
+
next if !File.file?(path) || path == local
|
45
|
+
paths << path
|
46
|
+
end
|
47
|
+
paths
|
48
|
+
end
|
49
|
+
|
50
|
+
def log(msg)
|
51
|
+
puts "#{Time.now.strftime("%a %b %d %Y %H:%M:%S %Z")} [SimpleS3::S3]: #{msg}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def connect!(access_key, secret_key)
|
55
|
+
AWS::S3::Base.establish_connection!(
|
56
|
+
:access_key_id => access_key,
|
57
|
+
:secret_access_key => secret_key
|
58
|
+
)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/simple_s3.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "simple_s3/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "simple_s3"
|
7
|
+
s.version = SimpleS3::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Olly Headey"]
|
10
|
+
s.email = ["olly@freeagent.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Super-simple file/directory upload to Amazon S3}
|
13
|
+
s.description = %q{Super-simple file/directory upload to Amazon S3}
|
14
|
+
|
15
|
+
s.add_dependency('aws-s3')
|
16
|
+
|
17
|
+
s.rubyforge_project = "simple_s3"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_s3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Olly Headey
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-27 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: aws-s3
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Super-simple file/directory upload to Amazon S3
|
36
|
+
email:
|
37
|
+
- olly@freeagent.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- Rakefile
|
48
|
+
- lib/simple_s3.rb
|
49
|
+
- lib/simple_s3/version.rb
|
50
|
+
- simple_s3.gemspec
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: ""
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project: simple_s3
|
81
|
+
rubygems_version: 1.5.2
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Super-simple file/directory upload to Amazon S3
|
85
|
+
test_files: []
|
86
|
+
|