s3poller 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "thor"
4
+ gem "fog"
5
+ gem "s3etag"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "rspec", "~> 2.13.0"
11
+ gem "rdoc", "~> 3.12"
12
+ gem "bundler", "~> 1.2.3"
13
+ gem "jeweler", "~> 1.8.4"
14
+ end
@@ -0,0 +1,56 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ builder (3.0.4)
5
+ diff-lcs (1.2.1)
6
+ excon (0.16.10)
7
+ fog (1.9.0)
8
+ builder
9
+ excon (~> 0.14)
10
+ formatador (~> 0.2.0)
11
+ mime-types
12
+ multi_json (~> 1.0)
13
+ net-scp (~> 1.0.4)
14
+ net-ssh (>= 2.1.3)
15
+ nokogiri (~> 1.5.0)
16
+ ruby-hmac
17
+ formatador (0.2.4)
18
+ git (1.2.5)
19
+ jeweler (1.8.4)
20
+ bundler (~> 1.0)
21
+ git (>= 1.2.5)
22
+ rake
23
+ rdoc
24
+ json (1.7.7)
25
+ mime-types (1.21)
26
+ multi_json (1.5.1)
27
+ net-scp (1.0.4)
28
+ net-ssh (>= 1.99.1)
29
+ net-ssh (2.6.5)
30
+ nokogiri (1.5.6)
31
+ rake (10.0.3)
32
+ rdoc (3.12.2)
33
+ json (~> 1.4)
34
+ rspec (2.13.0)
35
+ rspec-core (~> 2.13.0)
36
+ rspec-expectations (~> 2.13.0)
37
+ rspec-mocks (~> 2.13.0)
38
+ rspec-core (2.13.0)
39
+ rspec-expectations (2.13.0)
40
+ diff-lcs (>= 1.1.3, < 2.0)
41
+ rspec-mocks (2.13.0)
42
+ ruby-hmac (0.4.0)
43
+ s3etag (0.0.1)
44
+ thor (0.17.0)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ bundler (~> 1.2.3)
51
+ fog
52
+ jeweler (~> 1.8.4)
53
+ rdoc (~> 3.12)
54
+ rspec (~> 2.13.0)
55
+ s3etag
56
+ thor
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Erling Wegger Linde
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ = s3poller
2
+
3
+ Work in progres..
4
+
5
+ Use case: Legacy/proprietary app reads from a folder. Other app stores files in S3. Run this poller to pull down latest changes from S3 to local folder which legacy/proprietary app can then access..
6
+
7
+ == Contributing to s3poller
8
+
9
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
10
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
11
+ * Fork the project.
12
+ * Start a feature/bugfix branch.
13
+ * Commit and push until you are happy with your contribution.
14
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
15
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
16
+
17
+ == Copyright
18
+
19
+ Copyright (c) 2013 Erling Wegger Linde. See LICENSE.txt for
20
+ further details.
21
+
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "s3poller"
18
+ gem.homepage = "http://github.com/erlingwl/s3poller"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Poll and download from S3 to local folder}
21
+ gem.description = %Q{Poll and download from S3 to local folder}
22
+ gem.email = "erlingwl@gmail.com"
23
+ gem.authors = ["Erling Wegger Linde"]
24
+ gem.executables = ['s3poller']
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rdoc/task'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "s3poller #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require File.expand_path("../../lib/s3poller", __FILE__)
5
+ S3Poller::CLI.start
@@ -0,0 +1,9 @@
1
+ LIBRARY_PATH = File.join(File.dirname(__FILE__), 's3poller')
2
+
3
+ require File.join(LIBRARY_PATH, 'poller')
4
+ require File.join(LIBRARY_PATH, 'downloader')
5
+ require File.join(LIBRARY_PATH, 'cli')
6
+
7
+ module S3Poller
8
+
9
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ require 'thor'
4
+
5
+ module S3Poller
6
+ class CLI < Thor
7
+ include Thor::Actions
8
+
9
+
10
+ method_option :config_path, :type => :string, :required => true, :desc => "Path to fog config i.e. ~/aws.yml"
11
+ method_option :local_path, :type => :string, :required => true, :desc => "Path to local folder to sync to i.e. ~/localfolder"
12
+
13
+ desc 'poll', "Polls S3 once."
14
+ def poll
15
+ S3Poller::Poller.new(options[:config_path], options[:local_path]).poll
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,20 @@
1
+ module S3Poller
2
+
3
+ class Downloader
4
+
5
+ def initialize(local_path)
6
+ @local_path = local_path
7
+ end
8
+
9
+ def download(file)
10
+ local_file_path = "#{@local_path}#{file.key}"
11
+ dirname = File.dirname(local_file_path)
12
+ FileUtils.mkdir_p(dirname)
13
+ File.open(local_file_path, 'w') do |local_file|
14
+ local_file.write(file.body)
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,53 @@
1
+ require 'fog'
2
+ require 's3etag'
3
+
4
+ module S3Poller
5
+
6
+ class Poller
7
+
8
+ def initialize(config_path, local_path)
9
+ @local_path = local_path
10
+ @aws_config = YAML::load(File.open(config_path))
11
+ end
12
+
13
+ def poll
14
+ files_to_download.each do |file|
15
+ downloader.download(file)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def files_to_download
22
+ files.select do |file|
23
+ should_download?(file)
24
+ end
25
+ end
26
+
27
+ def files
28
+ bucket.files.inject([]) {|files, file| files << file; files}
29
+ end
30
+
31
+ def should_download?(file)
32
+ local_filename = "#{@local_path}#{file.key}"
33
+ return false if local_filename =~ /\/$/
34
+ return false if File.directory?(local_filename)
35
+ return true unless File.exist?(local_filename)
36
+ S3Etag.calc(:file => local_filename) != file.etag
37
+ end
38
+
39
+ def downloader
40
+ @downloader ||= Downloader.new(@local_path)
41
+ end
42
+
43
+ def bucket
44
+ connection.directories.get(@aws_config[:bucket])
45
+ end
46
+
47
+ def connection
48
+ @connection ||= Fog::Storage.new(@aws_config[:fog])
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,76 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "s3poller"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Erling Wegger Linde"]
12
+ s.date = "2013-03-04"
13
+ s.description = "Poll and download from S3 to local folder"
14
+ s.email = "erlingwl@gmail.com"
15
+ s.executables = ["s3poller"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/s3poller",
30
+ "lib/s3poller.rb",
31
+ "lib/s3poller/cli.rb",
32
+ "lib/s3poller/downloader.rb",
33
+ "lib/s3poller/poller.rb",
34
+ "s3poller.gemspec",
35
+ "spec/documents/subfolder/changed.txt",
36
+ "spec/documents/subfolder/test.txt",
37
+ "spec/integration/s3poller_spec.rb",
38
+ "spec/spec_helper.rb"
39
+ ]
40
+ s.homepage = "http://github.com/erlingwl/s3poller"
41
+ s.licenses = ["MIT"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = "1.8.11"
44
+ s.summary = "Poll and download from S3 to local folder"
45
+
46
+ if s.respond_to? :specification_version then
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<thor>, [">= 0"])
51
+ s.add_runtime_dependency(%q<fog>, [">= 0"])
52
+ s.add_runtime_dependency(%q<s3etag>, [">= 0"])
53
+ s.add_development_dependency(%q<rspec>, ["~> 2.13.0"])
54
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_development_dependency(%q<bundler>, ["~> 1.2.3"])
56
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
57
+ else
58
+ s.add_dependency(%q<thor>, [">= 0"])
59
+ s.add_dependency(%q<fog>, [">= 0"])
60
+ s.add_dependency(%q<s3etag>, [">= 0"])
61
+ s.add_dependency(%q<rspec>, ["~> 2.13.0"])
62
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.2.3"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
65
+ end
66
+ else
67
+ s.add_dependency(%q<thor>, [">= 0"])
68
+ s.add_dependency(%q<fog>, [">= 0"])
69
+ s.add_dependency(%q<s3etag>, [">= 0"])
70
+ s.add_dependency(%q<rspec>, ["~> 2.13.0"])
71
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
72
+ s.add_dependency(%q<bundler>, ["~> 1.2.3"])
73
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
74
+ end
75
+ end
76
+
@@ -0,0 +1,3 @@
1
+ changed
2
+
3
+ it changed..
@@ -0,0 +1,3 @@
1
+ This is a test document
2
+
3
+ Yup..
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe S3Poller::Poller do
4
+
5
+ let(:local_tmp_path) { "#{File.expand_path(File.dirname(__FILE__) + '/../tmp')}/" }
6
+ let(:config_path) { "#{File.dirname(__FILE__)}/../integration_config/aws.yml" }
7
+ let(:tmp_poller) { S3Poller::Poller.new(config_path, local_tmp_path) }
8
+
9
+ it "should download the files" do
10
+ FileUtils.remove_dir("#{local_tmp_path}subfolder", true)
11
+ tmp_poller.poll
12
+ File.exists?("#{local_tmp_path}subfolder/changed.txt").should == true
13
+ File.exists?("#{local_tmp_path}subfolder/new.txt").should == true
14
+ File.exists?("#{local_tmp_path}subfolder/test.txt").should == true
15
+ end
16
+
17
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib', 's3poller'))
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ require 'rspec'
5
+ require 's3poller'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: s3poller
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Erling Wegger Linde
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: &70117057306980 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70117057306980
25
+ - !ruby/object:Gem::Dependency
26
+ name: fog
27
+ requirement: &70117057352620 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70117057352620
36
+ - !ruby/object:Gem::Dependency
37
+ name: s3etag
38
+ requirement: &70117057351000 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70117057351000
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &70117057349780 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.13.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70117057349780
58
+ - !ruby/object:Gem::Dependency
59
+ name: rdoc
60
+ requirement: &70117057348400 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '3.12'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70117057348400
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: &70117057344880 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.2.3
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70117057344880
80
+ - !ruby/object:Gem::Dependency
81
+ name: jeweler
82
+ requirement: &70117057267820 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 1.8.4
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70117057267820
91
+ description: Poll and download from S3 to local folder
92
+ email: erlingwl@gmail.com
93
+ executables:
94
+ - s3poller
95
+ extensions: []
96
+ extra_rdoc_files:
97
+ - LICENSE.txt
98
+ - README.rdoc
99
+ files:
100
+ - .document
101
+ - .rspec
102
+ - Gemfile
103
+ - Gemfile.lock
104
+ - LICENSE.txt
105
+ - README.rdoc
106
+ - Rakefile
107
+ - VERSION
108
+ - bin/s3poller
109
+ - lib/s3poller.rb
110
+ - lib/s3poller/cli.rb
111
+ - lib/s3poller/downloader.rb
112
+ - lib/s3poller/poller.rb
113
+ - s3poller.gemspec
114
+ - spec/documents/subfolder/changed.txt
115
+ - spec/documents/subfolder/test.txt
116
+ - spec/integration/s3poller_spec.rb
117
+ - spec/spec_helper.rb
118
+ homepage: http://github.com/erlingwl/s3poller
119
+ licenses:
120
+ - MIT
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ segments:
132
+ - 0
133
+ hash: -465110537722511511
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 1.8.11
143
+ signing_key:
144
+ specification_version: 3
145
+ summary: Poll and download from S3 to local folder
146
+ test_files: []