colortail 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.markdown +4 -0
- data/TODO.markdown +0 -5
- data/VERSION +1 -1
- data/colortail.gemspec +7 -3
- data/lib/colortail.rb +9 -3
- data/lib/colortail/application.rb +27 -5
- data/lib/colortail/configuration.rb +6 -2
- data/test/colortail/test_application.rb +86 -0
- data/test/colortail/test_configuration.rb +117 -0
- data/test/helper.rb +4 -0
- data/test/test_colortail.rb +64 -4
- metadata +6 -2
data/Changelog.markdown
CHANGED
data/TODO.markdown
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
data/colortail.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{colortail}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Eric Lubow"]
|
12
|
-
s.date = %q{2010-04-
|
12
|
+
s.date = %q{2010-04-26}
|
13
13
|
s.default_executable = %q{colortail}
|
14
14
|
s.description = %q{Tail a file and color lines based on regular expressions within that line. By setting up multiple expression and color groups in the configuration file, you can apply highlighting to a file while its being tailed.}
|
15
15
|
s.email = %q{eric@lubow.org}
|
@@ -33,6 +33,8 @@ Gem::Specification.new do |s|
|
|
33
33
|
"lib/colortail.rb",
|
34
34
|
"lib/colortail/application.rb",
|
35
35
|
"lib/colortail/configuration.rb",
|
36
|
+
"test/colortail/test_application.rb",
|
37
|
+
"test/colortail/test_configuration.rb",
|
36
38
|
"test/helper.rb",
|
37
39
|
"test/test_colortail.rb"
|
38
40
|
]
|
@@ -42,7 +44,9 @@ Gem::Specification.new do |s|
|
|
42
44
|
s.rubygems_version = %q{1.3.5}
|
43
45
|
s.summary = %q{Tail a file and color lines based on regular expressions within that line}
|
44
46
|
s.test_files = [
|
45
|
-
"test/
|
47
|
+
"test/colortail/test_application.rb",
|
48
|
+
"test/colortail/test_configuration.rb",
|
49
|
+
"test/helper.rb",
|
46
50
|
"test/test_colortail.rb",
|
47
51
|
"examples/colortail.rb"
|
48
52
|
]
|
data/lib/colortail.rb
CHANGED
@@ -30,7 +30,13 @@ module ColorTail
|
|
30
30
|
:hidden => 8
|
31
31
|
}
|
32
32
|
|
33
|
-
|
33
|
+
attr_accessor :color_matchers
|
34
|
+
|
35
|
+
def initialize()
|
36
|
+
# This is an instance variable in case we tail
|
37
|
+
# multiple files with different groupings
|
38
|
+
@color_matchers = Array.new
|
39
|
+
end
|
34
40
|
|
35
41
|
def log(filename, message, line_prefix=nil)
|
36
42
|
# Add the filename to the message
|
@@ -39,7 +45,7 @@ module ColorTail
|
|
39
45
|
color = :none
|
40
46
|
attribute = nil
|
41
47
|
|
42
|
-
|
48
|
+
@color_matchers.each do |filter|
|
43
49
|
if message =~ filter[:match]
|
44
50
|
color = filter[:color]
|
45
51
|
attribute = filter[:attribute]
|
@@ -67,7 +73,7 @@ module ColorTail
|
|
67
73
|
end
|
68
74
|
|
69
75
|
def add_color_matcher( options )
|
70
|
-
|
76
|
+
@color_matchers.push( options )
|
71
77
|
end
|
72
78
|
end
|
73
79
|
|
@@ -8,16 +8,19 @@ module ColorTail
|
|
8
8
|
options = opt[:options]
|
9
9
|
|
10
10
|
# Deal with any/all options issues
|
11
|
-
if
|
12
|
-
$stderr.puts
|
11
|
+
if opt[:invalid_argument]
|
12
|
+
$stderr.puts opt[:invalid_argument]
|
13
13
|
options[:help] = true
|
14
14
|
end
|
15
15
|
|
16
|
+
# Show the help menu if desired
|
16
17
|
if options[:help]
|
17
18
|
$stderr.puts opt.opts
|
18
19
|
return 1
|
19
20
|
end
|
20
|
-
|
21
|
+
|
22
|
+
|
23
|
+
# The meat of the program
|
21
24
|
begin
|
22
25
|
# Read the config file if it exists
|
23
26
|
if File.exists?(options[:conf])
|
@@ -40,6 +43,22 @@ module ColorTail
|
|
40
43
|
return 1
|
41
44
|
end
|
42
45
|
|
46
|
+
# Before we go any further, check for existance of files
|
47
|
+
@files_exist = false
|
48
|
+
files.each do |file|
|
49
|
+
if File.exists?(file)
|
50
|
+
@files_exist = true
|
51
|
+
break
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# If we have no files, tell them and show the help
|
56
|
+
unless @files_exist
|
57
|
+
$stderr.puts "Please check to make sure the files exist ..."
|
58
|
+
$stderr.puts opt.opts
|
59
|
+
return 1
|
60
|
+
end
|
61
|
+
|
43
62
|
logger = ColorTail::Colorize.new()
|
44
63
|
|
45
64
|
# Add the color match array if we aren't using the default
|
@@ -74,13 +93,13 @@ module ColorTail
|
|
74
93
|
|
75
94
|
# If we get a CTRL-C, catch it (rescue) and send it for cleanup
|
76
95
|
rescue Interrupt
|
77
|
-
|
96
|
+
thread_cleanup(threads)
|
78
97
|
end
|
79
98
|
|
80
99
|
return 0
|
81
100
|
end
|
82
101
|
|
83
|
-
def
|
102
|
+
def thread_cleanup(threads)
|
84
103
|
threads.each do |thread|
|
85
104
|
thread.kill
|
86
105
|
end
|
@@ -90,6 +109,9 @@ module ColorTail
|
|
90
109
|
end
|
91
110
|
end
|
92
111
|
|
112
|
+
class Cleanup
|
113
|
+
end
|
114
|
+
|
93
115
|
|
94
116
|
class FileDoesNotExist < StandardError
|
95
117
|
end
|
@@ -6,7 +6,7 @@ module ColorTail
|
|
6
6
|
if File.exists?(conf)
|
7
7
|
@config = File.read(conf)
|
8
8
|
else
|
9
|
-
raise FileDoesNotExist, "Config file #{
|
9
|
+
raise FileDoesNotExist, "Config file #{@config_file} cannot be found."
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -15,7 +15,8 @@ module ColorTail
|
|
15
15
|
if groupings.has_key?( group )
|
16
16
|
return groupings[group]
|
17
17
|
else
|
18
|
-
|
18
|
+
$stderr.puts "No such group '#{group}', falling back to default."
|
19
|
+
return "'default' => []"
|
19
20
|
end
|
20
21
|
else
|
21
22
|
raise ComplexRecord, "Config file syntax error"
|
@@ -93,6 +94,9 @@ module ColorTail
|
|
93
94
|
self[:options] = options
|
94
95
|
rescue OptionParser::InvalidOption => e
|
95
96
|
self[:invalid_argument] = e.message
|
97
|
+
@opts.parse(args, flags={ :delete_invalid_opts => true })
|
98
|
+
self[:files] = args
|
99
|
+
self[:options] = options
|
96
100
|
end
|
97
101
|
end
|
98
102
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module TestColortail
|
4
|
+
|
5
|
+
class ApplicationTest < Test::Unit::TestCase
|
6
|
+
# No context name necessary since this is to redirect $stdout
|
7
|
+
context "" do
|
8
|
+
setup do
|
9
|
+
ARGV.clear
|
10
|
+
|
11
|
+
@stdout_orig = $stdout
|
12
|
+
$stdout = StringIO.new
|
13
|
+
end
|
14
|
+
|
15
|
+
teardown do
|
16
|
+
$stdout = @stdout_orig
|
17
|
+
end
|
18
|
+
|
19
|
+
context "" do
|
20
|
+
setup do
|
21
|
+
@stderr_orig = $stderr
|
22
|
+
$stderr = StringIO.new
|
23
|
+
end
|
24
|
+
|
25
|
+
teardown do
|
26
|
+
$stderr = @stderr_orig
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
context "With no options or files" do
|
31
|
+
setup do
|
32
|
+
ARGV.clear
|
33
|
+
end
|
34
|
+
|
35
|
+
should "show the help menu" do
|
36
|
+
ColorTail::Application.run!(*ARGV)
|
37
|
+
assert_match "Usage:", $stderr.string
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "With '-h' option and no files" do
|
42
|
+
setup do
|
43
|
+
ARGV.clear
|
44
|
+
ARGV.push("-h")
|
45
|
+
end
|
46
|
+
|
47
|
+
should "show the help menu" do
|
48
|
+
ColorTail::Application.run!(*ARGV)
|
49
|
+
assert_match "Usage:", $stderr.string
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "With non-existant option and no files" do
|
54
|
+
setup do
|
55
|
+
ARGV.clear
|
56
|
+
ARGV.push("-zdfkjlsd")
|
57
|
+
end
|
58
|
+
|
59
|
+
should "show the help menu" do
|
60
|
+
ColorTail::Application.run!(*ARGV)
|
61
|
+
assert_match "invalid option:", $stderr.string
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
should "kill all threads and exit cleanly with the word 'Terminating...'" do
|
66
|
+
threads = Array.new
|
67
|
+
threads.push(Thread.new { sleep }, Thread.new { sleep })
|
68
|
+
assert_equal 2, threads.size
|
69
|
+
assert_equal "sleep", threads[0].status
|
70
|
+
assert_equal "sleep", threads[1].status
|
71
|
+
begin
|
72
|
+
ColorTail::Application.thread_cleanup(threads)
|
73
|
+
rescue SystemExit => e
|
74
|
+
assert_equal "Terminating...\n", $stderr.string
|
75
|
+
assert_equal 0, e.status
|
76
|
+
end
|
77
|
+
assert_equal false, threads[0].status
|
78
|
+
assert_equal false, threads[1].status
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module TestColortail
|
4
|
+
|
5
|
+
class OptionsTest < Test::Unit::TestCase
|
6
|
+
# No context name necessary since this is to redirect $stdout
|
7
|
+
context "" do
|
8
|
+
setup do
|
9
|
+
ARGV.clear
|
10
|
+
|
11
|
+
@stdout_orig = $stdout
|
12
|
+
$stdout = StringIO.new
|
13
|
+
end
|
14
|
+
|
15
|
+
teardown do
|
16
|
+
$stdout = @stdout_orig
|
17
|
+
end
|
18
|
+
|
19
|
+
should "return an options object with no arguments" do
|
20
|
+
@opt = ColorTail::Options.new(ARGV)
|
21
|
+
assert_equal @opt.class, ColorTail::Options
|
22
|
+
end
|
23
|
+
|
24
|
+
context "With a valid options class instance" do
|
25
|
+
setup do
|
26
|
+
ARGV.clear
|
27
|
+
@opt = ColorTail::Options.new(ARGV)
|
28
|
+
end
|
29
|
+
|
30
|
+
should "have the group value set as default" do
|
31
|
+
assert_equal @opt[:options][:group], "default"
|
32
|
+
end
|
33
|
+
|
34
|
+
should "have the help switch set to false" do
|
35
|
+
assert_equal @opt[:options][:help], false
|
36
|
+
end
|
37
|
+
|
38
|
+
should "have the show list switch set to false" do
|
39
|
+
assert_equal @opt[:options][:list], false
|
40
|
+
end
|
41
|
+
|
42
|
+
should "have an empty files array" do
|
43
|
+
assert_equal @opt[:files].size, 0
|
44
|
+
end
|
45
|
+
|
46
|
+
should "have a possible config file to test for" do
|
47
|
+
assert_not_nil @opt[:options][:conf]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
should "raise FileDoesNotExist error on non-existant config file" do
|
52
|
+
ARGV.clear
|
53
|
+
config_file = String.new
|
54
|
+
ARGV.push("-c",config_file)
|
55
|
+
assert_raise( ColorTail::FileDoesNotExist ) { @opt = ColorTail::Options.new(ARGV) }
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
class ConfigurationTest < Test::Unit::TestCase
|
63
|
+
# No context name necessary since this is to redirect $stdout
|
64
|
+
context "" do
|
65
|
+
setup do
|
66
|
+
ARGV.clear
|
67
|
+
|
68
|
+
@stdout_orig = $stdout
|
69
|
+
$stdout = StringIO.new
|
70
|
+
end
|
71
|
+
|
72
|
+
teardown do
|
73
|
+
$stdout = @stdout_orig
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
should "raise a FileDoesNotExist error for non-existant file" do
|
78
|
+
config_file = String.new
|
79
|
+
assert_raise( ColorTail::FileDoesNotExist ) { @config = ColorTail::Configuration.new(config_file) }
|
80
|
+
end
|
81
|
+
|
82
|
+
context "With a valid configuration instance" do
|
83
|
+
setup do
|
84
|
+
@stderr_orig = $stderr
|
85
|
+
$stderr = StringIO.new
|
86
|
+
|
87
|
+
@config_file = File.join(File.dirname(__FILE__), '..', '..', 'examples', 'colortail.rb')
|
88
|
+
|
89
|
+
@config = ColorTail::Configuration.new("#{@config_file}")
|
90
|
+
end
|
91
|
+
|
92
|
+
teardown do
|
93
|
+
$stderr = @stderr_orig
|
94
|
+
end
|
95
|
+
|
96
|
+
should "be a valid configuration instance" do
|
97
|
+
assert_equal @config.class, ColorTail::Configuration
|
98
|
+
end
|
99
|
+
|
100
|
+
should "fallback to 'default' grouping when a non-existent match_group is specified" do
|
101
|
+
@match_group = @config.load_opts('doesNotExist')
|
102
|
+
assert_match "No such group '", $stderr.string
|
103
|
+
assert_equal @match_group, "'default' => []"
|
104
|
+
end
|
105
|
+
|
106
|
+
should "display match groups" do
|
107
|
+
@match_group = @config.load_opts('default')
|
108
|
+
@config.display_match_groups()
|
109
|
+
assert_match " * ", $stdout.string
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
data/test/helper.rb
CHANGED
data/test/test_colortail.rb
CHANGED
@@ -1,7 +1,67 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module TestColortail
|
4
|
+
|
5
|
+
class ColortailTest < Test::Unit::TestCase
|
6
|
+
# No context name necessary since this is to redirect $stdout
|
7
|
+
context "" do
|
8
|
+
setup do
|
9
|
+
ARGV.clear
|
10
|
+
|
11
|
+
@stdout_orig = $stdout
|
12
|
+
$stdout = StringIO.new
|
13
|
+
end
|
14
|
+
|
15
|
+
teardown do
|
16
|
+
$stdout = @stdout_orig
|
17
|
+
end
|
18
|
+
|
19
|
+
context "With valid logger class" do
|
20
|
+
setup do
|
21
|
+
@logger = ColorTail::Colorize.new()
|
22
|
+
end
|
23
|
+
|
24
|
+
should "be a valid logger class" do
|
25
|
+
@class = @logger.class
|
26
|
+
assert_equal @class, ColorTail::Colorize
|
27
|
+
end
|
28
|
+
|
29
|
+
should "show a line with no prefix" do
|
30
|
+
@logger.show('My test line', nil)
|
31
|
+
assert_equal $stdout.string, "My test line\n"
|
32
|
+
end
|
33
|
+
|
34
|
+
should "show a line with 'filename:' as a prefix" do
|
35
|
+
@logger.show('My test line', 'filename:')
|
36
|
+
assert_equal $stdout.string, "filename:My test line\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
should "add nothing to the color matchers class variable with an empty match group" do
|
40
|
+
match_group = Array.new
|
41
|
+
assert_equal match_group, @logger.color_matchers
|
42
|
+
match_group.push( 'default' => [] )
|
43
|
+
@logger.add_color_matcher( 'default' => [] )
|
44
|
+
assert_equal match_group, @logger.color_matchers
|
45
|
+
end
|
46
|
+
|
47
|
+
context "and an empty match group" do
|
48
|
+
setup do
|
49
|
+
@logger.add_color_matcher( 'default' => [] )
|
50
|
+
end
|
51
|
+
|
52
|
+
should "say 'My test line' with no prefix" do
|
53
|
+
@logger.log('testfile','My test line')
|
54
|
+
assert_equal $stdout.string, "\e[0mMy test line\e[0m\n"
|
55
|
+
end
|
56
|
+
|
57
|
+
should "say 'My test line' with 'testfile: ' as the prefix" do
|
58
|
+
@logger.log('testfile','My test line','testfile: ')
|
59
|
+
assert_equal $stdout.string, "\e[0mtestfile:\e[0m\e[0mMy test line\e[0m\n"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
6
65
|
end
|
7
|
-
|
66
|
+
|
67
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colortail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Lubow
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-04-
|
12
|
+
date: 2010-04-26 00:00:00 -04:00
|
13
13
|
default_executable: colortail
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -56,6 +56,8 @@ files:
|
|
56
56
|
- lib/colortail.rb
|
57
57
|
- lib/colortail/application.rb
|
58
58
|
- lib/colortail/configuration.rb
|
59
|
+
- test/colortail/test_application.rb
|
60
|
+
- test/colortail/test_configuration.rb
|
59
61
|
- test/helper.rb
|
60
62
|
- test/test_colortail.rb
|
61
63
|
has_rdoc: true
|
@@ -87,6 +89,8 @@ signing_key:
|
|
87
89
|
specification_version: 3
|
88
90
|
summary: Tail a file and color lines based on regular expressions within that line
|
89
91
|
test_files:
|
92
|
+
- test/colortail/test_application.rb
|
93
|
+
- test/colortail/test_configuration.rb
|
90
94
|
- test/helper.rb
|
91
95
|
- test/test_colortail.rb
|
92
96
|
- examples/colortail.rb
|