rdiff-simple 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +0 -12
- data/README.md +23 -1
- data/Rakefile +2 -2
- data/lib/rdiff_simple.rb +4 -3
- data/lib/rdiff_simple/options_parser.rb +17 -0
- data/lib/rdiff_simple/rdiff_backup.rb +9 -11
- data/lib/rdiff_simple/version.rb +1 -1
- data/rdiff-simple.gemspec +7 -0
- data/spec/lib/rdiff_simple/options_parser_spec.rb +27 -0
- data/spec/lib/rdiff_simple/rdiff_backup_spec.rb +10 -51
- data/spec/spec_helper.rb +1 -2
- metadata +81 -19
- data/lib/rdiff_simple/commands.rb +0 -6
- data/lib/rdiff_simple/errors.rb +0 -3
- data/lib/rdiff_simple/exit_codes.rb +0 -5
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 15b76630f1141cfacad11232d8406ba3b4d72d92
|
4
|
+
data.tar.gz: e6662d1deeed21bbaf612dd7f738dad38cef680b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 949f2b75133ac93f0e5945e7279f020b4917cfa2ee7cf3c35ab7cfe372d43668300f620f1ac8f76438aca75d1bae45dd52f5c2d81f913398395b5d83d8fa5883
|
7
|
+
data.tar.gz: 4007f8fb8fda98a34f063214ae65bf87d2b2cb2ff7e99fe2e3d1a12bbceb44a2061f7988b809a1139f556733b65ffda5878e57b753ba7c47e3c317e961e675ae
|
data/Gemfile
CHANGED
@@ -1,15 +1,3 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
# Specify your gem's dependencies in rdiff-simple.gemspec
|
4
3
|
gemspec
|
5
|
-
|
6
|
-
group :development, :test do
|
7
|
-
gem "rake"
|
8
|
-
gem "rspec", "~> 2"
|
9
|
-
gem "coveralls"
|
10
|
-
end
|
11
|
-
|
12
|
-
group :development do
|
13
|
-
gem "bundler", "~> 1.3"
|
14
|
-
gem "guard-rspec"
|
15
|
-
end
|
data/README.md
CHANGED
@@ -16,12 +16,34 @@ A simple wrapper around rdiff-backup
|
|
16
16
|
|
17
17
|
$ gem install rdiff-simple
|
18
18
|
|
19
|
+
## Quick Start
|
20
|
+
|
21
|
+
In your file:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'rdiff_simple'
|
25
|
+
|
26
|
+
backup = RdiffSimple::RdiffBackup.new
|
27
|
+
backup.execute('/source', '/destination', :print_statistics, exclude: '/source/private')
|
28
|
+
```
|
29
|
+
|
19
30
|
## Usage
|
20
31
|
|
21
|
-
|
32
|
+
Arguments Order is:
|
33
|
+
|
34
|
+
- `source`
|
35
|
+
- `destination`
|
36
|
+
- `flag options like --exclude-other-filesystems`
|
37
|
+
- `hash arguments like --exclude /usr/bin`
|
38
|
+
|
39
|
+
All multi-word symbols should be converted to underscores: `--exclude-other-filesystems` becomes `:exclude_other_filesystems`.
|
40
|
+
|
41
|
+
The `execute` method will return the exit code from rdiff-backup. In order to get the output from rdiff-backup pass in a [`Logger`][logger] to [`RdiffBackup.new`][new].
|
22
42
|
|
23
43
|
## License
|
24
44
|
|
25
45
|
Released under the MIT License. See the [LICENSE][] file for further details.
|
26
46
|
|
27
47
|
[license]: LICENSE.txt
|
48
|
+
[logger]: http://www.ruby-doc.org/stdlib-2.0.0/libdoc/logger/rdoc/Logger.html
|
49
|
+
[new]: http://rubydoc.info/github/ketiko/rdiff-simple/master/RdiffSimple/RdiffBackup#initialize-instance_method
|
data/Rakefile
CHANGED
data/lib/rdiff_simple.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'open3'
|
3
|
+
require 'active_support/all'
|
1
4
|
require 'rdiff_simple/version'
|
2
|
-
require 'rdiff_simple/
|
3
|
-
require 'rdiff_simple/errors'
|
4
|
-
require 'rdiff_simple/commands'
|
5
|
+
require 'rdiff_simple/options_parser'
|
5
6
|
require 'rdiff_simple/rdiff_backup'
|
6
7
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RdiffSimple
|
2
|
+
class OptionsParser
|
3
|
+
def self.parse(*args)
|
4
|
+
options = args.extract_options!
|
5
|
+
|
6
|
+
args.reverse!
|
7
|
+
|
8
|
+
source = args.pop
|
9
|
+
destination = args.pop
|
10
|
+
|
11
|
+
flags = args.reverse.map { |flag| flag.size == 1 ? "-#{flag}" : "--#{flag}" } * ' '
|
12
|
+
arguments = options.map { |key, value| (key.size == 1 ? "-#{key}" : "--#{key}") + " #{value}" } * ' '
|
13
|
+
|
14
|
+
"#{flags} #{arguments} #{source} #{destination}".dasherize.strip
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,22 +1,20 @@
|
|
1
|
-
require 'open3'
|
2
1
|
|
3
2
|
module RdiffSimple
|
4
3
|
class RdiffBackup
|
5
|
-
|
4
|
+
def initialize(logger = Logger.new(STDOUT), open3 = Open3)
|
5
|
+
@logger = logger
|
6
|
+
@open3 = open3
|
7
|
+
end
|
6
8
|
|
7
9
|
def execute(*args)
|
8
|
-
|
10
|
+
command_arguments = OptionsParser.parse(*args)
|
9
11
|
|
10
|
-
|
12
|
+
out, err, result = @open3.capture3("rdiff-backup #{command_arguments}".strip)
|
11
13
|
|
12
|
-
@
|
13
|
-
|
14
|
-
end
|
14
|
+
@logger.info(out) if out.length > 0
|
15
|
+
@logger.error(err) if err.length > 0
|
15
16
|
|
16
|
-
|
17
|
-
def installed?
|
18
|
-
output, status = Open3.capture2e(COMMANDS[:installed])
|
19
|
-
status == EXIT_CODE[:success]
|
17
|
+
return result.exitstatus
|
20
18
|
end
|
21
19
|
end
|
22
20
|
end
|
data/lib/rdiff_simple/version.rb
CHANGED
data/rdiff-simple.gemspec
CHANGED
@@ -20,4 +20,11 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.extra_rdoc_files = [ "LICENSE.txt", "README.md" ]
|
22
22
|
spec.rdoc_options = [ "--charset=UTF-8" ]
|
23
|
+
|
24
|
+
spec.add_dependency "activesupport"
|
25
|
+
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rspec", "~> 2"
|
28
|
+
spec.add_development_dependency "coveralls"
|
29
|
+
spec.add_development_dependency "guard-rspec"
|
23
30
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RdiffSimple::OptionsParser do
|
4
|
+
subject { RdiffSimple::OptionsParser.parse('~/Documents', '~/Test', :b, :exclude_other_filesystems, verbosity: 5, exclude: '*.png', r: Date.today) }
|
5
|
+
|
6
|
+
describe '.parse' do
|
7
|
+
it 'converts options to long argument format' do
|
8
|
+
expect(subject).to match /\s--verbosity\s/
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'sets value for argument' do
|
12
|
+
expect(subject).to match /\s--verbosity 5\s/
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'converts symbols to dasherized strings' do
|
16
|
+
expect(subject).to match /\s--exclude-other-filesystems\s/
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'handles single letter argument' do
|
20
|
+
expect(subject).to match /\A-b\s/
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'sets value for single letter argument' do
|
24
|
+
expect(subject).to match /\s-r #{Date.today}\s/
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,61 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe RdiffSimple::RdiffBackup do
|
4
|
-
let(:
|
4
|
+
let(:args) { 'rdiff-backup --exclude-other-filesystems --verbosity 5 --exclude *.png ~/Documents ~/Test' }
|
5
|
+
let(:status) { double('status', exitstatus: Random.rand(100)) }
|
6
|
+
let(:open3) { double('open3') }
|
7
|
+
let(:backup) { RdiffSimple::RdiffBackup.new(double('logger'), open3) }
|
5
8
|
|
6
|
-
|
7
|
-
context 'when rdiff-backup is installed' do
|
8
|
-
before do
|
9
|
-
Open3.stub(:capture2e).with(RdiffSimple::COMMANDS[:installed]).and_return(['', 0])
|
10
|
-
end
|
9
|
+
subject { backup.execute('~/Documents', '~/Test', :exclude_other_filesystems, verbosity: 5, exclude: '*.png') }
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
subject { backup.execute('') }
|
18
|
-
|
19
|
-
it { should be_false }
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'when arguments are given' do
|
23
|
-
before do
|
24
|
-
Open3.stub(:capture2e).with("#{RdiffSimple::COMMANDS[:rdiff]} --version").and_return(['', 0])
|
25
|
-
end
|
26
|
-
|
27
|
-
subject { backup.execute('--version') }
|
28
|
-
|
29
|
-
it { should be_true }
|
30
|
-
end
|
11
|
+
describe '#backup' do
|
12
|
+
before do
|
13
|
+
expect(open3).to receive(:capture3).with(args) { ['', '', status] }
|
31
14
|
end
|
32
15
|
|
33
|
-
|
34
|
-
|
35
|
-
Open3.stub(:capture2e).with(RdiffSimple::COMMANDS[:installed]).and_return(['', 1])
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should raise an exception' do
|
39
|
-
expect { subject.execute('--version') }.to raise_error(RdiffSimple::NotInstalledError)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '.installed?' do
|
45
|
-
context 'when rdiff-backup is installed' do
|
46
|
-
before do
|
47
|
-
Open3.stub(:capture2e).with(RdiffSimple::COMMANDS[:installed]).and_return(['', 0])
|
48
|
-
end
|
49
|
-
|
50
|
-
it { should be_installed }
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'when rdiff-backup is not installed' do
|
54
|
-
before do
|
55
|
-
Open3.stub(:capture2e).with(RdiffSimple::COMMANDS[:installed]).and_return(['', 1])
|
56
|
-
end
|
57
|
-
|
58
|
-
it { should_not be_installed }
|
16
|
+
it 'returns the exit code' do
|
17
|
+
expect(subject).to eq status.exitstatus
|
59
18
|
end
|
60
19
|
end
|
61
20
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdiff-simple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.0.9
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ryan Hansen
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
11
|
+
date: 2013-09-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
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: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
14
83
|
description: A simple wrapper around rdiff-backup
|
15
84
|
email:
|
16
85
|
- ketiko@gmail.com
|
@@ -29,17 +98,17 @@ files:
|
|
29
98
|
- README.md
|
30
99
|
- Rakefile
|
31
100
|
- lib/rdiff_simple.rb
|
32
|
-
- lib/rdiff_simple/
|
33
|
-
- lib/rdiff_simple/errors.rb
|
34
|
-
- lib/rdiff_simple/exit_codes.rb
|
101
|
+
- lib/rdiff_simple/options_parser.rb
|
35
102
|
- lib/rdiff_simple/rdiff_backup.rb
|
36
103
|
- lib/rdiff_simple/version.rb
|
37
104
|
- rdiff-simple.gemspec
|
105
|
+
- spec/lib/rdiff_simple/options_parser_spec.rb
|
38
106
|
- spec/lib/rdiff_simple/rdiff_backup_spec.rb
|
39
107
|
- spec/spec_helper.rb
|
40
108
|
homepage: http://github.com/ketiko/rdiff-simple
|
41
109
|
licenses:
|
42
110
|
- MIT
|
111
|
+
metadata: {}
|
43
112
|
post_install_message:
|
44
113
|
rdoc_options:
|
45
114
|
- --charset=UTF-8
|
@@ -47,28 +116,21 @@ require_paths:
|
|
47
116
|
- lib
|
48
117
|
required_ruby_version: !ruby/object:Gem::Requirement
|
49
118
|
requirements:
|
50
|
-
- -
|
119
|
+
- - '>='
|
51
120
|
- !ruby/object:Gem::Version
|
52
|
-
segments:
|
53
|
-
- 0
|
54
|
-
hash: 4306097889160700498
|
55
121
|
version: '0'
|
56
|
-
none: false
|
57
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
123
|
requirements:
|
59
|
-
- -
|
124
|
+
- - '>='
|
60
125
|
- !ruby/object:Gem::Version
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
hash: 4306097889160700498
|
64
126
|
version: '0'
|
65
|
-
none: false
|
66
127
|
requirements: []
|
67
128
|
rubyforge_project:
|
68
|
-
rubygems_version:
|
129
|
+
rubygems_version: 2.0.3
|
69
130
|
signing_key:
|
70
|
-
specification_version:
|
131
|
+
specification_version: 4
|
71
132
|
summary: A wrapper around the rdiff-backup executable
|
72
133
|
test_files:
|
134
|
+
- spec/lib/rdiff_simple/options_parser_spec.rb
|
73
135
|
- spec/lib/rdiff_simple/rdiff_backup_spec.rb
|
74
136
|
- spec/spec_helper.rb
|
data/lib/rdiff_simple/errors.rb
DELETED