watch-paths 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/History.txt +5 -0
  2. data/bin/watch-paths +14 -7
  3. data/lib/watch-paths.rb +12 -7
  4. metadata +3 -3
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.1.0 / 2007-09-05
2
+
3
+ * 1 minor enhancement
4
+ * recursive option
5
+
1
6
  == 1.0.0 / 2007-08-03
2
7
 
3
8
  * 1 major enhancement
data/bin/watch-paths CHANGED
@@ -1,15 +1,22 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env ruby -ws
2
2
 
3
- require 'rubygems'
4
- require 'watch-paths'
3
+ begin require 'rubygems' rescue LoadError end
5
4
 
6
- changes = WatchPaths.new.watch ARGV
5
+ require 'watch-paths'
7
6
 
8
- if changes.empty?
7
+ if defined? $h then
8
+ puts "#{File.basename $0} [options] paths"
9
+ puts " -h display help"
10
+ puts " -r process paths recursively"
9
11
  exit 0
10
- else
12
+ end
13
+
14
+ changes = Watchpaths.new.watch ARGV
15
+
16
+ unless changes.empty?
11
17
  changes.each do |path,files|
12
- STDERR.puts "Warning: checksum failures in #{path}:", files
18
+ STDERR.puts "Warning: checksum mismatch in #{path} for:", files
13
19
  end
14
20
  exit 1
15
21
  end
22
+
data/lib/watch-paths.rb CHANGED
@@ -4,12 +4,14 @@ require 'digest/md5'
4
4
 
5
5
  include FileUtils
6
6
 
7
+ $r ||= false
8
+
7
9
  ##
8
10
  # A poor man's configuration management tool.
9
11
 
10
12
  class WatchPaths
11
13
 
12
- VERSION = '1.0.0'
14
+ VERSION = '1.1.0'
13
15
 
14
16
  ##
15
17
  # File used to record checksums in each path scanned
@@ -17,18 +19,20 @@ class WatchPaths
17
19
  MANIFEST = '.chksum_manifest.yml'
18
20
 
19
21
  ##
20
- # compares file checksums for a set of paths
22
+ # compares file checksums for a set of directory paths
21
23
 
22
24
  def watch( paths )
23
25
  chksum_errors = {}
24
- paths.each do |path|
25
- cd path do
26
+ paths.map!{ |path| Dir["#{path}/**/*"] } if $r
27
+ dirs = paths.select{ |path| File.directory? path }
28
+ dirs.each do |dir|
29
+ cd dir do
26
30
  begin
27
31
  chksum_manifest = load
28
32
  chksum_manifest = check chksum_manifest
29
33
  dump chksum_manifest
30
34
  rescue ChecksumError => error
31
- chksum_errors[path] = error.message
35
+ chksum_errors[dir] = error.message
32
36
  end
33
37
  end
34
38
  end
@@ -47,7 +51,7 @@ class WatchPaths
47
51
  # Write YAML file containing checksum manifest
48
52
 
49
53
  def dump( chksum_manifest )
50
- File.open(MANIFEST,'w'){ |f| YAML.dump chksum_manifest, f }
54
+ File.open(MANIFEST,'w') { |f| YAML.dump chksum_manifest, f }
51
55
  end
52
56
 
53
57
  ##
@@ -55,7 +59,8 @@ class WatchPaths
55
59
 
56
60
  def create_chksum_manifest
57
61
  chksum_manifest = {}
58
- Dir['*'].each do |file|
62
+ files = Dir['*'].select{ |f| File.file? f }
63
+ files.each do |file|
59
64
  chksum_manifest[file] = Digest::MD5.hexdigest File.read(file)
60
65
  end
61
66
  chksum_manifest
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: watch-paths
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.0
7
- date: 2007-08-07 00:00:00 -04:00
6
+ version: 1.1.0
7
+ date: 2007-09-06 00:00:00 -04:00
8
8
  summary: "== FEATURES/PROBLEMS: * A poor man's configuration management * Does not report files added since last scan * Error handling is minimal"
9
9
  require_paths:
10
10
  - lib
@@ -61,5 +61,5 @@ dependencies:
61
61
  requirements:
62
62
  - - ">="
63
63
  - !ruby/object:Gem::Version
64
- version: 1.2.2
64
+ version: 1.3.0
65
65
  version: