synchrotron 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/synchrotron.rb CHANGED
@@ -1,13 +1,7 @@
1
- # Prepend this file's directory to the include path if it's not there already.
2
- $:.unshift(File.dirname(File.expand_path(__FILE__)))
3
- $:.uniq!
4
-
5
1
  require 'find'
6
2
  require 'pathname'
7
- require 'set'
8
- require 'osx/foundation'
9
3
 
10
- OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'
4
+ require 'rb-fsevent'
11
5
 
12
6
  require 'synchrotron/ignore'
13
7
  require 'synchrotron/logger'
@@ -38,9 +32,10 @@ module Synchrotron; class << self
38
32
  :verbosity => :info
39
33
  }.merge(config)
40
34
 
41
- @log = Logger.new(@config[:verbosity])
42
35
  @ignore = Ignore.new(@config[:exclude])
36
+ @log = Logger.new(@config[:verbosity])
43
37
  @regex_rel = Regexp.new("^#{Regexp.escape(@config[:local_path].chomp('/'))}/?")
38
+ @queue = Queue.new
44
39
 
45
40
  @config[:rsync_options] << '--dry-run' if @config[:dry_run]
46
41
 
@@ -48,20 +43,6 @@ module Synchrotron; class << self
48
43
  @config[:exclude_from] << local_exclude_file if File.exist?(local_exclude_file)
49
44
  @config[:exclude_from].each {|filename| @ignore.add_file(filename) }
50
45
 
51
- @callback = proc do |stream, context, event_count, paths, marks, event_ids|
52
- changed = Set.new
53
- paths.regard_as('*')
54
- event_count.times {|i| changed.add(paths[i]) unless @ignore.match(paths[i]) }
55
-
56
- changed = coalesce_changes(changed)
57
- return if changed.empty?
58
-
59
- @log.info "Change detected"
60
- changed.each {|path| sync(path) }
61
- end
62
-
63
- @stream = Stream.new(config[:local_path], @callback)
64
-
65
46
  @log.info "Local path : #{@config[:local_path]}"
66
47
  @log.info "Remote path: #{@config[:remote_path]}"
67
48
  end
@@ -85,13 +66,21 @@ module Synchrotron; class << self
85
66
 
86
67
  def monitor
87
68
  @log.info "Watching for changes"
88
- @stream.start
89
69
 
90
- begin
91
- OSX.CFRunLoopRun()
92
- rescue Interrupt
93
- @stream.release
70
+ @sync_thread = Thread.new do
71
+ while changed = @queue.pop do
72
+ @log.info "Change detected"
73
+ changed.each {|path| sync(path) if File.exist?(path) }
74
+ end
75
+ end
76
+
77
+ fsevent = FSEvent.new
78
+ fsevent.watch(@config[:local_path], {:latency => 5, :no_defer => true}) do |paths|
79
+ changed = coalesce_changes(paths.reject {|path| @ignore.match(path) })
80
+ @queue << changed unless changed.empty?
94
81
  end
82
+
83
+ fsevent.run
95
84
  end
96
85
 
97
86
  def relative_path(path)
@@ -1,9 +1,9 @@
1
1
  module Synchrotron
2
2
  APP_NAME = 'Synchrotron'
3
- APP_VERSION = '0.0.1'
3
+ APP_VERSION = '0.0.2'
4
4
  APP_AUTHOR = 'Ryan Grove'
5
5
  APP_EMAIL = 'ryan@wonko.com'
6
6
  APP_URL = 'http://github.com/rgrove/synchrotron/'
7
- APP_COPYRIGHT = 'Copyright (c) 2009 Ryan Grove <ryan@wonko.com>. All ' <<
7
+ APP_COPYRIGHT = 'Copyright (c) 2012 Ryan Grove <ryan@wonko.com>. All ' <<
8
8
  'rights reserved.'
9
9
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synchrotron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
5
10
  platform: ruby
6
11
  authors:
7
12
  - Ryan Grove
@@ -9,19 +14,36 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-04 00:00:00 -08:00
17
+ date: 2012-06-07 00:00:00 -07:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
- name: trollop
21
+ name: rb-fsevent
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 9
30
+ - 1
31
+ version: 0.9.1
17
32
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: trollop
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
20
38
  requirements:
21
39
  - - ~>
22
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 13
23
44
  version: "1.13"
24
- version:
45
+ type: :runtime
46
+ version_requirements: *id002
25
47
  description:
26
48
  email: ryan@wonko.com
27
49
  executables:
@@ -32,12 +54,12 @@ extra_rdoc_files: []
32
54
 
33
55
  files:
34
56
  - bin/synchrotron
35
- - lib/synchrotron.rb
36
57
  - lib/synchrotron/ignore.rb
37
58
  - lib/synchrotron/logger.rb
38
59
  - lib/synchrotron/scanner.rb
39
60
  - lib/synchrotron/stream.rb
40
61
  - lib/synchrotron/version.rb
62
+ - lib/synchrotron.rb
41
63
  has_rdoc: true
42
64
  homepage: http://github.com/rgrove/synchrotron/
43
65
  licenses: []
@@ -51,20 +73,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
73
  requirements:
52
74
  - - ">="
53
75
  - !ruby/object:Gem::Version
54
- version: 1.8.6
55
- version:
76
+ segments:
77
+ - 1
78
+ - 8
79
+ - 7
80
+ version: 1.8.7
56
81
  required_rubygems_version: !ruby/object:Gem::Requirement
57
82
  requirements:
58
83
  - - ">="
59
84
  - !ruby/object:Gem::Version
60
- version: "0"
61
- version:
85
+ segments:
86
+ - 1
87
+ - 2
88
+ - 0
89
+ version: 1.2.0
62
90
  requirements: []
63
91
 
64
92
  rubyforge_project:
65
- rubygems_version: 1.3.5
93
+ rubygems_version: 1.3.6
66
94
  signing_key:
67
95
  specification_version: 3
68
- summary: Synchrotron monitors a local directory tree and performs nearly instantaneous one-way synchronization of changes to a remote directory.
96
+ summary: Synchrotron monitors a local directory tree and performs nearly instantaneous one-way synchronization of changes to a remote directory using rsync.
69
97
  test_files: []
70
98