iwatcher 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/bin/iwatcher +46 -0
- data/iwatcher.gemspec +21 -0
- metadata +100 -0
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/iwatcher
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rb-inotify'
|
2
|
+
require 'trollop'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
@notifier = INotify::Notifier.new
|
6
|
+
@logger = Logger.new(STDOUT)
|
7
|
+
|
8
|
+
@opts = Trollop::options do
|
9
|
+
version "Inotify watcher"
|
10
|
+
banner <<-EOS
|
11
|
+
Inotify recursive watcher (ruby realization)
|
12
|
+
|
13
|
+
Usage:
|
14
|
+
watcher [options]
|
15
|
+
where [options] are:
|
16
|
+
EOS
|
17
|
+
|
18
|
+
opt :dir, 'Dir to watch', :default => '/tmp'
|
19
|
+
opt :command, 'Command execute on in_close_write message', :default => 'logger'
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_dir(dir)
|
23
|
+
@notifier.watch(dir, :create, :moved_to, :close_write, :recursive) do |event|
|
24
|
+
process_event event
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def process_event(event)
|
29
|
+
@logger.info "process event: #{event.inspect}"
|
30
|
+
file = File.join(event.absolute_name)
|
31
|
+
if File.directory? file
|
32
|
+
@logger.info "add dir: #{file} to watch"
|
33
|
+
add_dir(file)
|
34
|
+
else
|
35
|
+
@logger.info "file: #{file} process with flags: #{event.flags}"
|
36
|
+
system "#{@opts[:command]} #{file}" if event.flags.include? :close_write
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
add_dir @opts[:dir]
|
41
|
+
|
42
|
+
while true
|
43
|
+
if IO.select([@notifier.to_io], [], [], 10)
|
44
|
+
@notifier.process
|
45
|
+
end
|
46
|
+
end
|
data/iwatcher.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'iwatcher'
|
5
|
+
s.version = '0.0.1'
|
6
|
+
s.authors = ['Vasiliev D.V.']
|
7
|
+
s.email = %w(vadv.mkn@gmail.com)
|
8
|
+
s.homepage = 'https://github.com/vadv/iwatcher'
|
9
|
+
s.summary = %q{Ruby inotify watcher.}
|
10
|
+
s.description = %q{Execute command on inotify event.}
|
11
|
+
s.licenses = %w(MIT)
|
12
|
+
|
13
|
+
s.add_dependency('rb-inotify')
|
14
|
+
s.add_dependency('logger')
|
15
|
+
s.add_dependency('trollop')
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = %w(lib)
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iwatcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vasiliev D.V.
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rb-inotify
|
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
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: logger
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
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: trollop
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Execute command on inotify event.
|
63
|
+
email:
|
64
|
+
- vadv.mkn@gmail.com
|
65
|
+
executables:
|
66
|
+
- iwatcher
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- Gemfile
|
71
|
+
- Rakefile
|
72
|
+
- bin/iwatcher
|
73
|
+
- iwatcher.gemspec
|
74
|
+
homepage: https://github.com/vadv/iwatcher
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 1.8.25
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: Ruby inotify watcher.
|
99
|
+
test_files: []
|
100
|
+
has_rdoc:
|