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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e284fa33515d0d74bc7cf8ddc014678e14f3700
4
- data.tar.gz: 55d15b651a1246f50f1982ceab55a51afb5c5477
3
+ metadata.gz: 1530083e28860bdfe9ffd4cc1c754b6026e25814
4
+ data.tar.gz: d9fad06f13778bb85fbc6206e9975885cb83a874
5
5
  SHA512:
6
- metadata.gz: 623df61d04ce2ab7b920d1718ddfbf7ac1791f617b17bac3e740a9b72235c9dabb0ea3824afe16cf07ac6d5e5391b4e41663c58701dcf465811c1e7c98044d4c
7
- data.tar.gz: 4564616b0ecc6d8cdb781ea9d84790c2a60c3c89cb63f5cf915cefaf5810369b00e13c78fc3c2fee532a0d69b576d56666f252a19e542a11a129ae98dbe1d9c2
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 necessay use the stanard lib 'pathname' like this:
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
  -------
@@ -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 2015"
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
- child_pid = Process.spawn(env, cmd)
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(child_pid == nil)
137
+ if child_pid.nil?
139
138
  child_pid = Process.spawn(env, cmd)
140
139
  else
141
- child_id = restart(child_pid, env, cmd)
140
+ child_pid = restart(child_pid, env, cmd)
142
141
  end
143
142
  else
144
143
  begin
@@ -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.3'
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
@@ -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: [File.expand_path("test/fixtures/**/*.txt")])
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.3
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: 2015-11-26 00:00:00.000000000 Z
11
+ date: 2017-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop