synchrotron 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/synchrotron CHANGED
@@ -24,7 +24,7 @@ BANNER
24
24
  opt :exclude, "Pathname or pattern to exclude", :short => :none, :multi => true, :type => :string
25
25
  opt :exclude_from, "File containing pathnames and patterns to exclude", :short => :none, :multi => true, :type => :string
26
26
  opt :rsync_path, "Path to the rsync binary", :short => :none, :default => '/usr/bin/rsync'
27
- opt :verbosity, "Output verbosity: debug, info, warn, error, or fatal", :short => '-V', :default => 'info'
27
+ opt :verbosity, "Output verbosity: debug, verbose, info, warn, error, or fatal", :short => '-V', :default => 'info'
28
28
  end
29
29
 
30
30
  config[:remote_path] = ARGV.shift or abort("Error: Remote path not specified")
@@ -4,13 +4,13 @@ module Synchrotron; class Ignore
4
4
  REGEX_COMMENT = /#.*$/
5
5
  REGEX_REGEX = /^\s*(%r(.).*\2[imxouesn]*)\s*$/i
6
6
 
7
- def initialize(list = [])
7
+ def initialize(list = [], logger)
8
8
  @cache = {}
9
9
  @globs = []
10
10
  @regexes = []
11
11
 
12
12
  @list = list.to_a
13
- @log = Synchrotron.log
13
+ @log = logger
14
14
 
15
15
  compile(@list)
16
16
  end
@@ -31,7 +31,7 @@ module Synchrotron; class Ignore
31
31
  @cache[_path] = match = @globs.any? {|glob| _path =~ glob } ||
32
32
  @regexes.any? {|regex| _path =~ regex }
33
33
 
34
- @log.insane "Ignoring #{_path}" if match
34
+ @log.verbose "Ignoring #{_path}" if match
35
35
  match
36
36
  end
37
37
 
@@ -46,7 +46,7 @@ module Synchrotron; class Ignore
46
46
  lineno += 1
47
47
 
48
48
  # Strip comments.
49
- line.sub!(REGEX_COMMENT, '')
49
+ line = line.sub(REGEX_COMMENT, '')
50
50
  line.strip!
51
51
 
52
52
  # Skip empty lines.
@@ -66,7 +66,7 @@ module Synchrotron; class Ignore
66
66
 
67
67
  def glob_to_regex(str)
68
68
  regex = str.gsub(/(.)/) {|c| GLOB_PATTERNS[$1] || Regexp.escape(c) }
69
- Regexp.new("#{regex}$")
69
+ Regexp.new("#{regex}\\Z")
70
70
  end
71
71
 
72
72
  end; end
@@ -4,12 +4,12 @@ class Logger
4
4
  attr_reader :level, :output
5
5
 
6
6
  LEVELS = {
7
- :fatal => 0,
8
- :error => 1,
9
- :warn => 2,
10
- :info => 3,
11
- :debug => 4,
12
- :insane => 5
7
+ :fatal => 0,
8
+ :error => 1,
9
+ :warn => 2,
10
+ :info => 3,
11
+ :verbose => 4,
12
+ :debug => 5
13
13
  }
14
14
 
15
15
  def initialize(level = :info, output = $stdout)
@@ -1,6 +1,6 @@
1
1
  module Synchrotron
2
2
  APP_NAME = 'Synchrotron'
3
- APP_VERSION = '0.0.2'
3
+ APP_VERSION = '0.0.3'
4
4
  APP_AUTHOR = 'Ryan Grove'
5
5
  APP_EMAIL = 'ryan@wonko.com'
6
6
  APP_URL = 'http://github.com/rgrove/synchrotron/'
data/lib/synchrotron.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'find'
2
2
  require 'pathname'
3
+ require 'thread'
3
4
 
4
5
  require 'rb-fsevent'
5
6
 
@@ -21,19 +22,21 @@ module Synchrotron; class << self
21
22
 
22
23
  :rsync_options => [
23
24
  '--compress',
25
+ '--delete',
24
26
  '--human-readable',
25
27
  '--links',
28
+ '--out-format="--> [%o] %n %L"',
29
+ '--perms',
26
30
  '--recursive',
27
- '--times',
28
- '--verbose'
31
+ '--times'
29
32
  ],
30
33
 
31
34
  :rsync_path => '/usr/bin/rsync',
32
35
  :verbosity => :info
33
36
  }.merge(config)
34
37
 
35
- @ignore = Ignore.new(@config[:exclude])
36
38
  @log = Logger.new(@config[:verbosity])
39
+ @ignore = Ignore.new(@config[:exclude], @log)
37
40
  @regex_rel = Regexp.new("^#{Regexp.escape(@config[:local_path].chomp('/'))}/?")
38
41
  @queue = Queue.new
39
42
 
@@ -69,13 +72,15 @@ module Synchrotron; class << self
69
72
 
70
73
  @sync_thread = Thread.new do
71
74
  while changed = @queue.pop do
72
- @log.info "Change detected"
75
+ @log.verbose "Change detected"
76
+
77
+ changed.each {|path| @log.verbose "--> #{path}" }
73
78
  changed.each {|path| sync(path) if File.exist?(path) }
74
79
  end
75
80
  end
76
81
 
77
82
  fsevent = FSEvent.new
78
- fsevent.watch(@config[:local_path], {:latency => 5, :no_defer => true}) do |paths|
83
+ fsevent.watch(@config[:local_path], {:latency => 1}) do |paths|
79
84
  changed = coalesce_changes(paths.reject {|path| @ignore.match(path) })
80
85
  @queue << changed unless changed.empty?
81
86
  end
@@ -96,8 +101,11 @@ module Synchrotron; class << self
96
101
  @config[:exclude].each {|p| rsync_options << " --exclude #{escape_arg(p)}" }
97
102
  @config[:exclude_from].each {|f| rsync_options << " --exclude-from #{escape_arg(f)}"}
98
103
 
99
- puts `#{@config[:rsync_path]} #{rsync_options} #{rsync_local} #{rsync_remote}`
100
- puts
104
+ rsync_cmd = "#{@config[:rsync_path]} #{rsync_options} #{rsync_local} #{rsync_remote}"
105
+
106
+ @log.debug rsync_cmd
107
+
108
+ `#{rsync_cmd}`.each_line {|line| @log.info line }
101
109
  end
102
110
 
103
111
  private
metadata CHANGED
@@ -1,58 +1,55 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: synchrotron
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 2
9
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Ryan Grove
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-06-07 00:00:00 -07:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-06-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rb-fsevent
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
25
19
  - - ~>
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- - 9
30
- - 1
20
+ - !ruby/object:Gem::Version
31
21
  version: 0.9.1
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: trollop
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- requirements:
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: trollop
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
39
35
  - - ~>
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 1
43
- - 13
44
- version: "1.13"
36
+ - !ruby/object:Gem::Version
37
+ version: '1.13'
45
38
  type: :runtime
46
- version_requirements: *id002
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.13'
47
46
  description:
48
47
  email: ryan@wonko.com
49
- executables:
48
+ executables:
50
49
  - synchrotron
51
50
  extensions: []
52
-
53
51
  extra_rdoc_files: []
54
-
55
- files:
52
+ files:
56
53
  - bin/synchrotron
57
54
  - lib/synchrotron/ignore.rb
58
55
  - lib/synchrotron/logger.rb
@@ -60,39 +57,29 @@ files:
60
57
  - lib/synchrotron/stream.rb
61
58
  - lib/synchrotron/version.rb
62
59
  - lib/synchrotron.rb
63
- has_rdoc: true
64
60
  homepage: http://github.com/rgrove/synchrotron/
65
61
  licenses: []
66
-
67
62
  post_install_message:
68
63
  rdoc_options: []
69
-
70
- require_paths:
64
+ require_paths:
71
65
  - lib
72
- required_ruby_version: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- segments:
77
- - 1
78
- - 8
79
- - 7
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
80
71
  version: 1.8.7
81
- required_rubygems_version: !ruby/object:Gem::Requirement
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- segments:
86
- - 1
87
- - 2
88
- - 0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
89
77
  version: 1.2.0
90
78
  requirements: []
91
-
92
79
  rubyforge_project:
93
- rubygems_version: 1.3.6
80
+ rubygems_version: 1.8.24
94
81
  signing_key:
95
82
  specification_version: 3
96
- summary: Synchrotron monitors a local directory tree and performs nearly instantaneous one-way synchronization of changes to a remote directory using rsync.
83
+ summary: Synchrotron monitors a local directory tree and performs nearly instantaneous
84
+ one-way synchronization of changes to a remote directory using rsync.
97
85
  test_files: []
98
-