| Revision 277,
936 bytes
checked in by henning, 16 months ago
(diff) |
|
rubysleuth: test on tools in PATH, recover() as block method
|
-
Property svn:executable set to
*
|
| Line | |
|---|
| 1 | #!/usr/bin/env ruby |
|---|
| 2 | |
|---|
| 3 | require 'sleuth.rb' |
|---|
| 4 | include Sleuth |
|---|
| 5 | |
|---|
| 6 | if ARGV.count != 2 |
|---|
| 7 | $stderr.print( "Usage: #{File.basename( $0 )} <image> <pattern>\n" ) |
|---|
| 8 | exit( 1 ) |
|---|
| 9 | else |
|---|
| 10 | haystack = ARGV[0] |
|---|
| 11 | needle = ARGV[1] |
|---|
| 12 | end |
|---|
| 13 | |
|---|
| 14 | begin |
|---|
| 15 | # throw Exception if not File.stat( haystack ).readable? |
|---|
| 16 | rescue |
|---|
| 17 | $stderr.print( "'#{haystack}' could not be found or is unreadable.\n" ) |
|---|
| 18 | exit( 1 ) |
|---|
| 19 | end |
|---|
| 20 | |
|---|
| 21 | print( "Searching for '#{needle}' in '#{haystack}'..\n\n" ) |
|---|
| 22 | |
|---|
| 23 | matches = Image.new( haystack ).searchDir( needle ) |
|---|
| 24 | if matches.count > 0 |
|---|
| 25 | print( "Found #{matches.count} matches:\n" ) |
|---|
| 26 | |
|---|
| 27 | i = 0 |
|---|
| 28 | matches.each do |match| |
|---|
| 29 | i += 1 |
|---|
| 30 | print( " #{i}. #{match}\n" ) |
|---|
| 31 | end |
|---|
| 32 | |
|---|
| 33 | choice = 0 |
|---|
| 34 | while choice < 1 or choice > i |
|---|
| 35 | print( "\nChoose wisely (by number): " ) |
|---|
| 36 | begin |
|---|
| 37 | choice = $stdin.gets.to_i |
|---|
| 38 | rescue Interrupt |
|---|
| 39 | exit( 1 ) |
|---|
| 40 | end |
|---|
| 41 | end |
|---|
| 42 | |
|---|
| 43 | choice -= 1 |
|---|
| 44 | matches[choice].recover do |match| |
|---|
| 45 | print( "#{match.path}\n" ) |
|---|
| 46 | end |
|---|
| 47 | else |
|---|
| 48 | $stderr.print( "No matches found.\n" ) |
|---|
| 49 | exit( 1 ) |
|---|
| 50 | end |
|---|
Note: See
TracBrowser
for help on using the repository browser.