s3rsync 0.1.3

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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MjAyMmU2ZDVkNmM1YTdlNDdjOWNhYWZjY2FhN2U4MzJiY2I2MzRmZg==
5
+ data.tar.gz: !binary |-
6
+ YTkzYzFjNWFkYWE1MTk3NzRjMmYxY2Y0ZjU5MWE4MTY1Yzk3NWNmNg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ N2UxNTc0ZGNmZTE5ODkyNzcwYzE1NzczMGY0ZDM0MjM4MjJmOWM0YzVhZmM4
10
+ YzIyM2Q5OWU0MjU3OTI0YWM0NGE1MGZlZGMzZDdlNmMxN2MzYjNmYWQ0ZjUz
11
+ OGFjOGZiYjJhOWU1Yzg3N2Q5Y2FiOWU1NjI2N2Y5MWE4MDBjMWE=
12
+ data.tar.gz: !binary |-
13
+ OTE3NjU4MWQ2YWY0ZTJlNDVjMWU2Nzk0ZTk1NGRkYTlkOWYyNzQ0ZjNhMjYw
14
+ ZDNjMjlhYTJlYzJkNjBjNzEzOGRmNTI5YTZkYTA1YzQyNmUwNTNhYzBkN2Mx
15
+ NDFkMDdhODBjYWVlNmY1MDgyN2ZkYmVhNTJlMmFjMDY5MWM1MDU=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.2
5
+ deploy:
6
+ provider: rubygems
7
+ api_key:
8
+ secure: O4vHRY7yoWgWpcp+dTqFwVjGSjeYnGDFbRbvgfjxbSWxIGhtD3HbuUm62ncb83IIr7eCTqIQkYXGsndvsd5k3m4xJhJA8rkxPWri/B+ZdOqwSChov65Raf1I+gUW/ZAgfyMvFBlNB4jEPFe46eL/2N1AQtLDeq1ZdJaUwYC2dew=
9
+ gem: s3rsync
10
+ on:
11
+ all_branches: true
12
+ tags: true
13
+ repo: idevops/s3rsync
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in s3rsync.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ #notification :gntp
2
+ notification :growl
3
+
4
+ guard :rspec, cmd: 'bundle exec rspec' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/s3rsync/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch('lib/s3rsync.rb') { "spec" }
8
+ watch('spec/spec_helper.rb') { "spec" }
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Innovid Ltd.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # S3rsync
2
+
3
+ ============================================
4
+ [![Gem Version](http://img.shields.io/gem/v/s3rsync.svg)][gem]
5
+ [![Build Status](http://img.shields.io/travis/idevops/s3rsync.svg)][travis]
6
+
7
+ [gem]: https://rubygems.org/gems/s3rsync
8
+ [travis]: http://travis-ci.org/idevops/s3rsync
9
+
10
+ Wrapper gem to sync files with s3cmd tool
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 's3rsync'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install s3rsync
25
+
26
+ ## Usage
27
+
28
+ TODO: Write usage instructions here
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it ( http://github.com/<my-github-username>/s3rsync/fork )
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => [:spec]
4
+ desc 'run Rspec specs'
5
+ task :spec do
6
+ sh 'rspec spec'
7
+ end
8
+
data/bin/s3rsync ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 's3rsync/cli'
4
+ S3Rsync::CLI.start
@@ -0,0 +1,32 @@
1
+ require 'logger'
2
+
3
+ module S3Rsync
4
+ class Base
5
+ def init_logger
6
+ logger = Logger.new(STDOUT)
7
+ logger.level = (!ENV['DEBUG'].nil?) ? Logger::DEBUG : Logger::INFO
8
+ logger.debug "logger.level: #{logger.level}"
9
+ logger
10
+ end
11
+
12
+ def error_exit(msg)
13
+ @log.error msg
14
+ return 1
15
+ end
16
+
17
+ def pass_cli(cmd, valid_out_pattern = nil)
18
+ cmd += ' 2>&1'
19
+ @log.debug "running cmd: #{cmd}"
20
+ cmd_out = `#{cmd}`
21
+ success_exec = $?.success?
22
+ @log.info "cmd_out: #{cmd_out}"
23
+ @log.debug "success_exec: #{success_exec}"
24
+
25
+ valid_content = valid_out_pattern.nil? ? true : !cmd_out.match(/#{valid_out_pattern}/).nil?
26
+ @log.debug "valid_content: #{valid_content}"
27
+
28
+ error_exit "Not successful execution or not valid_content! out: #{cmd_out}" if (!success_exec || !valid_content)
29
+ cmd_out
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ require 'thor'
2
+
3
+ module S3Rsync
4
+ class CLI < Thor
5
+ DEFAULT_SETTINGS = {
6
+ :lock_file_path => "default",
7
+ }
8
+
9
+ desc "upload", "Upload"
10
+ method_option :dir, :aliases => "-d", :required => true
11
+ method_option :config_path, :aliases => "-c", :required => true
12
+ method_option :s3_prefix, :aliases => "-p", :default => 's3rsync'
13
+ def upload
14
+ require 's3rsync/sync'
15
+ sync = Sync.new(options)
16
+ sync.run(:upload)
17
+ end
18
+
19
+ desc "download", "Download"
20
+ method_option :dir, :aliases => "-d", :required => true
21
+ method_option :config_path, :aliases => "-c", :required => true
22
+ method_option :s3_prefix, :aliases => "-p", :default => 's3rsync'
23
+ def download
24
+ require 's3rsync/sync'
25
+ sync = Sync.new(options)
26
+ sync.run(:download)
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,53 @@
1
+ require "s3rsync"
2
+ require "json"
3
+
4
+ module S3Rsync
5
+ class Sync < Base
6
+
7
+ def initialize(opt)
8
+ @log = init_logger
9
+ @log.debug "opt: #{opt.inspect}"
10
+ @params = {}
11
+ @params[:dir] = opt['dir']
12
+ @params[:s3_prefix] = opt['s3_prefix']
13
+ @params[:config_path] = opt['config_path']
14
+ @s3cmd = 's3cmd'
15
+
16
+ @log.debug "@params[:config_path]: #{@params[:config_path]}"
17
+ begin
18
+ conf = JSON.parse File.read(@params[:config_path])
19
+ rescue Exception => e
20
+ mgs = "ERROR: opening or parsing config file failed: #{e.inspect}"
21
+ @log.error mgs
22
+ raise mgs
23
+ exit 1
24
+ end
25
+
26
+ @log.debug "conf: #{conf}"
27
+ @params[:s3_bucket] = conf['env.static.s3.bucket']
28
+ @params[:s3_access] = conf['env.static.s3.key.user']
29
+ @params[:s3_secret] = conf['env.static.s3.key.secret']
30
+ @log.debug "@params: #{@params.inspect}"
31
+ end
32
+
33
+ def run(mode = :upload)
34
+ sync_locations = "#{@params[:dir]} s3://#{@params[:s3_bucket]}/#{@params[:s3_prefix]}/"
35
+ @log.debug "original sync_locations: #{sync_locations}"
36
+ if mode == :download
37
+ @log.debug "reversing sync_locations"
38
+ sync_locations = sync_locations.split(' ').reverse.join(' ')
39
+ @log.debug "download sync_locations: #{sync_locations}"
40
+ end
41
+ sync_output = pass_cli "s3cmd sync #{sync_locations}"
42
+ @log.debug "sync_output: #{sync_output}"
43
+ if (sync_output == 1) || sync_output.downcase.include?('error')
44
+ @log.error "errors found in output: #{sync_output}"
45
+ return 1
46
+ else
47
+ return 0
48
+ end
49
+ end
50
+
51
+ end
52
+ end
53
+
@@ -0,0 +1,3 @@
1
+ module S3rsync
2
+ VERSION = "0.1.3"
3
+ end
data/lib/s3rsync.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "s3rsync/version"
2
+ require "s3rsync/base"
3
+
4
+ module S3rsync
5
+
6
+ end
7
+
data/s3rsync.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 's3rsync/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "s3rsync"
8
+ spec.version = S3rsync::VERSION
9
+ spec.authors = ["idevops"]
10
+ spec.email = ["devops@innovid.com"]
11
+ spec.summary = "Remote update protocol between local set of files and S3 storage"
12
+ spec.description = "Remote update protocol allows sync files to transfer just the differences between two sets of files across the network connection between local filesystem and s3 storage"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "thor", "0.19.1"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "bump"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency "growl"
29
+ spec.add_development_dependency "guard"
30
+ spec.add_development_dependency "guard-rspec"
31
+ end
@@ -0,0 +1,12 @@
1
+ require "simplecov"
2
+ require "s3rsync"
3
+ require "s3rsync/base"
4
+
5
+ SimpleCov.start do
6
+ add_filter '/spec/'
7
+ add_filter '/bin/'
8
+ end# if ENV["COVERAGE"]
9
+
10
+ module Helpers
11
+
12
+ end
data/spec/sync_spec.rb ADDED
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 's3rsync/sync'
3
+
4
+ include Helpers
5
+
6
+ describe S3Rsync::Sync do
7
+ context 'sync is successfull' do
8
+ let(:opt) { {
9
+ 'dir' => '/test_dir',
10
+ 's3_prefix' => 's3rsync',
11
+ 'config_path' => 'test_json_conf_path',
12
+ } }
13
+
14
+ let(:json_conf) { {
15
+ 'env.static.s3.bucket' => 'test-bucket',
16
+ 'env.static.s3.key.user' => 'test_access_key',
17
+ 'env.static.s3.key.secret' => 'test_secret_key',
18
+ } }
19
+
20
+ before do
21
+ allow(File).to receive(:read).and_return(nil)
22
+ allow(File).to receive(:read).with(opt['config_path']).and_return(json_conf.to_json)
23
+ allow_any_instance_of(S3Rsync::Sync).to receive(:pass_cli).and_return(nil)
24
+ end
25
+
26
+ after do
27
+ #
28
+ end
29
+
30
+ before(:each) do
31
+ #Helpers::pre_run_helper
32
+ end
33
+
34
+ it "uploads the files" do
35
+ cmd = "s3cmd sync #{opt['dir']} s3://#{json_conf['env.static.s3.bucket']}/#{opt['s3_prefix']}/"
36
+ allow_any_instance_of(S3Rsync::Sync).to receive(:pass_cli).with(cmd).and_return('Success')
37
+
38
+ sync = S3Rsync::Sync.new(opt)
39
+ expect(sync.run(:upload)).to eq 0
40
+ end
41
+
42
+ it "download the files" do
43
+ cmd = "s3cmd sync s3://#{json_conf['env.static.s3.bucket']}/#{opt['s3_prefix']}/ #{opt['dir']}"
44
+ allow_any_instance_of(S3Rsync::Sync).to receive(:pass_cli).with(cmd).and_return('Success')
45
+
46
+ sync = S3Rsync::Sync.new(opt)
47
+ expect(sync.run(:download)).to eq 0
48
+ end
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: s3rsync
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - idevops
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bump
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: growl
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Remote update protocol allows sync files to transfer just the differences
140
+ between two sets of files across the network connection between local filesystem
141
+ and s3 storage
142
+ email:
143
+ - devops@innovid.com
144
+ executables:
145
+ - s3rsync
146
+ extensions: []
147
+ extra_rdoc_files: []
148
+ files:
149
+ - .gitignore
150
+ - .travis.yml
151
+ - Gemfile
152
+ - Guardfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - bin/s3rsync
157
+ - lib/s3rsync.rb
158
+ - lib/s3rsync/base.rb
159
+ - lib/s3rsync/cli.rb
160
+ - lib/s3rsync/sync.rb
161
+ - lib/s3rsync/version.rb
162
+ - s3rsync.gemspec
163
+ - spec/spec_helper.rb
164
+ - spec/sync_spec.rb
165
+ homepage: ''
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ! '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ! '>='
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.3.0
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Remote update protocol between local set of files and S3 storage
189
+ test_files:
190
+ - spec/spec_helper.rb
191
+ - spec/sync_spec.rb