Skip to content

Commit

Permalink
removed special purpose parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Lütke committed Dec 5, 2009
1 parent 423ffb6 commit 3e719ac
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 237 deletions.
170 changes: 165 additions & 5 deletions Manifest.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,166 @@
.git/COMMIT_EDITMSG
.git/FETCH_HEAD
.git/HEAD
.git/ORIG_HEAD
.git/config
.git/description
.git/hooks/applypatch-msg.sample
.git/hooks/commit-msg.sample
.git/hooks/post-commit.sample
.git/hooks/post-receive.sample
.git/hooks/post-update.sample
.git/hooks/pre-applypatch.sample
.git/hooks/pre-commit.sample
.git/hooks/pre-rebase.sample
.git/hooks/prepare-commit-msg.sample
.git/hooks/update.sample
.git/index
.git/info/exclude
.git/logs/HEAD
.git/logs/refs/heads/master
.git/logs/refs/remotes/origin/3cb1cb92dc196b1d84a30ed12b906ad8a141aa27
.git/logs/refs/remotes/origin/HEAD
.git/logs/refs/remotes/origin/master
.git/objects/07/4ad9286bf025d13ad17edd8aea7be5769ee3d2
.git/objects/07/65dda8fe36c1682faf012e53cebd968de49557
.git/objects/0a/4bc0f77dd330e9e965870c14cc949a7832fd0b
.git/objects/0a/e16403b3e558d00643f004ec09f334d4f2b0f0
.git/objects/0c/7d21bfe13e3153ea2f9b87a235289a0ba2fa0b
.git/objects/0d/4f5bfd4ea3b56fb4487c22cbbd33c8917a480d
.git/objects/0e/54c258158ebcefe13043200190acf2581a2736
.git/objects/11/4e1e4ed075af2fabedf142999fafa55069d2b8
.git/objects/12/c08dbcb6e9d747af2c9ab4d1b534fc65543a04
.git/objects/13/d34b561193da18ea9e4c23baa2889925b136c2
.git/objects/14/7cadaa8ea2f5b519d51d463a054506d3fa2daa
.git/objects/15/aa7cb94cc034e1d40bd8e6dfb18a43fb71e963
.git/objects/17/b3f58e34f8d603979c6203195ffa7077ddb6b4
.git/objects/18/5140bb62cf8865eed0b4190ac56f268eb61659
.git/objects/20/a9a41229d300bb02702e37542c485d562283fc
.git/objects/24/81a1ea86da7690b6933b6c3e43df199ae2759f
.git/objects/29/04ad9c76d02d613025cda698a01909aae481c3
.git/objects/2a/0da5f3347d89b15f4595d1d86e36edd985b37e
.git/objects/2a/6f9d3ffa2c1bde690a5f83ff1256aed1df51e5
.git/objects/2b/4f1b1c8f1e8f29808e84c1253489f9cc6e9b23
.git/objects/2c/28a140a83b8d90561dcb1eff7c0740cc5c466a
.git/objects/2c/3ad655c9f5788144375877d35e2012c178e1f9
.git/objects/2c/9b2f15de27a959f323b8025d47a7d54023745a
.git/objects/2e/a4ac462fd5b94ca2d6d4dab553d53a161b8aa6
.git/objects/2e/a55bebb429dece7e143a061118386eac9f2ecc
.git/objects/2e/ef97fd572854ca599c5a429f849819ae001205
.git/objects/2e/f56d503616c21a1f8e0e7d4f8dc9daec731d3f
.git/objects/2f/2da91b54af9c05d7411ecc1c39c1617f1f4043
.git/objects/31/ac1c15950e868882cbc83631bcbd43d54d49fe
.git/objects/34/7df9d1dcf91b5d8095d3536a54e4b5aa6d8206
.git/objects/34/cb8b80da1461d7a023e0c1cca2c488b6a1e1fc
.git/objects/38/85d79b0ab9bc36154c6bb195ad5f58e7c49558
.git/objects/39/93882cbe4e210056dce9bbe1b4f2d23d89fb8f
.git/objects/3c/b1cb92dc196b1d84a30ed12b906ad8a141aa27
.git/objects/3c/e0e0c0bdce32b290a617d4bf1707a9828fbafa
.git/objects/3d/67e7591e2a97edc5e1f32838e7bcf4c0abb7b1
.git/objects/3d/72a06cf4d4a8f8da488a816c61b5a3af89c1f7
.git/objects/3f/7f20971498dc181ee1df392377962dd9cb0ac3
.git/objects/41/6c66f50cea775311f912b1a1627491b6c4ad22
.git/objects/42/3ffb6b46440d04d967a8ff5b6f76dd33ee005c
.git/objects/48/bba832ddd367502dec4976ad7ad91f3b7e2212
.git/objects/4a/82ff9fe6083109ff92ade4dde75244aed4333e
.git/objects/4c/456a3a867cc6e6589058e9a04d5e8f7f138d0e
.git/objects/4d/691f17377f16d09f6f647274c2e97a055ee01c
.git/objects/4e/5c1d2b701a90cc9fa3f889c276091235330b58
.git/objects/4e/c6a0b2d721a91d44dc5064180c6c9e9381e026
.git/objects/51/bf54fff55b5435bec597ec2c53c60331791f2d
.git/objects/53/ee2ca9294cba5b5feca8341c1686d8bea78320
.git/objects/55/60c2a365673e857e6cfe2ea60e27e7e8a00a9b
.git/objects/55/9c5567b25ddf52539d7cd4d174499fe1245fc0
.git/objects/58/a368e2cd949ddecd48530e717972f57d3e4cc4
.git/objects/5a/50ef9acf9c6d4b4ef28c85d92176c1fb673bbc
.git/objects/5b/0a2a4e9b7b8ebb961458fdedbb7fa84169844f
.git/objects/5c/01ef5c66079b28914a4c66c91f54d60d9e64f2
.git/objects/5c/4f9e74658278d187438bcdf769d3f47f306aab
.git/objects/5f/d4e817894d4c569bd9239fb51cb7c6b3fdb39a
.git/objects/60/e6f791b425216498078f47fa73a1251674621d
.git/objects/61/8473d9ea31f9438c290439942dd66c0426519b
.git/objects/68/4563cb73016860c490c8417611ba30389b6a3b
.git/objects/68/80b0fe88669a8b674a51e942e081c456a87198
.git/objects/69/cfadbf94e845e48bfc06ec546cc66f9774eff4
.git/objects/6a/afe1103b308a08e138124dd3dc2ba8f6229aae
.git/objects/6b/835c3b509b946073f9982f3deaed02ebd886c9
.git/objects/6b/a9b4990a48d5630b250e1fa755a40bbe694786
.git/objects/6c/76612a21bfa3c36dcbb460f6d833a7c2eefeae
.git/objects/6f/9fdeb5aeededced2757f6371ae99fd94c8f77f
.git/objects/6f/a67dd445c01358acb9e4f65ed968a04df9aeaf
.git/objects/72/348477a1ef597f318f3481a4021b9c27c93e1f
.git/objects/73/d40d19d6071e1ce12b2d26cdecd6ff549f073b
.git/objects/7e/1ed59b838c799fa0eed6ad9083073343ee059f
.git/objects/81/157b2b72e484bae81bcf73a2f878a2d27880ad
.git/objects/81/51694f42a34ffeabf9bebaa7ef6f0dc85666e9
.git/objects/83/916674da84c7ce8004b988f6350627222a5188
.git/objects/84/38f02d5de1976393324974df9388fbd058fae6
.git/objects/84/ef9646dedffdc087a762a5c0131169a6da7782
.git/objects/89/35f726967181bf0a8dd776a8a643587d225491
.git/objects/89/478d30f5c28c6a505f27a5ba0846e04aef4196
.git/objects/93/a0697eeb2ebf39059ea24a3f94d6896b0a738e
.git/objects/94/678932f192e77d163cd5bd266b9b61ecb9c861
.git/objects/94/8081d177ae3347417a8911eae102f5d453eea0
.git/objects/9b/de48b25488be00d53a43532889000a8365282b
.git/objects/9c/6f69bc97cc79cb67e7e0add68bf5254ca2d5dd
.git/objects/a0/c2867973e30144d87a4db070e1506f276f3444
.git/objects/a2/07534d0f0c5beda7083625511d7b56fee6829a
.git/objects/a2/11c0e1940ca42be847bd8d7290bfac3ccfc56e
.git/objects/a2/2216df476f02a02f9a14f3223881aac7ec2872
.git/objects/a7/133cc1d3322916e46ab250caf9099d9efd5f80
.git/objects/a7/791b9f50d912ca3c9ce89cb296da728134628c
.git/objects/a7/ca11e69527d8e1da9e05ebab6c608cb39b393a
.git/objects/a8/66e5d4899ea9c3d32153973cc465da02b1f243
.git/objects/ad/0c16d4a7719f6e48314dbade450045b264167d
.git/objects/ad/351604df4f1f31f07d4170586b7922aa9f2d10
.git/objects/b0/776436425c2cf187e6c9844de8189eb70e554a
.git/objects/b1/49b4df1712e6229aee72cb9de018559a341beb
.git/objects/b1/d5450f60f1796ae76eee9bb0fc5c1a6a133c9d
.git/objects/b7/69625e57eb1a1bad591f602fc874af1517febf
.git/objects/ba/704288262ee61481194174c794166017741c61
.git/objects/be/137935629e8b37e9a73b9b6136e2a7c0f1ac58
.git/objects/c2/7f6559350f7adb19d43742b55b2f91d07b6550
.git/objects/c4/5932ad2a3a52ea8ef5e63ff46da5a59220fe18
.git/objects/c7/15d3c368c22eba9f6b891cdb48ca02d9aacc9a
.git/objects/c7/de5d21e9407ab6e9459c1326e39658cae6140e
.git/objects/c8/90d7cd6c7448589ca4e8a0a53ecbada48d2044
.git/objects/cc/282828b1e3fe43aa3d267f9e0d442a1278899e
.git/objects/cd/7ccf92f1c2dd5232f70fa5a03ad8eefb223e38
.git/objects/ce/867f952877cb329a54bc7b66f305eaf6884424
.git/objects/d4/5ac4d0c9af69f25101640eff55bdd004dca4e9
.git/objects/d5/9ae3d4e2fc4deaae1db71baec0a98fe894052d
.git/objects/d5/d4da8e6786edbe86f91c0390f4d1920078c158
.git/objects/d7/0eea2289e5bfacbc9db3ad2b4a23dce63f79e1
.git/objects/d7/3b40b8ebdab06b9f60512a62df1ba5f3fdd425
.git/objects/dd/a75ffe0c5c9c3364cb8d134a6738123f482915
.git/objects/dd/ea3d1c4b9bc66b7bbc7c51c554e19255947d49
.git/objects/df/ab5c8ffc5cc101f7c3036546104056db1ca1c4
.git/objects/e4/3a656d4a10c7dd3c8d77898498449d6cc9b7e0
.git/objects/e4/8464df56bf487e96e21ea99487330266dae3c9
.git/objects/e5/49cee6229b3c814e7b233643d3782b79753f0f
.git/objects/e9/1bcad800b028bc40c2cd16be9b55502ee8e6d2
.git/objects/eb/9115feea5440e5b136101bc0fb290bcb3dc49d
.git/objects/eb/d5bc1ecc6cc18965389d5ebefbc26b595da74f
.git/objects/ed/d53826c5e7577e1652c85b8e3070fceb082403
.git/objects/ed/f64bfb7c6bd5bc7c4489d6a31ce355a6ea4f60
.git/objects/f2/67bbe23158bb97a8517c5d48fd24da0990410c
.git/objects/f4/15af7e70bbed51b80762bd47df0c61d5e530f1
.git/objects/f4/b1c2867b0b2bc52e840b76c2fd61fbecb6eb7d
.git/objects/f4/fc8a5d1a701fe94d046cc41211072854b43ce7
.git/objects/f5/156ee67d016e6f651700709ebc98c8995aa053
.git/objects/f8/07539c823f11983c75a95a5e6e06af415294ce
.git/objects/fa/ad3148b489acce84e91935c850c82fb2c42bc3
.git/objects/fb/ee2d18d87c0cc3f63686590321e673520582af
.git/objects/fd/2f2e4a65619a31da8d577e5d07f6c2fe4de377
.git/objects/fd/da047db28fca2a3ccd6dd508e080379f6195d0
.git/objects/pack/pack-624e8a418388f1f608033bc75af8982ce8e09c4d.idx
.git/objects/pack/pack-624e8a418388f1f608033bc75af8982ce8e09c4d.pack
.git/packed-refs
.git/refs/heads/master
.git/refs/remotes/origin/3cb1cb92dc196b1d84a30ed12b906ad8a141aa27
.git/refs/remotes/origin/HEAD
.git/refs/remotes/origin/master
.gitignore
History.txt
Manifest.txt
PostInstall.txt
Expand All @@ -7,7 +170,7 @@ bin/clarity
config/config.yml.sample
lib/clarity.rb
lib/clarity/cli.rb
lib/clarity/commands/command_builder.rb
lib/clarity/commands/grep_command_builder.rb
lib/clarity/commands/tail_command_builder.rb
lib/clarity/grep_renderer.rb
lib/clarity/process_tree.rb
Expand All @@ -22,12 +185,9 @@ public/stylesheets/app.css
script/console
script/destroy
script/generate
test/commands/command_builder_test.rb
test/commands/grep_command_builder_test.rb
test/commands/tail_command_builder_test.rb
test/files/logfile.log
test/parsers/hostname_parser_test.rb
test/parsers/shop_parser_test.rb
test/parsers/time_parser_test.rb
test/test_helper.rb
test/test_string_scanner.rb
views/_header.html.erb
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ $hoe = Hoe.spec 'clarity' do
self.developer 'Tobias Lütke', 'tobi@shopify.com'
self.developer 'John Tajima', 'john@shopify.com'
self.post_install_message = 'PostInstall.txt'
self.extra_deps = [['eventmachine','>= 0.12.10'], ['eventmachine_httpserver','>= 0.2.0']]
self.test_globs = ['test/**/*_test.rb']
self.extra_deps = [['eventmachine','>= 0.12.10'], ['eventmachine_httpserver','>= 0.2.0'], ["json", ">= 1.0.0"]]
self.test_globs = ['test/**/*_test.rb']
end

require 'newgem/tasks'
Expand Down
6 changes: 2 additions & 4 deletions lib/clarity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

require 'eventmachine'
require 'evma_httpserver'
require 'json'
require 'yaml'
require 'base64'
require 'clarity/server'
require 'clarity/commands/command_builder'
require 'clarity/commands/grep_command_builder'
require 'clarity/commands/tail_command_builder'
require 'clarity/parsers/time_parser'
require 'clarity/parsers/hostname_parser'
require 'clarity/parsers/shop_parser'
require 'clarity/renderers/log_renderer'

module Clarity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CommandBuilder
class GrepCommandBuilder

# parameter names
TermParameters = ['term1', 'term2', 'term3']
Expand Down
2 changes: 1 addition & 1 deletion lib/clarity/commands/tail_command_builder.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# Handles tailing of log files
#
class TailCommandBuilder < CommandBuilder
class TailCommandBuilder < GrepCommandBuilder

def valid?
raise InvalidParameterError, "Log file parameter not supplied or invalid log file" unless filename && !filename.empty? && File.extname(filename) == ".log"
Expand Down
2 changes: 1 addition & 1 deletion lib/clarity/renderers/log_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def finalize
private

def html_link(url)
uri = URI.parse(url)
uri = URI.parse(url) rescue url
"<a href='#{uri}'>#{url}</a>"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/clarity/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def process_http_request
else
# get command
command = case params['tool']
when 'grep' then CommandBuilder.new(params).command
when 'grep' then GrepCommandBuilder.new(params).command
when 'tail' then TailCommandBuilder.new(params).command
else raise InvalidParameterError, "Invalid Tool parameter"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class CommandBuilderTest < Test::Unit::TestCase
class GrepCommandBuilderTest < Test::Unit::TestCase

def setup
@params = {
Expand All @@ -10,88 +10,88 @@ def setup
"term2" => nil,
"term3" => nil
}
@command = CommandBuilder.new(@params)
@command = GrepCommandBuilder.new(@params)
end

def test_create_new_builder
assert @command.is_a?(CommandBuilder)
assert @command.is_a?(GrepCommandBuilder)
assert_equal "testfile.log", @command.filename
assert_equal 1, @command.terms.size
end

def test_raises_error_if_no_file
assert_raises CommandBuilder::InvalidParameterError do
command = CommandBuilder.new(@params.merge("file" => nil))
assert_raises GrepCommandBuilder::InvalidParameterError do
command = GrepCommandBuilder.new(@params.merge("file" => nil))
end
end

def test_exec_functions_for_log
command = CommandBuilder.new(@params)
command = GrepCommandBuilder.new(@params)
assert_equal 1, command.exec_functions.size
assert_match(/^grep/, command.exec_functions.first)
end

def test_exec_functions_with_multiple_terms_for_log
command = CommandBuilder.new(@params.merge("term2" => "bar", "term3" => "baz"))
command = GrepCommandBuilder.new(@params.merge("term2" => "bar", "term3" => "baz"))
assert_equal 3, command.exec_functions.size
assert_match(/^grep/, command.exec_functions[0])
assert_match(/^grep/, command.exec_functions[1])
assert_match(/^grep/, command.exec_functions[2])
end

def test_exec_function_with_no_terms_for_log
command = CommandBuilder.new(@params.merge("term1" => nil))
command = GrepCommandBuilder.new(@params.merge("term1" => nil))
assert_equal 1, command.exec_functions.size
assert_match(/^cat/, command.exec_functions[0])
end

def test_exec_funcations_for_gzip
command = CommandBuilder.new(@params.merge("file" => "testfile.gz"))
command = GrepCommandBuilder.new(@params.merge("file" => "testfile.gz"))
assert_equal 1, command.exec_functions.size
assert_match(/^zgrep/, command.exec_functions.first)
end

def test_exec_functions_with_multiple_terms_for_gzip
command = CommandBuilder.new(@params.merge("file" => "testfile.gz", "term2" => "bar", "term3" => "baz"))
command = GrepCommandBuilder.new(@params.merge("file" => "testfile.gz", "term2" => "bar", "term3" => "baz"))
assert_equal 3, command.exec_functions.size
assert_match(/^zgrep/, command.exec_functions[0])
assert_match(/^grep/, command.exec_functions[1])
assert_match(/^grep/, command.exec_functions[2])
end

def test_exec_function_with_no_terms_for_gzip
command = CommandBuilder.new(@params.merge("file" => "testfile.gz", "term1" => nil))
command = GrepCommandBuilder.new(@params.merge("file" => "testfile.gz", "term1" => nil))
assert_equal 1, command.exec_functions.size
assert_match "gzcat", command.exec_functions[0]
end

def test_command_for_log
command = CommandBuilder.new(@params)
command = GrepCommandBuilder.new(@params)
assert_equal "sh -c 'grep -e foo testfile.log'", command.command
end

def test_command_with_no_terms_for_log
command = CommandBuilder.new(@params.merge("term1" => nil))
command = GrepCommandBuilder.new(@params.merge("term1" => nil))
assert_equal "sh -c 'cat testfile.log'", command.command
end

def test_command_with_multiple_terms_for_log
command = CommandBuilder.new(@params.merge("term2" => "bar", "term3" => "baz"))
command = GrepCommandBuilder.new(@params.merge("term2" => "bar", "term3" => "baz"))
assert_equal "sh -c 'grep -e foo testfile.log | grep -e bar | grep -e baz'", command.command
end

def test_command_for_gzip
command = CommandBuilder.new(@params.merge("file" => "testfile.gz"))
command = GrepCommandBuilder.new(@params.merge("file" => "testfile.gz"))
assert_equal "sh -c 'zgrep -e foo testfile.gz'", command.command
end

def test_command_with_no_terms_for_gzip
command = CommandBuilder.new(@params.merge("file" => "testfile.gz","term1" => nil))
command = GrepCommandBuilder.new(@params.merge("file" => "testfile.gz","term1" => nil))
assert_equal "sh -c 'gzcat testfile.gz'", command.command
end

def test_command_with_multiple_terms_for_gzip
command = CommandBuilder.new(@params.merge("file" => "testfile.gz","term2" => "bar", "term3" => "baz"))
command = GrepCommandBuilder.new(@params.merge("file" => "testfile.gz","term2" => "bar", "term3" => "baz"))
assert_equal "sh -c 'zgrep -e foo testfile.gz | grep -e bar | grep -e baz'", command.command
end

Expand Down
2 changes: 1 addition & 1 deletion test/commands/tail_command_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_create_new_builder
end

def test_raises_error_if_invalid_file
assert_raises CommandBuilder::InvalidParameterError do
assert_raises GrepCommandBuilder::InvalidParameterError do
command = TailCommandBuilder.new(@params.merge("file" => "testfile.gz"))
end
end
Expand Down
Loading

0 comments on commit 3e719ac

Please sign in to comment.