rbfs 1.0.16 → 1.0.17

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.
@@ -1,5 +1,5 @@
1
1
  ---
2
- script: 'rake spec'
2
+ script: 'rake travis'
3
3
  rvm:
4
4
  - 1.8.7
5
5
  - 1.9.2
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require 'rspec/core/rake_task'
3
3
 
4
- RSpec::Core::RakeTask.new(:spec) do |t|
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ RSpec::Core::RakeTask.new(:travis) do |t|
5
7
  t.rspec_opts = "--tag ~local"
6
8
  end
@@ -19,9 +19,6 @@ module Rbfs
19
19
  opts.on("-e", "--remote-root ROOT", "Remote root path to sync") do |v|
20
20
  options[:remote_root] = v
21
21
  end
22
- opts.on("--shell SHELL", "Remote shell to use") do |v|
23
- options[:shell] = v
24
- end
25
22
  opts.on("-s", "--subpath PATH", "Subpath of root to sync") do |v|
26
23
  options[:subpath] = v
27
24
  end
@@ -39,13 +39,23 @@ module Rbfs
39
39
  @config[:logger]
40
40
  end
41
41
 
42
+ def sync_path
43
+ if config[:subpath]
44
+ File.join(config[:root], config[:subpath])
45
+ else
46
+ config[:root]
47
+ end
48
+ end
49
+
42
50
  def sync
43
51
  success = true
44
52
 
45
53
  sync_hosts.each do |host, result|
46
54
  logger.info "#{host.name}: #{result.error}"
47
55
  result.changes.each do |change|
48
- logger.puts " | #{change.filename} (#{change.summary})"
56
+ if config[:verbose]
57
+ logger.puts " | #{change.filename} (#{change.summary})"
58
+ end
49
59
  end
50
60
  success = false unless result.success?
51
61
  end
@@ -54,12 +64,7 @@ module Rbfs
54
64
  end
55
65
 
56
66
  def sync_hosts
57
- if config[:subpath]
58
- config[:root] = File.join(config[:root], config[:subpath])
59
- config[:remote_root] = File.join(config[:remote_root], config[:subpath])
60
- end
61
-
62
- logger.info "Syncing #{config[:root]}..."
67
+ logger.info "Syncing #{sync_path}..."
63
68
  hosts = HostsFile.load(config[:hosts])
64
69
  hosts.collect do |host|
65
70
  [host, sync_host(host)]
@@ -7,38 +7,51 @@ module Rbfs
7
7
  @host = host
8
8
  end
9
9
 
10
+ def config
11
+ @config
12
+ end
13
+
10
14
  def logger
11
- @config[:logger]
15
+ config[:logger]
16
+ end
17
+
18
+ def sub_root(path)
19
+ if config[:subpath]
20
+ File.join(path, config[:subpath])
21
+ else
22
+ path
23
+ end
12
24
  end
13
25
 
14
26
  def remote_url
15
- "#{@host.ip}:#{@config[:remote_root]}"
27
+ "#{@host.ip}:#{remote_root}"
28
+ end
29
+
30
+ def remote_root
31
+ sub_root(config[:remote_root])
16
32
  end
17
33
 
18
34
  def local_root
19
- if File.directory?(@config[:root])
20
- @config[:root] + "/"
21
- else
22
- @config[:root]
23
- end
35
+ path = sub_root(config[:root])
36
+ path += "/" if File.directory?(path)
37
+ path
24
38
  end
25
39
 
26
40
  def mkdir
27
- args = [@host.ip, "mkdir", "-p", @config[:remote_root]]
41
+ args = [@host.ip, "mkdir", "-p", File.dirname(remote_root)]
28
42
  command("ssh", args)
29
43
  end
30
44
 
31
45
  def rsync
32
46
  args = ["-a", "--delete"]
33
- args << "-e #{@config[:shell]}" if @config[:shell]
34
- args << "-v" if @config[:verbose]
35
- args << "-n" if @config[:dry]
36
- args << "--timeout=#{@config[:timeout]}" if @config[:timeout]
47
+ args << "-v" if config[:verbose]
48
+ args << "-n" if config[:dry]
49
+ args << "--timeout=#{config[:timeout]}" if config[:timeout]
37
50
  ::Rsync.run(local_root, remote_url, args)
38
51
  end
39
52
 
40
53
  def sync
41
- if File.directory?(@config[:root])
54
+ if config[:subpath]
42
55
  mkdir
43
56
  end
44
57
  rsync
@@ -1,3 +1,3 @@
1
1
  module Rbfs
2
- VERSION = "1.0.16"
2
+ VERSION = "1.0.17"
3
3
  end
@@ -12,20 +12,23 @@ describe Rbfs::Command do
12
12
  end
13
13
  end
14
14
 
15
- def build_simple_test_dir
15
+ # /sample.txt
16
+ def build_simple
16
17
  File.open(File.join(@tmpdir, "local", "sample.txt"), 'w') do |f|
17
18
  f.write("hello world!")
18
19
  end
19
20
  end
20
21
 
21
- def build_multipath_test_dir
22
+ # /somepath/sample.txt
23
+ def build_subpath_simple
22
24
  Dir.mkdir(File.join(@tmpdir, "local", "somepath"))
23
25
  File.open(File.join(@tmpdir, "local", "somepath", "sample.txt"), 'w') do |f|
24
26
  f.write("hello world!")
25
27
  end
26
28
  end
27
29
 
28
- def build_deeppath_test_dir
30
+ # /somepath/someotherpath/sample.txt
31
+ def build_deeppath_simple
29
32
  Dir.mkdir(File.join(@tmpdir, "local", "somepath"))
30
33
  Dir.mkdir(File.join(@tmpdir, "local", "somepath", "someotherpath"))
31
34
  File.open(File.join(@tmpdir, "local", "somepath", "someotherpath", "sample.txt"), 'w') do |f|
@@ -37,6 +40,26 @@ describe Rbfs::Command do
37
40
  `cd #{@tmpdir}/#{subpath}; tree`
38
41
  end
39
42
 
43
+ def run_sync_test
44
+ Rbfs::Command.new(
45
+ :hosts => File.join(@tmpdir, "hosts"),
46
+ :root => File.join(@tmpdir, "local"),
47
+ :remote_root => File.join(@tmpdir, "remote")
48
+ ).sync
49
+ get_tree("remote").should eql(get_tree("local"))
50
+ end
51
+
52
+ def run_deeppath_test(subpath)
53
+ build_deeppath_simple
54
+ Rbfs::Command.new(
55
+ :hosts => File.join(@tmpdir, "hosts"),
56
+ :root => File.join(@tmpdir, "local"),
57
+ :subpath => subpath,
58
+ :remote_root => File.join(@tmpdir, "remote")
59
+ ).sync
60
+ get_tree("remote").should eql(get_tree("local"))
61
+ end
62
+
40
63
  context "simple", :local => true do
41
64
  around(:each) do |example|
42
65
  make_test_dir do
@@ -45,48 +68,35 @@ describe Rbfs::Command do
45
68
  end
46
69
 
47
70
  it "should do simple file sync" do
48
- build_simple_test_dir
71
+ build_simple
49
72
  Rbfs::Command.new(
50
73
  :hosts => File.join(@tmpdir, "hosts"),
51
74
  :root => File.join(@tmpdir, "local") + "/sample.txt",
52
- :shell => '"ssh -o StrictHostKeyChecking=no"',
53
75
  :remote_root => File.join(@tmpdir, "remote") + "/sample.txt"
54
76
  ).sync
55
- get_tree("local").should eql(get_tree("remote"))
77
+ get_tree("remote").should eql(get_tree("local"))
56
78
  end
57
79
 
58
80
  it "should do simple path sync" do
59
- build_simple_test_dir
60
- Rbfs::Command.new(
61
- :hosts => File.join(@tmpdir, "hosts"),
62
- :root => File.join(@tmpdir, "local"),
63
- :shell => '"ssh -o StrictHostKeyChecking=no"',
64
- :remote_root => File.join(@tmpdir, "remote")
65
- ).sync
66
- get_tree("local").should eql(get_tree("remote"))
81
+ build_simple
82
+ run_sync_test
67
83
  end
68
84
 
69
85
  it "should do multi path sync" do
70
- build_multipath_test_dir
71
- Rbfs::Command.new(
72
- :hosts => File.join(@tmpdir, "hosts"),
73
- :root => File.join(@tmpdir, "local"),
74
- :shell => '"ssh -o StrictHostKeyChecking=no"',
75
- :remote_root => File.join(@tmpdir, "remote")
76
- ).sync
77
- get_tree("local").should eql(get_tree("remote"))
86
+ build_subpath_simple
87
+ run_sync_test
78
88
  end
79
89
 
80
90
  it "should do sub path sync" do
81
- build_deeppath_test_dir
82
- Rbfs::Command.new(
83
- :hosts => File.join(@tmpdir, "hosts"),
84
- :root => File.join(@tmpdir, "local"),
85
- :subpath => "somepath/someotherpath/",
86
- :shell => '"ssh -o StrictHostKeyChecking=no"',
87
- :remote_root => File.join(@tmpdir, "remote")
88
- ).sync
89
- get_tree("local").should eql(get_tree("remote"))
91
+ run_deeppath_test("somepath")
92
+ end
93
+
94
+ it "should do deep sub path sync" do
95
+ run_deeppath_test("somepath/someotherpath")
96
+ end
97
+
98
+ it "should do deep sub path file sync" do
99
+ run_deeppath_test("somepath/someotherpath/sample.txt")
90
100
  end
91
101
  end
92
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.16
4
+ version: 1.0.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-07-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rsync
16
- requirement: &19509060 !ruby/object:Gem::Requirement
16
+ requirement: &9835680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *19509060
24
+ version_requirements: *9835680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hosts_file
27
- requirement: &19507900 !ruby/object:Gem::Requirement
27
+ requirement: &9833240 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *19507900
35
+ version_requirements: *9833240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &19505500 !ruby/object:Gem::Requirement
38
+ requirement: &9832140 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '1.3'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *19505500
46
+ version_requirements: *9832140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &19504860 !ruby/object:Gem::Requirement
49
+ requirement: &9831340 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *19504860
57
+ version_requirements: *9831340
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &19503760 !ruby/object:Gem::Requirement
60
+ requirement: &9830360 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *19503760
68
+ version_requirements: *9830360
69
69
  description: Ruby File Sync
70
70
  email:
71
71
  - jbussdieker@gmail.com