syncwatch 0.2.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/Gemfile +2 -0
- data/Gemfile.lock +18 -0
- data/bin/syncwatch +52 -0
- data/lib/syncwatch.rb +71 -0
- data/readme.md +10 -0
- data/syncwatch.gemspec +17 -0
- metadata +67 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
macaddr (1.6.1)
|
5
|
+
systemu (~> 2.5.0)
|
6
|
+
rb-fsevent (0.9.1)
|
7
|
+
ruby-growl (4.0)
|
8
|
+
uuid (~> 2.3, >= 2.3.5)
|
9
|
+
systemu (2.5.1)
|
10
|
+
uuid (2.3.5)
|
11
|
+
macaddr (~> 1.0)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
ruby
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
rb-fsevent
|
18
|
+
ruby-growl
|
data/bin/syncwatch
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path('../../lib/syncwatch', __FILE__)
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
# Default options
|
7
|
+
options = {
|
8
|
+
:rsync_excludes => [],
|
9
|
+
}
|
10
|
+
|
11
|
+
OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: syncwatch [otpions] <local path> <remote path>"
|
13
|
+
|
14
|
+
opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
|
15
|
+
options[:verbose] = v
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on('-X', '--exclude=FILE', 'Exclude file from sync') do |x|
|
19
|
+
options[:rsync_excludes] << x
|
20
|
+
end
|
21
|
+
|
22
|
+
opts.on('-p', '--port [PORT]', 'Port to SSH to on remote host') do |p|
|
23
|
+
options[:port] = p
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on_tail('--version', 'Show version') do
|
27
|
+
puts SyncWatch::VERSION
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
31
|
+
end.parse!
|
32
|
+
|
33
|
+
options[:path] = ARGV[0]
|
34
|
+
options[:remote_path] = ARGV[1]
|
35
|
+
|
36
|
+
# Error checking
|
37
|
+
if options[:path].nil?
|
38
|
+
$stderr.puts "Local path not provided"
|
39
|
+
exit
|
40
|
+
elsif options[:remote_path].nil?
|
41
|
+
$stderr.puts "Remote path not provided"
|
42
|
+
exit
|
43
|
+
end
|
44
|
+
|
45
|
+
unless File.directory? options[:path]
|
46
|
+
$stderr.puts "Invalid path specified"
|
47
|
+
exit
|
48
|
+
end
|
49
|
+
|
50
|
+
# Start
|
51
|
+
sw = SyncWatch.new options
|
52
|
+
sw.run
|
data/lib/syncwatch.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# TODO: switch to guard/listen
|
2
|
+
require 'rb-fsevent'
|
3
|
+
|
4
|
+
# SyncWatch
|
5
|
+
# rsync file system changes
|
6
|
+
class SyncWatch
|
7
|
+
VERSION = "0.2.1"
|
8
|
+
|
9
|
+
def initialize(params)
|
10
|
+
@path = params[:path] || Dir.pwd
|
11
|
+
@remote_path = params[:remote_path] || Dir.pwd
|
12
|
+
@ignore_rules ||= params[:ignore_rules] || [/^\.git/, /^\.svn/, /\.DS_Store/]
|
13
|
+
@verbose = params[:verbose] || true
|
14
|
+
@port = params[:port]
|
15
|
+
|
16
|
+
@last_touched_dirs = nil
|
17
|
+
|
18
|
+
@rsync_excludes = if params[:rsync_excludes].nil?
|
19
|
+
''
|
20
|
+
else
|
21
|
+
params[:rsync_excludes].reduce('') {|list, excl| list += "--exclude=#{excl} "}
|
22
|
+
end
|
23
|
+
|
24
|
+
@fsevent = FSEvent.new
|
25
|
+
|
26
|
+
## trigger event
|
27
|
+
@fsevent.watch @path do |dirs|
|
28
|
+
@last_touched_dirs = dirs
|
29
|
+
puts "[#{Time.now.to_s}] Detected #{dirs.length} change#{'s' if dirs.length > 1}" if @verbose
|
30
|
+
|
31
|
+
if requires_sync? dirs
|
32
|
+
run_sync
|
33
|
+
else
|
34
|
+
puts "\tOnly ignored files changed -- skipping sync" if @verbose
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def requires_sync? (dirs)
|
40
|
+
# run through directories. sync if 1+ non-ignored files change
|
41
|
+
dirs.each do |dir|
|
42
|
+
dir.gsub!(@path, '') # normalize
|
43
|
+
return true unless dir_ignored? dir #only need 1 non-ignore to run the syncd
|
44
|
+
end
|
45
|
+
false
|
46
|
+
end
|
47
|
+
|
48
|
+
def run_sync
|
49
|
+
print "\tSyncing..." if @verbose
|
50
|
+
start = Time.now
|
51
|
+
rsh = 'ssh'
|
52
|
+
rsh += " -p#{@port}" unless @port.nil?
|
53
|
+
%x[rsync -avPz --delete #{@rsync_excludes} --rsh='#{rsh}' #{@path} #{@remote_path} ]
|
54
|
+
msg = "rsync complete (took %.2fs)" % (Time.now - start)
|
55
|
+
puts msg if @verbose
|
56
|
+
end
|
57
|
+
|
58
|
+
def run
|
59
|
+
if @verbose
|
60
|
+
puts '== Starting SyncWatch =='
|
61
|
+
puts "[#{@path}]=>[#{@remote_path}]"
|
62
|
+
puts 'Initial Sync:'
|
63
|
+
end
|
64
|
+
run_sync
|
65
|
+
@fsevent.run
|
66
|
+
end
|
67
|
+
|
68
|
+
def dir_ignored?(dir)
|
69
|
+
@ignore_rules.reduce(false) {|v,r| break(true) if dir =~ r }
|
70
|
+
end
|
71
|
+
end
|
data/readme.md
ADDED
data/syncwatch.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/syncwatch', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'syncwatch'
|
6
|
+
s.authors = ['Logan Linn']
|
7
|
+
s.description = %q{Simple CLI tool to rsync directories after file system changes}
|
8
|
+
s.summary = s.description
|
9
|
+
s.email = 'logan@loganlinn.com'
|
10
|
+
s.homepage = 'https://github.com/loganlinn/syncwatch'
|
11
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.require_paths = ['lib']
|
14
|
+
s.version = SyncWatch::VERSION
|
15
|
+
|
16
|
+
s.add_dependency 'rb-fsevent'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: syncwatch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Logan Linn
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rb-fsevent
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '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: '0'
|
30
|
+
description: Simple CLI tool to rsync directories after file system changes
|
31
|
+
email: logan@loganlinn.com
|
32
|
+
executables:
|
33
|
+
- syncwatch
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- Gemfile
|
38
|
+
- Gemfile.lock
|
39
|
+
- bin/syncwatch
|
40
|
+
- lib/syncwatch.rb
|
41
|
+
- readme.md
|
42
|
+
- syncwatch.gemspec
|
43
|
+
homepage: https://github.com/loganlinn/syncwatch
|
44
|
+
licenses: []
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.8.24
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: Simple CLI tool to rsync directories after file system changes
|
67
|
+
test_files: []
|