filewatcher 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/bin/filewatcher +12 -13
- data/lib/filewatcher.rb +13 -4
- data/test/test_filewatcher.rb +14 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1530083e28860bdfe9ffd4cc1c754b6026e25814
|
4
|
+
data.tar.gz: d9fad06f13778bb85fbc6206e9975885cb83a874
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f3044ce20143591b8c257ab09eab7c0a14b1058784020abea5653fb114ef61fa4f98e6813f61a1d7c825a54a3787b9d20416cd1086a9179524068550fbfcefa
|
7
|
+
data.tar.gz: c1409c73a378c5c0debc73725904a5f8260de6e828e5e93863f8f8018eeafbb907e3aa2d735fdc423818c80aec8a8207bd76857f088106d74162d9f877bb86eb
|
data/README.md
CHANGED
@@ -221,7 +221,7 @@ over the network)
|
|
221
221
|
filewatcher.finalize # Ensure all filesystem changes made prior to
|
222
222
|
# ending the watch are handled.
|
223
223
|
|
224
|
-
If basename, relative filename or absolute filename is
|
224
|
+
If basename, relative filename or absolute filename is necessary use the standard lib 'pathname' like this:
|
225
225
|
|
226
226
|
require 'pathname'
|
227
227
|
|
@@ -237,9 +237,9 @@ with no dependencies.
|
|
237
237
|
|
238
238
|
Changelog
|
239
239
|
---------
|
240
|
-
0.5.3 Exclude files. More environment variables. Options in ruby api.
|
241
|
-
0.5.2 Start, stop and finalize API.
|
242
|
-
0.5.1 Kill and restart long running command with --restart option.
|
240
|
+
* 0.5.3 Exclude files. More environment variables. Options in ruby api.
|
241
|
+
* 0.5.2 Start, stop and finalize API.
|
242
|
+
* 0.5.1 Kill and restart long running command with --restart option.
|
243
243
|
|
244
244
|
Credits
|
245
245
|
-------
|
data/bin/filewatcher
CHANGED
@@ -6,7 +6,7 @@ require 'pathname'
|
|
6
6
|
require 'thread'
|
7
7
|
|
8
8
|
options = Trollop::options do
|
9
|
-
version "filewatcher, version #{FileWatcher.VERSION} by Thomas Flemming
|
9
|
+
version "filewatcher, version #{FileWatcher.VERSION} by Thomas Flemming 2016"
|
10
10
|
banner <<-EOS
|
11
11
|
Filewatcher scans the filesystem and executes shell commands when files changes.
|
12
12
|
|
@@ -21,13 +21,14 @@ Examples:
|
|
21
21
|
filewatcher '*.rb' 'ruby $FILENAME'
|
22
22
|
filewatcher '**/*.rb' 'ruby $FILENAME' # Watch subdirectories
|
23
23
|
|
24
|
-
Other available environment variables are BASENAME, ABSOLUTE_FILENAME,
|
24
|
+
Other available environment variables are BASENAME, ABSOLUTE_FILENAME,
|
25
25
|
RELATIVE_FILENAME, EVENT and DIRNAME.
|
26
26
|
|
27
27
|
Options:
|
28
28
|
EOS
|
29
29
|
|
30
30
|
opt :dontwait, "Do not wait for filesystem updates before running", :short => 'd', :type => :boolean, :default => false
|
31
|
+
opt :daemon, "Run in the background as system daemon.", :short => 'D', :type => :boolean, :default => false
|
31
32
|
opt :restart, "Restart process when filesystem is updated", :short => 'r', :type => :boolean, :default => false
|
32
33
|
opt :list, "Print name of files being watched"
|
33
34
|
opt :exec, "Execute file as a script when file is updated.", :short => 'e', :type => :boolean, :default => false
|
@@ -63,23 +64,19 @@ def split_files_void_escaped_whitespace(files)
|
|
63
64
|
end
|
64
65
|
|
65
66
|
files = split_files_void_escaped_whitespace(files)
|
67
|
+
child_pid = nil
|
66
68
|
|
67
69
|
def restart(child_pid, env, cmd)
|
68
|
-
Process.kill(9,child_pid)
|
70
|
+
Process.kill(9, child_pid)
|
69
71
|
Process.wait(child_pid)
|
70
72
|
rescue Errno::ESRCH
|
71
73
|
# already killed
|
72
74
|
ensure
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
if(options[:restart])
|
77
|
-
rd, wr = IO.pipe
|
78
|
-
child_pid = nil
|
75
|
+
return Process.spawn(env, cmd)
|
79
76
|
end
|
80
77
|
|
81
78
|
if(options[:exclude] != "")
|
82
|
-
options[:exclude] = split_files_void_escaped_whitespace(options[:exclude].split(" "))
|
79
|
+
options[:exclude] = split_files_void_escaped_whitespace(options[:exclude].split(" "))
|
83
80
|
end
|
84
81
|
|
85
82
|
begin
|
@@ -91,7 +88,9 @@ begin
|
|
91
88
|
puts " #{filename}"
|
92
89
|
end
|
93
90
|
end
|
94
|
-
|
91
|
+
|
92
|
+
Process.daemon(true, true) if options[:daemon]
|
93
|
+
|
95
94
|
fw.watch(options[:interval]) do |filename, event|
|
96
95
|
cmd = nil
|
97
96
|
if(options[:exec] and File.exist?(filename))
|
@@ -135,10 +134,10 @@ begin
|
|
135
134
|
end
|
136
135
|
|
137
136
|
if(options[:restart])
|
138
|
-
if
|
137
|
+
if child_pid.nil?
|
139
138
|
child_pid = Process.spawn(env, cmd)
|
140
139
|
else
|
141
|
-
|
140
|
+
child_pid = restart(child_pid, env, cmd)
|
142
141
|
end
|
143
142
|
else
|
144
143
|
begin
|
data/lib/filewatcher.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
# Simple file watcher. Detect changes in files and directories.
|
2
3
|
#
|
3
4
|
# Issues: Currently doesn't monitor changes in directorynames
|
@@ -6,7 +7,7 @@ class FileWatcher
|
|
6
7
|
attr_accessor :filenames
|
7
8
|
|
8
9
|
def self.VERSION
|
9
|
-
return '0.5.
|
10
|
+
return '0.5.4'
|
10
11
|
end
|
11
12
|
|
12
13
|
def update_spinner(label)
|
@@ -39,7 +40,7 @@ class FileWatcher
|
|
39
40
|
@sleep = sleep
|
40
41
|
if(@interval and @interval > 0)
|
41
42
|
@sleep = @interval
|
42
|
-
end
|
43
|
+
end
|
43
44
|
@stored_update = on_update
|
44
45
|
@keep_watching = true
|
45
46
|
if(@dontwait)
|
@@ -119,7 +120,7 @@ class FileWatcher
|
|
119
120
|
end
|
120
121
|
@filenames = @filtered_filenames
|
121
122
|
end
|
122
|
-
|
123
|
+
|
123
124
|
@filenames.each do |filename|
|
124
125
|
mtime = File.exist?(filename) ? File.stat(filename).mtime : Time.new(0)
|
125
126
|
snapshot[filename] = mtime
|
@@ -164,7 +165,7 @@ class FileWatcher
|
|
164
165
|
if(!patterns.kind_of?Array)
|
165
166
|
patterns = [patterns]
|
166
167
|
end
|
167
|
-
patterns.map { |it| Dir[fulldepth(it)] }.flatten.uniq
|
168
|
+
patterns.map { |it| Dir[fulldepth(expand_path(it))] }.flatten.uniq
|
168
169
|
end
|
169
170
|
|
170
171
|
private
|
@@ -177,4 +178,12 @@ class FileWatcher
|
|
177
178
|
end
|
178
179
|
end
|
179
180
|
|
181
|
+
def expand_path(pattern)
|
182
|
+
if pattern.start_with?('~')
|
183
|
+
File.expand_path(pattern)
|
184
|
+
else
|
185
|
+
pattern
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
180
189
|
end
|
data/test/test_filewatcher.rb
CHANGED
@@ -28,7 +28,7 @@ describe FileWatcher do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should exclude selected file patterns" do
|
31
|
-
filewatcher = FileWatcher.new(File.expand_path('test/fixtures/**/*'), exclude
|
31
|
+
filewatcher = FileWatcher.new(File.expand_path('test/fixtures/**/*'), :exclude => [File.expand_path("test/fixtures/**/*.txt")])
|
32
32
|
filtered_fixtures =
|
33
33
|
%w(test/fixtures/file4.rb
|
34
34
|
test/fixtures/subdir/file6.rb
|
@@ -62,6 +62,19 @@ describe FileWatcher do
|
|
62
62
|
filewatcher.filenames.should.satisfy &includes_all(explicit_relative_fixtures)
|
63
63
|
end
|
64
64
|
|
65
|
+
it "should handle tilde expansion" do
|
66
|
+
filename = File.expand_path('~/file_watcher_1.txt')
|
67
|
+
open(filename, 'w') { |f| f.puts 'content1' }
|
68
|
+
|
69
|
+
filewatcher = FileWatcher.new('~/file_watcher_1.txt')
|
70
|
+
|
71
|
+
begin
|
72
|
+
filewatcher.filenames.should == [filename]
|
73
|
+
ensure
|
74
|
+
FileUtils.rm(filename)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
65
78
|
it "should detect file deletions" do
|
66
79
|
filename = "test/fixtures/file1.txt"
|
67
80
|
open(filename,"w") { |f| f.puts "content1" }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filewatcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Flemming
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trollop
|