rr_publish 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 +7 -0
- data/.gitignore +19 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/lib/rr_publish/version.rb +3 -0
- data/lib/rr_publish.rb +96 -0
- data/rr_publish.gemspec +23 -0
- data/spec/fixtures/config.yml +27 -0
- data/spec/fixtures/destination/.gitkeep +0 -0
- data/spec/fixtures/source/1.txt +1 -0
- data/spec/fixtures/source/2.txt +1 -0
- data/spec/fixtures/source/3.txt +1 -0
- data/spec/rr_publish_spec.rb +58 -0
- data/spec/spec_helper.rb +3 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8bc7ae9b808308b60eee09d461e09d890d76147f
|
4
|
+
data.tar.gz: 0168b47eee0e3b73905be7fe8a1d8408f34e8bab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d7d02608ae40f97d8603363031a4031b6f4482b0a2706ba8522f67f6647590fc223d1c02d6c670a5405d47881f4d8c4b43855c2461a8c25fee6f6c4195771641
|
7
|
+
data.tar.gz: 06f4e2c630d640cdf0cefb673fe3c965892b6b3b640e4c827b0306b2005d79cfdd0fc3474d3a5675df3a7bad4d34068bcdae42780cf1f750e76ea5fafa9743f3
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Winton Welsh
|
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,31 @@
|
|
1
|
+
# rr_publish
|
2
|
+
|
3
|
+
Used for Rubber Ring publishing.
|
4
|
+
|
5
|
+
this is the fork of original [rbackup](https://github.com/winton/rbackup) from Winton Welsh. Thanks!
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'rr_publish', :git => 'TODO'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Create YAML file like this
|
20
|
+
|
21
|
+
site:
|
22
|
+
server:
|
23
|
+
source: /Users/me/site
|
24
|
+
destination: deploy@server:/var/www
|
25
|
+
exclude:
|
26
|
+
- .git
|
27
|
+
- /site/config/database.yml
|
28
|
+
|
29
|
+
Run the code with path to the YAML file
|
30
|
+
|
31
|
+
RRPublish::Sync.new('path/to/yaml').run
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/rr_publish.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module RRPublish
|
4
|
+
class Sync
|
5
|
+
|
6
|
+
attr_accessor :profiles
|
7
|
+
|
8
|
+
def initialize(yaml_file, *args)
|
9
|
+
yaml_hash = load_yaml(yaml_file)
|
10
|
+
get_profiles(args, yaml_hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
def load_yaml(yaml_file)
|
14
|
+
if File.exists?(yaml_file)
|
15
|
+
YAML::load(File.open(yaml_file))
|
16
|
+
else
|
17
|
+
error 'YAML configuration not found.'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_profiles(input, hash, force=false)
|
22
|
+
@profiles ||= []
|
23
|
+
hash.each do |key, value|
|
24
|
+
next unless value.respond_to?(:keys)
|
25
|
+
is_profile = value['source'] && value['destination']
|
26
|
+
if input.include?(key) || input.empty? || force
|
27
|
+
if is_profile
|
28
|
+
@profiles << value
|
29
|
+
else
|
30
|
+
get_profiles(input, value, true)
|
31
|
+
end
|
32
|
+
elsif !is_profile
|
33
|
+
get_profiles(input, value, force)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def esc(paths)
|
39
|
+
paths = [ paths ].flatten
|
40
|
+
paths.collect { |path| path.gsub(' ', '\ ') }.join(' ')
|
41
|
+
end
|
42
|
+
|
43
|
+
def rsync(profile)
|
44
|
+
inc1ude = []
|
45
|
+
exclude = []
|
46
|
+
destination = profile['destination']
|
47
|
+
source = profile['source']
|
48
|
+
|
49
|
+
options = "--numeric-ids --safe-links -axzSvL"
|
50
|
+
# --numeric-ids don't map uid/gid values by user/group name
|
51
|
+
# --safe-links ignore symlinks that point outside the tree
|
52
|
+
# -a, --archive recursion and preserve almost everything (-rlptgoD)
|
53
|
+
# -x, --one-file-system don't cross filesystem boundaries
|
54
|
+
# -z, --compress compress file data during the transfer
|
55
|
+
# -S, --sparse handle sparse files efficiently
|
56
|
+
# -v, --verbose verbose
|
57
|
+
|
58
|
+
if profile['delete'].nil? || profile['delete']
|
59
|
+
options = "--delete " + options
|
60
|
+
# --delete delete extraneous files from dest dirs
|
61
|
+
end
|
62
|
+
|
63
|
+
if destination.include?(':') || source.include?(':')
|
64
|
+
options += ' -e ssh'
|
65
|
+
# -e, --rsh=COMMAND specify the remote shell to use
|
66
|
+
else
|
67
|
+
options += 'E'
|
68
|
+
# -E, --extended-attributes copy extended attributes, resource forks
|
69
|
+
FileUtils.mkdir_p destination
|
70
|
+
end
|
71
|
+
|
72
|
+
if profile['include']
|
73
|
+
exclude = %w(*) unless profile['exclude']
|
74
|
+
inc1ude = [ profile['include'] ].flatten
|
75
|
+
end
|
76
|
+
|
77
|
+
if profile['exclude']
|
78
|
+
exclude += [ profile['exclude'] ].flatten
|
79
|
+
end
|
80
|
+
|
81
|
+
inc1ude = inc1ude.collect { |i| "--include='#{i}'" }.join(' ')
|
82
|
+
exclude = exclude.collect { |e| "--exclude='#{e}'" }.join(' ')
|
83
|
+
# --exclude=PATTERN use one of these for each file you want to exclude
|
84
|
+
# --include-from=FILE don't exclude patterns listed in FILE
|
85
|
+
|
86
|
+
cmd = "rsync #{options} #{inc1ude} #{exclude} #{esc(source)} #{esc(destination)}"
|
87
|
+
`#{cmd}`
|
88
|
+
end
|
89
|
+
|
90
|
+
def run
|
91
|
+
@profiles.each do |profile|
|
92
|
+
rsync(profile)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/rr_publish.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rr_publish/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rr_publish'
|
8
|
+
spec.version = RRPublish::VERSION
|
9
|
+
spec.authors = ['Winton Welsh', 'zigomir']
|
10
|
+
spec.email = ['mail@wintoni.us, zigomir@gmail.com']
|
11
|
+
spec.description = %q{Rysnc your files with simple YAML file.}
|
12
|
+
spec.summary = %q{Simple Ruby Rsync}
|
13
|
+
spec.homepage = 'http://github.com/zigomir/rr_publish'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
profile_1:
|
2
|
+
source: spec/fixtures/source/*
|
3
|
+
destination: spec/fixtures/destination
|
4
|
+
exclude: 1.txt
|
5
|
+
profile_2:
|
6
|
+
source: spec/fixtures/source/*
|
7
|
+
destination: spec/fixtures/destination
|
8
|
+
exclude: 2.txt
|
9
|
+
profile_3:
|
10
|
+
profile_4:
|
11
|
+
source: spec/fixtures/source/*
|
12
|
+
destination: spec/fixtures/destination
|
13
|
+
exclude:
|
14
|
+
- 1.txt
|
15
|
+
- 2.txt
|
16
|
+
profile_5:
|
17
|
+
source: spec/fixtures/source/*
|
18
|
+
destination: spec/fixtures/destination
|
19
|
+
exclude:
|
20
|
+
- 1.txt
|
21
|
+
- 3.txt
|
22
|
+
profile_6:
|
23
|
+
source: spec/fixtures/source/*
|
24
|
+
destination: spec/fixtures/destination
|
25
|
+
include:
|
26
|
+
- 2.txt
|
27
|
+
- 3.txt
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
1
|
@@ -0,0 +1 @@
|
|
1
|
+
2
|
@@ -0,0 +1 @@
|
|
1
|
+
3
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RRPublish do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
$config = SPEC + '/fixtures/config.yml'
|
7
|
+
Dir[SPEC + '/fixtures/destination/*.txt'].each do |path|
|
8
|
+
FileUtils.rm_rf(path)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should backup all profiles' do
|
13
|
+
RRPublish::Sync.new($config).run
|
14
|
+
File.exists?(SPEC + '/fixtures/destination/1.txt').should == true
|
15
|
+
File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
|
16
|
+
File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
|
17
|
+
File.read(SPEC + '/fixtures/destination/1.txt').should == '1'
|
18
|
+
File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
|
19
|
+
File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should backup profile_1' do
|
23
|
+
RRPublish::Sync.new($config, 'profile_1').run
|
24
|
+
File.exists?(SPEC + '/fixtures/destination/1.txt').should == false
|
25
|
+
File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
|
26
|
+
File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
|
27
|
+
File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
|
28
|
+
File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should backup profile_2' do
|
32
|
+
RRPublish::Sync.new($config, 'profile_2').run
|
33
|
+
File.exists?(SPEC + '/fixtures/destination/1.txt').should == true
|
34
|
+
File.exists?(SPEC + '/fixtures/destination/2.txt').should == false
|
35
|
+
File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
|
36
|
+
File.read(SPEC + '/fixtures/destination/1.txt').should == '1'
|
37
|
+
File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should backup profile_3' do
|
41
|
+
RRPublish::Sync.new($config, 'profile_3').run
|
42
|
+
File.exists?(SPEC + '/fixtures/destination/1.txt').should == false
|
43
|
+
File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
|
44
|
+
File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
|
45
|
+
File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
|
46
|
+
File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should backup profile_6' do
|
50
|
+
RRPublish::Sync.new($config, 'profile_6').run
|
51
|
+
File.exists?(SPEC + '/fixtures/destination/1.txt').should == false
|
52
|
+
File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
|
53
|
+
File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
|
54
|
+
File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
|
55
|
+
File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rr_publish
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Winton Welsh
|
8
|
+
- zigomir
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.3'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.3'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
description: Rysnc your files with simple YAML file.
|
43
|
+
email:
|
44
|
+
- mail@wintoni.us, zigomir@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- .rspec
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/rr_publish.rb
|
56
|
+
- lib/rr_publish/version.rb
|
57
|
+
- rr_publish.gemspec
|
58
|
+
- spec/fixtures/config.yml
|
59
|
+
- spec/fixtures/destination/.gitkeep
|
60
|
+
- spec/fixtures/source/1.txt
|
61
|
+
- spec/fixtures/source/2.txt
|
62
|
+
- spec/fixtures/source/3.txt
|
63
|
+
- spec/rr_publish_spec.rb
|
64
|
+
- spec/spec_helper.rb
|
65
|
+
homepage: http://github.com/zigomir/rr_publish
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.0.0
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Simple Ruby Rsync
|
89
|
+
test_files:
|
90
|
+
- spec/fixtures/config.yml
|
91
|
+
- spec/fixtures/destination/.gitkeep
|
92
|
+
- spec/fixtures/source/1.txt
|
93
|
+
- spec/fixtures/source/2.txt
|
94
|
+
- spec/fixtures/source/3.txt
|
95
|
+
- spec/rr_publish_spec.rb
|
96
|
+
- spec/spec_helper.rb
|