simple_sync 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 103aad0ffc5a90c307ccc0f9ed7c78a167978a72
4
+ data.tar.gz: 33655b87ce9d39722b5a4cc9a295b1d99d784587
5
+ SHA512:
6
+ metadata.gz: 3e0c8dcf91ff8d3e882aec76b402627d3230509e9170d1fe52c68eaafb1583564502c68bd9dacc9bc6baafbc430b3422c5ffa7caa7854fd0529e7068dc990013
7
+ data.tar.gz: 41c3dfb3b0b547cdac28190df1a5ef9eb1362e1475f83ca9820332327224717f45f78faaa5b72dfceee7d8cabb65ff76b7b4731b5fe7fafb956d2145ac2cf31d
data/.autotest ADDED
@@ -0,0 +1,8 @@
1
+ require 'autotest/fsevent'
2
+ require 'autotest/restart'
3
+
4
+ Autotest.add_hook :initialize do |autotest|
5
+ %w{test/test_destination}.each { |exception|
6
+ autotest.add_exception(exception)
7
+ }
8
+ end
data/.gitignore ADDED
@@ -0,0 +1,25 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ *.swp
24
+ test/test_destination/*
25
+ !test/test_destination/.keep
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0
4
+ - 2.1
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+ gem 'rsync'
3
+ gem 'rake'
4
+
5
+ group :development, :test do
6
+ gem 'minitest'
7
+ gem 'minitest-rg'
8
+ gem 'pry'
9
+ gem 'pry-nav'
10
+ gem 'autotest-standalone'
11
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Nathan Claburn
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,82 @@
1
+ # SimpleSync
2
+
3
+ A simple script that rsnycs the given list of files and directories to the specified output directory.
4
+
5
+ [![Build Status](https://travis-ci.org/nclaburn/simple_sync.svg?branch=master)](https://travis-ci.org/nclaburn/simple_sync)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'simple_sync'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install simple_sync
20
+
21
+ ## Configuration
22
+ SimpleSync looks in the current directory for a json configuration file named `.simple_sync`.
23
+
24
+ ### Example
25
+ ```json
26
+ { "configurations" : [
27
+ { "config" : {
28
+ "name" : "1st configuration",
29
+ "rsync" : "-azv",
30
+ "sources" : ["test/test_source/file1.txt", "test/test_source/file2.txt"],
31
+ "destination" : "test/test_destination/first_config/"
32
+ }},
33
+ { "config" : {
34
+ "name" : "2nd configuration",
35
+ "rsync" : "-azrv",
36
+ "rsync_suffix" : "2>&1",
37
+ "sources" : ["test/test_source/somedirectory"] ,
38
+ "destination" : "test/test_destination/second_config"
39
+ }},
40
+ { "config" : {
41
+ "name" : "ssh configuration",
42
+ "rsync" : "-azrv --recursive -e ssh -i /Users/someuser/.ssh/backup_server",
43
+ "sources" : ["test_source/file1.txt", "test_source/file2.txt", "test_source/somedirectory"] ,
44
+ "destination" : "someuser@backupserver:/BACKUP/personal"
45
+ }}
46
+ ]
47
+ }
48
+ ```
49
+
50
+ #### rsync
51
+ If the rsync configuration option is given it is passed unmodified to rsync.
52
+
53
+ #### rsync_suffix
54
+ The rsync_suffix option provides a method to redirect the rsync stdio
55
+
56
+ #### sources
57
+ A list of files and/or directories that are to be rsynced to a single directory
58
+
59
+ #### destination
60
+ A destination for the synced files
61
+
62
+ ## Usage
63
+
64
+ SimpleSync is meant to be run from cron or another script. To run it from the command line, simpley type in
65
+
66
+ `simple_sync`
67
+
68
+ SimpleSync can also be used as a library
69
+ ```ruby
70
+ require 'simple_sync'
71
+ sync = SimpleSync.new
72
+ sync.load_config
73
+ sync.copy_to_destination
74
+ ```
75
+
76
+ ## Contributing
77
+
78
+ 1. Fork it ( https://github.com/[my-github-username]/simple_sync/fork )
79
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
80
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
81
+ 4. Push to the branch (`git push origin my-new-feature`)
82
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'test/unit'
7
+ t.libs << 'lib'
8
+ #t.test_files = ['test/unit/simple_sync_test.rb']
9
+ t.test_files = ['test/unit/test_simple_sync.rb']
10
+ t.verbose = true
11
+ end
12
+
13
+ task default: :test
14
+
data/bin/simple_sync ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'simple_sync'
4
+ bs = SimpleSync.new
5
+ bs.load_config
6
+ bs.copy_to_destination
7
+
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rsync'
3
+ require 'json'
4
+
5
+ class SimpleSync
6
+ attr_reader :config_list
7
+ def initialize(config_file = nil)
8
+ @config_file = config_file.nil? ? '.simple_sync' : config_file
9
+ @config_list = {}
10
+ end
11
+
12
+ def read_config_from_file
13
+ if File.exists?(@config_file)
14
+ #puts "opening file #{@config_file}"
15
+ config = File.open(@config_file).read
16
+ elsif File.exists?(File.join(Dir.home, @config_file))
17
+ config = File.open(File.join(Dir.home, @config_file)).read
18
+ #puts "opening file #{File.join(Dir.home, @config_file)}"
19
+ else
20
+ #puts "opening environment #{ENV['BACKUP_SYNC']}"
21
+ return { status: 'error ', message: "could not find configuration file #{@config_file}" } unless ENV['BACKUP_SYNC']
22
+ return { status: 'error ', message: "could not find configuration file #{@config_file}" } unless File.exists?(ENV['BACKUP_SYNC'])
23
+ config = File.open(ENV['BACKUP_SYNC']).read
24
+ end
25
+ { status: 'success', config: config }
26
+ end
27
+
28
+ def load_config
29
+ configuration = read_config_from_file()
30
+ return configuration if configuration[:status] == 'error'
31
+ @config_list = JSON.parse(configuration[:config], symbolize_names: true)
32
+ return { status: 'success' }
33
+ end
34
+
35
+ def copy_to_destination
36
+ output = []
37
+ @config_list[:configurations].each { |config|
38
+ config[:config][:sources].each { |source|
39
+ #puts "Synching from #{source} to #{@config[:destination]}..."
40
+ #puts "rsync #{config[:config][:rsync]} --itemize-changes #{source} #{config[:config][:destination]} #{config[:config][:rsync_suffix]} "
41
+ output << IO.popen("rsync #{config[:config][:rsync]} --itemize-changes #{source} #{config[:config][:destination]} #{config[:config][:rsync_suffix]} ").read
42
+ }
43
+ }
44
+ { status: 'success', message: output }.to_json
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleSync
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,2 @@
1
+ require "simple_sync/version"
2
+ require 'simple_sync/simple_sync'
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_sync/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_sync"
8
+ spec.version = SimpleSync::VERSION
9
+ spec.authors = ["Nathan Claburn"]
10
+ spec.email = ["nathan.claburn@1st-edge.com"]
11
+ spec.summary = %q{A simple library for synching a given list of source files/directories to a specified output directory.}
12
+ spec.description = %q{A library for synching a given list of source files/directories to a specified output directory. The library wraps a call to rsync, which provide synchronization capabilities.}
13
+ spec.homepage = "http://github.com/nclaburn/simple_sync"
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_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~>10"
23
+ spec.add_development_dependency "pry", "~>0.9"
24
+ spec.add_development_dependency "pry-nav", "~>0.2"
25
+ spec.add_development_dependency "autotest-standalone", "~>4.4"
26
+
27
+ end
@@ -0,0 +1,16 @@
1
+ { "configurations" : [
2
+ { "config" : {
3
+ "name" : "1st configuration",
4
+ "rsync" : "-azv",
5
+ "sources" : ["test/test_source/file1.txt", "test/test_source/file2.txt"],
6
+ "destination" : "test/test_destination/first_config/"
7
+ }},
8
+ { "config" : {
9
+ "name" : "2nd configuration",
10
+ "rsync" : "-azrv",
11
+ "rsync_suffix" : "2>&1",
12
+ "sources" : ["test/test_source/somedirectory"] ,
13
+ "destination" : "test/test_destination/second_config"
14
+ }}
15
+ ]
16
+ }
@@ -0,0 +1,9 @@
1
+ { "configurations" : [
2
+ { "config" : {
3
+ "name" : "ssh configuration",
4
+ "rsync" : "-azrv --recursive -e ssh -i /Users/someuser/.ssh/backup_server",
5
+ "sources" : ["test_source/file1.txt", "test_source/file2.txt", "test_source/somedirectory"] ,
6
+ "destination" : "someuser@backupserver:/BACKUP/personal"
7
+ }}
8
+ ]
9
+ }
File without changes
@@ -0,0 +1,4 @@
1
+ require 'minitest'
2
+ require 'minitest/autorun'
3
+ require 'minitest/unit'
4
+ require 'minitest/rg'
@@ -0,0 +1 @@
1
+ file 1
@@ -0,0 +1 @@
1
+ file 2
@@ -0,0 +1,52 @@
1
+ require 'simple_sync/simple_sync'
2
+ require 'test_helper'
3
+ require 'pry'
4
+
5
+ class SimpleSyncTest < MiniTest::Test
6
+ include MiniTest::Assertions
7
+
8
+ MiniTest.after_run {
9
+ FileUtils.rm_rf(Dir.glob('test/test_destination/*'))
10
+ }
11
+
12
+ describe 'configuration' do
13
+ it 'locates the configuration file' do
14
+ sync = SimpleSync.new('test/ssh_configuration.json')
15
+ assert_respond_to(sync, :read_config_from_file)
16
+ config = sync.read_config_from_file
17
+ assert_equal('success', config[:status])
18
+ end
19
+
20
+ it 'loads configuration file' do
21
+ sync = SimpleSync.new('test/ssh_configuration.json')
22
+ assert_respond_to(sync, :load_config)
23
+ assert_equal({ status: 'success' }, sync.load_config)
24
+ configurations = sync.config_list
25
+ assert_equal("-azrv --recursive -e ssh -i /Users/someuser/.ssh/backup_server", configurations[:configurations][0][:config][:rsync])
26
+ assert_equal("ssh configuration", configurations[:configurations][0][:config][:name])
27
+
28
+ sync = SimpleSync.new('test/multiple_configurations.json')
29
+ assert_respond_to(sync, :load_config)
30
+ assert_equal({ status: 'success' }, sync.load_config)
31
+ configurations = sync.config_list
32
+
33
+ assert_equal("1st configuration", configurations[:configurations][0][:config][:name])
34
+ assert_equal("-azv", configurations[:configurations][0][:config][:rsync])
35
+ #assert_equal("2>&1", configurations[:configurations][0][:config][:rsync_suffix])
36
+
37
+ assert_equal("2nd configuration", configurations[:configurations][1][:config][:name])
38
+ assert_equal("-azrv", configurations[:configurations][1][:config][:rsync])
39
+ end
40
+
41
+ it 'copies source files/directories to destination directories' do
42
+ sync = SimpleSync.new('test/multiple_configurations.json')
43
+ assert_respond_to(sync, :copy_to_destination)
44
+ sync.load_config
45
+ sync.copy_to_destination
46
+ assert File.exists?('test/test_destination/first_config/file1.txt'), "file1.txt didn't exist"
47
+ assert File.exists?('test/test_destination/first_config/file2.txt'), "file2.txt didn't exist"
48
+ assert File.exists?('test/test_destination/second_config/somedirectory/dir1/another_file1.txt'), "another_file1.txt didn't exist"
49
+ assert File.exists?('test/test_destination/second_config/somedirectory/dir2/another_file2.txt'), "another_file1.txt didn't exist"
50
+ end
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_sync
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Claburn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-nav
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: autotest-standalone
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.4'
83
+ description: A library for synching a given list of source files/directories to a
84
+ specified output directory. The library wraps a call to rsync, which provide synchronization
85
+ capabilities.
86
+ email:
87
+ - nathan.claburn@1st-edge.com
88
+ executables:
89
+ - simple_sync
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - ".autotest"
94
+ - ".gitignore"
95
+ - ".ruby-version"
96
+ - ".travis.yml"
97
+ - Gemfile
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bin/simple_sync
102
+ - lib/simple_sync.rb
103
+ - lib/simple_sync/simple_sync.rb
104
+ - lib/simple_sync/version.rb
105
+ - simple_sync.gemspec
106
+ - test/multiple_configurations.json
107
+ - test/ssh_configuration.json
108
+ - test/test_destination/.keep
109
+ - test/test_helper.rb
110
+ - test/test_source/file1.txt
111
+ - test/test_source/file2.txt
112
+ - test/test_source/somedirectory/dir1/another_file1.txt
113
+ - test/test_source/somedirectory/dir2/another_file2.txt
114
+ - test/unit/test_simple_sync.rb
115
+ homepage: http://github.com/nclaburn/simple_sync
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.2.0
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: A simple library for synching a given list of source files/directories to
139
+ a specified output directory.
140
+ test_files:
141
+ - test/multiple_configurations.json
142
+ - test/ssh_configuration.json
143
+ - test/test_destination/.keep
144
+ - test/test_helper.rb
145
+ - test/test_source/file1.txt
146
+ - test/test_source/file2.txt
147
+ - test/test_source/somedirectory/dir1/another_file1.txt
148
+ - test/test_source/somedirectory/dir2/another_file2.txt
149
+ - test/unit/test_simple_sync.rb
150
+ has_rdoc: