guard-remote-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.
- data/LICENSE +22 -0
- data/README.md +24 -0
- data/lib/guard/remote-sync/command.rb +96 -0
- data/lib/guard/remote-sync/source.rb +13 -0
- data/lib/guard/remote-sync/templates/Guardfile +11 -0
- data/lib/guard/remote-sync/version.rb +5 -0
- data/lib/guard/remote-sync.rb +121 -0
- metadata +116 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Patrick McJury
|
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,24 @@
|
|
1
|
+
guard-rsync-remote
|
2
|
+
============
|
3
|
+
|
4
|
+
**Usage**
|
5
|
+
```
|
6
|
+
bundle exec guard
|
7
|
+
```
|
8
|
+
|
9
|
+
**Example Guardfile**
|
10
|
+
```
|
11
|
+
guard 'rsync-remote',
|
12
|
+
:source => ".",
|
13
|
+
:destination => '/export/home/{username}/tmp',
|
14
|
+
:user => '{user}',
|
15
|
+
:remote_address => '{address}',
|
16
|
+
:verbose => true,
|
17
|
+
:cli => "--color",
|
18
|
+
:sync_on_start => true do
|
19
|
+
|
20
|
+
watch(%r{^.+\.(js|xml|php|class|config)$})
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
A more extensive and tested rsync guard
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Guard
|
2
|
+
class RemoteSync
|
3
|
+
class Command
|
4
|
+
|
5
|
+
attr_accessor :command, :source, :destination
|
6
|
+
|
7
|
+
def initialize(source, destination, options = {})
|
8
|
+
@options = options
|
9
|
+
@source = source
|
10
|
+
@destination = destination
|
11
|
+
@command = build_command
|
12
|
+
end
|
13
|
+
|
14
|
+
def sync
|
15
|
+
UI.info "Guard::RsyncX `#{@command}`"
|
16
|
+
r = `#{@command}`
|
17
|
+
UI.info "Guard::RsyncX Status : \n #{r}" if @options[:verbose]
|
18
|
+
end
|
19
|
+
|
20
|
+
def test
|
21
|
+
@options[:dry_run] = true
|
22
|
+
test_command = build_command
|
23
|
+
@options[:dry_run] = false
|
24
|
+
$stdout.sync = true
|
25
|
+
`#{test_command}`
|
26
|
+
$stdout.sync = false
|
27
|
+
$?.exitstatus
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def build_command
|
33
|
+
unless @options[:cli_options].nil?
|
34
|
+
UI.info "':cli' option was given so ignoring all other options, and outputting as is..."
|
35
|
+
command = "#{rsync_command} #{@options[:cli_options]}"
|
36
|
+
else
|
37
|
+
UI.debug "building rsync options from specified options"
|
38
|
+
@command_options = build_options
|
39
|
+
@remote_options = check_remote_options
|
40
|
+
destination = @remote_options.nil? ? "#{@destination.directory}" : "#{@remote_options}:#{@destination.directory}"
|
41
|
+
command = "#{rsync_command} #{@command_options}#{@source.directory} #{destination}"
|
42
|
+
end
|
43
|
+
command
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_options
|
47
|
+
opts = ""
|
48
|
+
simple_opts = ""
|
49
|
+
[:archive, :recursive, :verbose].each do |o|
|
50
|
+
value = check_simple_option(o)
|
51
|
+
simple_opts.concat "#{value}" unless value.nil?
|
52
|
+
end
|
53
|
+
opts.concat "-#{simple_opts} " unless simple_opts.empty?
|
54
|
+
|
55
|
+
[:progress, :delete, :stats, :dry_run, :cvs_exclude].each do |o|
|
56
|
+
value = check_boolean_option(o)
|
57
|
+
opts.concat "#{value} " unless value.nil?
|
58
|
+
end
|
59
|
+
[:include, :include_from, :exclude, :exclude_from, :password_file].each do |o|
|
60
|
+
value = check_nil_option(o)
|
61
|
+
opts.concat "#{value} " unless value.nil?
|
62
|
+
end
|
63
|
+
|
64
|
+
opts
|
65
|
+
end
|
66
|
+
|
67
|
+
def rsync_command
|
68
|
+
"rsync"
|
69
|
+
end
|
70
|
+
|
71
|
+
def check_remote_options
|
72
|
+
unless @options[:user].nil? && @options[:remote_address].nil?
|
73
|
+
raise "A remote address is required if you specify a user" if !@options[:user].nil? && @options[:remote_address].nil?
|
74
|
+
raise "A user is required if you specify a remote address" if @options[:user].nil? && !@options[:remote_address].nil?
|
75
|
+
value = "#{@options[:user]}@#{@options[:remote_address]}"
|
76
|
+
else
|
77
|
+
value = nil
|
78
|
+
end
|
79
|
+
value
|
80
|
+
end
|
81
|
+
|
82
|
+
def check_boolean_option(option)
|
83
|
+
@options[option] ? "--#{option.to_s.gsub(/_/, '-')}" : nil
|
84
|
+
end
|
85
|
+
|
86
|
+
def check_nil_option(option)
|
87
|
+
@options[option].nil? ? nil : "--#{option.to_s.gsub(/_/, '-')} '#{@options[option]}'"
|
88
|
+
end
|
89
|
+
|
90
|
+
def check_simple_option(option)
|
91
|
+
@options[option] ? "#{option.to_s[0, 1]}" : nil
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
guard 'remote-sync',
|
2
|
+
:source => ".",
|
3
|
+
:destination => '/export/home/{username}/tmp',
|
4
|
+
:user => '{user}',
|
5
|
+
:remote_address => '{address}',
|
6
|
+
:verbose => true,
|
7
|
+
:cli => "--color",
|
8
|
+
:sync_on_start => true do
|
9
|
+
|
10
|
+
watch(%r{^.+\.(js|xml|php|class|config)$})
|
11
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
|
4
|
+
module Guard
|
5
|
+
class RemoteSync < Guard
|
6
|
+
|
7
|
+
autoload :Command, 'guard/remote-sync/command'
|
8
|
+
autoload :Source, 'guard/remote-sync/source'
|
9
|
+
|
10
|
+
attr_accessor :command
|
11
|
+
|
12
|
+
# Initialize a Guard.
|
13
|
+
# @param [Array<Guard::Watcher>] watchers the Guard file watchers
|
14
|
+
# @param [Hash] options the custom Guard options
|
15
|
+
def initialize(watchers = [], options = {})
|
16
|
+
super
|
17
|
+
@options = {
|
18
|
+
:source => nil,
|
19
|
+
:destination => nil,
|
20
|
+
:user => nil,
|
21
|
+
:remote_address => nil,
|
22
|
+
:ssh => false,
|
23
|
+
:cli_options => nil,
|
24
|
+
:archive => true,
|
25
|
+
:recursive => true,
|
26
|
+
:verbose => true,
|
27
|
+
:delete => true,
|
28
|
+
:include => nil,
|
29
|
+
:include_from => nil,
|
30
|
+
:exclude => nil,
|
31
|
+
:exclude_from => ".rsync-filter",
|
32
|
+
:progress => true,
|
33
|
+
:sync_on_start => false,
|
34
|
+
:dry_run => false,
|
35
|
+
:cvs_exclude => true,
|
36
|
+
:password_file => nil
|
37
|
+
}.merge(options)
|
38
|
+
|
39
|
+
@source = Source.new(options[:source])
|
40
|
+
@destination = Source.new(options[:destination])
|
41
|
+
@command = Command.new(@source, @destination, @options)
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
# Call once when Guard starts. Please override initialize method to init stuff.
|
46
|
+
# @raise [:task_has_failed] when start has failed
|
47
|
+
def start
|
48
|
+
throw([:task_has_failed], "Guard::RsyncX options invalid") unless options_valid?
|
49
|
+
UI.info "Guard::RsyncX started in source directory '#{File.expand_path @source.directory}'"
|
50
|
+
Notifier.notify("Guard::RsyncX is running in directory #{File.expand_path @source.directory}", notifier_options)
|
51
|
+
@command.sync if options[:sync_on_start] && @command.test
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
# Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
|
56
|
+
# @raise [:task_has_failed] when stop has failed
|
57
|
+
|
58
|
+
def stop
|
59
|
+
UI.info "Guard::RsyncX stopped."
|
60
|
+
Notifier.notify("Guard::RsyncX stopped.",notifier_options)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Called when `reload|r|z + enter` is pressed.
|
64
|
+
# This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
|
65
|
+
# @raise [:task_has_failed] when reload has failed
|
66
|
+
def reload
|
67
|
+
Notifier.notify("Manual Guard::RsyncX synchronize #{File.expand_path @source.directory} to #{@destination.directory}",notifier_options)
|
68
|
+
@command.sync
|
69
|
+
end
|
70
|
+
|
71
|
+
# Called when just `enter` is pressed
|
72
|
+
# This method should be principally used for long action like running all specs/tests/...
|
73
|
+
# @raise [:task_has_failed] when run_all has failed
|
74
|
+
def run_all
|
75
|
+
Notifier.notify("Manual Guard::RsyncX synchronize #{@source.directory} to #{@destination.directory}",notifier_options)
|
76
|
+
@command.sync
|
77
|
+
end
|
78
|
+
|
79
|
+
# Called on file(s) modifications that the Guard watches.
|
80
|
+
# @param [Array<String>] paths the changes files or paths
|
81
|
+
# @raise [:task_has_failed] when run_on_change has failed
|
82
|
+
def run_on_changes(paths)
|
83
|
+
#paths.each do |p| ::Guard::UI.info("Files effect : #{p}") end
|
84
|
+
@command.sync
|
85
|
+
end
|
86
|
+
|
87
|
+
# Called on file(s) deletions that the Guard watches.
|
88
|
+
# @param [Array<String>] paths the deleted files or paths
|
89
|
+
# @raise [:task_has_failed] when run_on_removals has failed
|
90
|
+
def run_on_removals(paths)
|
91
|
+
@command.sync
|
92
|
+
end
|
93
|
+
|
94
|
+
# Called on file(s) additions that the Guard watches.
|
95
|
+
# @param [Array<String>] paths the added files or paths
|
96
|
+
# @raise [:task_has_failed] when run_on_additions has failed
|
97
|
+
def run_on_additions(paths)
|
98
|
+
@command.sync
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
def options_valid?
|
104
|
+
valid = true
|
105
|
+
if options[:source].nil? && options[:cli_options].nil?
|
106
|
+
UI.error("Guard::RsyncX a source directory is required")
|
107
|
+
valid = false
|
108
|
+
end
|
109
|
+
if options[:destination].nil? && options[:cli_options].nil?
|
110
|
+
UI.error("Guard::RsyncX a source directory is required")
|
111
|
+
valid = false
|
112
|
+
end
|
113
|
+
valid
|
114
|
+
end
|
115
|
+
|
116
|
+
def notifier_options
|
117
|
+
{:title => "Guard::RsyncX", :image => :success}
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-remote-sync
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Patrick McJury
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: guard
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.1.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.9.2.2
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.2.2
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: guard-rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Guard::RemoteSync to automatically rsync your files.
|
79
|
+
email:
|
80
|
+
- pmcjury@mcjent.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- lib/guard/remote-sync/command.rb
|
86
|
+
- lib/guard/remote-sync/source.rb
|
87
|
+
- lib/guard/remote-sync/templates/Guardfile
|
88
|
+
- lib/guard/remote-sync/version.rb
|
89
|
+
- lib/guard/remote-sync.rb
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
homepage: https://github.com/pmcjury/guard-remote-sync
|
93
|
+
licenses: []
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.3.6
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project: guard-remote-synch
|
112
|
+
rubygems_version: 1.8.24
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: Guard gem for Remote Syncing through rsync
|
116
|
+
test_files: []
|