rubylogparser 0.1.1 → 0.1.3

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.
data/EXAMPLES.txt CHANGED
@@ -25,13 +25,11 @@ Time) are also printed.
25
25
  lp = RubyLogParser.new
26
26
  lp.open_query('FS', 'Select Top 10 name, size INTO STDOUT from c:/win*.* ORDER BY size DESC', 'CSV', nil)
27
27
 
28
- while hash = lp.data_hash(lp.process_array_line(lp.readline)) do
28
+ while hash = lp.read_hash do
29
29
  p "#{hash['Name'].ljust(60)} #{hash['Size'].rjust(12)}\n"
30
30
  end
31
-
31
+
32
32
  lp.parse_errors_and_stats(lp.read)
33
-
34
- p "Parse errors:\n" + lp.parse_errors.to_s + "\n\n"
35
33
  p "Processed: " + (lp.elements_processed.nil? ? "0" : "#{lp.elements_processed}") + "\n"
36
34
  p "Output: " + (lp.elements_output.nil? ? "0" : "#{lp.elements_output}") + "\n"
37
35
  p "Time: " + (lp.execution_time.nil? ? "0" : "#{lp.execution_time}") + " seconds\n"
@@ -65,13 +63,11 @@ In this example, each line of data is read into an array for further processing
65
63
  "
66
64
 
67
65
  lp.open_query('EVT', sql, 'CSV', nil)
68
- while array = lp.process_array_line(lp.readline) do
66
+ while array = lp.read_array_line do
69
67
  p "#{array[0].ljust(35)} #{array[1].rjust(8)}\n"
70
68
  end
71
69
 
72
70
  lp.parse_errors_and_stats(lp.read)
73
-
74
- p "Parse errors:\n" + lp.parse_errors.to_s + "\n\n"
75
71
  p "Processed: " + (lp.elements_processed.nil? ? "0" : "#{lp.elements_processed}") + "\n"
76
72
  p "Output: " + (lp.elements_output.nil? ? "0" : "#{lp.elements_output}") + "\n"
77
73
  p "Time: " + (lp.execution_time.nil? ? "0" : "#{lp.execution_time}") + " seconds\n"
@@ -105,10 +101,11 @@ printing the query statistics.
105
101
 
106
102
  lp.open_query('REG', sql, 'CSV', {'e' => 100})
107
103
 
108
- while array = lp.process_array_line(lp.readline) do
104
+ while array = lp.read_array_line do
109
105
  p "#{array[0].ljust(80)} #{array[1].rjust(25)}\n"
110
106
  end
111
-
107
+
108
+ lp.parse_errors_and_stats(lp.read)
112
109
  p "Parse errors:\n" + lp.parse_errors.to_s + "\n\n"
113
110
  p "Statistics:\n"
114
111
  p "Processed: " + (lp.elements_processed.nil? ? "0" : "#{lp.elements_processed}") + "\n"
@@ -140,4 +137,4 @@ open_query method as {'queryInfo' => true, 'iw' => true}.
140
137
 
141
138
  lp.open_query('EVT', sql, nil, {'queryInfo' => true})
142
139
 
143
- puts "#{lp.formatted_queryInfo}"
140
+ puts "#{lp.queryInfo}"
data/GUIDE.txt CHANGED
@@ -84,12 +84,12 @@ Next we read the Log Parser output line by line into an array and format the
84
84
  output to be printed to the screen. See the examples/files.rb example for using
85
85
  a hash to retrieve output.
86
86
 
87
- while array = lp.process_array_line(lp.readline) do
87
+ while array = lp.read_array_line do
88
88
  p "#{array[0].ljust(35)} #{array[1].rjust(8)}\n"
89
89
  end
90
90
 
91
91
  Once all output has been processed, the query statistics and any warnings/errors
92
- are read from the remaining Log Parser output in the pipe and made available.
92
+ are available.
93
93
 
94
94
  lp.parse_errors_and_stats(lp.read)
95
95
  p "Parse errors:\n" + lp.parse_errors.to_s + "\n\n"
data/History.txt CHANGED
@@ -1,8 +1,12 @@
1
- == 0.1.1 / 2008-06-06
1
+ == 0.1.3 / 2008-12-27
2
2
 
3
- * Updated to have 100% code coverage (as reported by rcov)
4
- * Methods refactored to achieve the 100% testing nirvana.
5
- * Some minor changes in the examples
3
+ * Updated paths to find LogParser for 64-bit Windows installs (tested on Windows Server 2008)
4
+ * Added methods read_hash and read_array_line back in that were unintentionally dropped and broke the documentation / examples
5
+ * Updated documentation
6
+
7
+ == 0.1.1 / 2008-05-30
8
+
9
+ * Added better test coverage (100% coverage according to rcov)
6
10
 
7
11
  == 0.1.0 / 2008-01-10
8
12
 
data/README.txt CHANGED
@@ -51,8 +51,8 @@ Testing was done in the following environment:
51
51
 
52
52
  * Microsoft Log Parser 2.2
53
53
 
54
- Other software versions may work but are completely untested. Testing with Rails
55
- and Ruby 1.9 will be done in early 2008.
54
+ Other software versions may work but are completely untested. I have used and tested
55
+ the examples on Windows XP and Windows Server 2008.
56
56
 
57
57
  == INSTALL:
58
58
 
@@ -70,6 +70,8 @@ locations:
70
70
 
71
71
  * c:\Program Files\Log Parser 2.2\LogParser.exe (Default location when downloaded and installed without the IIS Resource kit)
72
72
 
73
+ * c:\Program Files (x86)\Log Parser 2.2\LogParser.exe (Default location for 64-bit Windows Server 2008 install)
74
+
73
75
  * LogParser.exe on the path somewhere
74
76
 
75
77
  If the LogParser.exe executable cannot be found, the "test_valid_executable"
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ require 'rubylogparser'
5
5
 
6
6
  Hoe.new('rubylogparser', RubyLogParser::VERSION) do |p|
7
7
  p.rubyforge_name = 'rubylogparser'
8
+ p.version = "0.1.3"
8
9
  p.author = 'Jim Clark'
9
10
  p.email = 'jimclark@ieee.org'
10
11
  p.summary = "RubyLogParser provides a wrapper around Microsoft's Log Parser executable."
@@ -19,7 +19,7 @@ ORDER BY number_of_events desc
19
19
  lp.open_query('EVT', sql, 'CSV', nil)
20
20
 
21
21
  i=1
22
- while array = lp.process_array_line(lp.readline) do
22
+ while array = lp.read_array_line do
23
23
  p "#{i}.".ljust(4) + " #{array[0].ljust(35)} #{array[1].rjust(8)}\n"
24
24
  i += 1
25
25
  end
@@ -27,6 +27,6 @@ end
27
27
  lp.parse_errors_and_stats(lp.read)
28
28
 
29
29
  p "Parse errors:\n" + lp.parse_errors.to_s + "\n\n"
30
- p "\nProcessed: " + (lp.elements_processed.nil? ? "0" : "#{lp.elements_processed}") + "\n"
30
+ p "Processed: " + (lp.elements_processed.nil? ? "0" : "#{lp.elements_processed}") + "\n"
31
31
  p "Output: " + (lp.elements_output.nil? ? "0" : "#{lp.elements_output}") + "\n"
32
32
  p "Time: " + (lp.execution_time.nil? ? "0" : "#{lp.execution_time}") + " seconds\n"
data/examples/files.rb CHANGED
@@ -6,17 +6,16 @@ require 'rubylogparser.rb'
6
6
  lp = RubyLogParser.new
7
7
 
8
8
  # Note: This query may take several minutes to run
9
- lp.open_query('FS', 'Select Top 10 name, size INTO STDOUT from c:/rubylogparser/*.* ORDER BY size DESC', 'CSV', nil)
9
+ lp.open_query('FS', 'Select Top 10 name, size INTO STDOUT from c:/win*.* ORDER BY size DESC', 'CSV', nil)
10
10
 
11
11
  i=1
12
- while hash = lp.data_hash(lp.process_array_line(lp.readline)) do
13
- p "#{i}. #{hash['Name'].ljust(60)} #{hash['Size'].rjust(12)}\n"
12
+ while hash = lp.read_hash do
13
+ p "#{i}.".ljust(4) + " #{hash['Name'].ljust(60)} #{hash['Size'].rjust(12)}\n"
14
14
  i += 1
15
15
  end
16
16
 
17
17
  lp.parse_errors_and_stats(lp.read)
18
18
 
19
- p "Parse errors:\n" + lp.parse_errors.to_s + "\n\n"
20
19
  p "Processed: " + (lp.elements_processed.nil? ? "0" : "#{lp.elements_processed}") + "\n"
21
20
  p "Output: " + (lp.elements_output.nil? ? "0" : "#{lp.elements_output}") + "\n"
22
21
  p "Time: " + (lp.execution_time.nil? ? "0" : "#{lp.execution_time}") + " seconds\n"
data/examples/registry.rb CHANGED
@@ -19,7 +19,7 @@ lp.open_query('REG', sql, 'CSV', {'e' => 100})
19
19
 
20
20
  i=1
21
21
  while array = lp.process_array_line(lp.readline) do
22
- p "#{i}. #{array[0].ljust(80)} #{array[1].rjust(25)}\n"
22
+ p "#{i}.".ljust(5) + " #{array[0].ljust(80)} #{array[1].rjust(25)}\n"
23
23
  i += 1
24
24
  end
25
25
 
data/lib/rubylogparser.rb CHANGED
@@ -16,7 +16,7 @@
16
16
  require 'csv'
17
17
 
18
18
  class RubyLogParser
19
- VERSION = "0.1.1"
19
+ VERSION = "0.1.3"
20
20
 
21
21
  # Stores the various options that will be used to build the command line that
22
22
  # the process is eventually started with
@@ -71,7 +71,7 @@ class RubyLogParser
71
71
  def valid_executable(lp_executable = nil)
72
72
  @logparser_exe = nil
73
73
  if lp_executable.nil? then
74
- file_locations = ['c:\Program Files\IIS Resources\Log Parser 2.2\LogParser.exe', 'c:\Program Files\Log Parser 2.2\LogParser.exe', 'LogParser.exe']
74
+ file_locations = ['c:\Program Files\IIS Resources\Log Parser 2.2\LogParser.exe', 'c:\Program Files\Log Parser 2.2\LogParser.exe', 'c:\Program Files (x86)\Log Parser 2.2\LogParser.exe', 'LogParser.exe']
75
75
  else
76
76
  file_locations = [ lp_executable ]
77
77
  end
@@ -196,7 +196,7 @@ class RubyLogParser
196
196
  # the data output is complete and anything that will follow are the errors
197
197
  # or query statistics.
198
198
  def process_line(line)
199
- if line == "\r\n" then
199
+ if (line == "\r\n" || line =~ /Task completed with parse errors/i) then
200
200
  self.error_flag = true # remaining output should now be error
201
201
  return nil
202
202
  else
@@ -307,13 +307,18 @@ class RubyLogParser
307
307
  return data_array
308
308
  end
309
309
 
310
+ # Often times, the easiest way to use the LogParser output is to parse a single
311
+ # line into a hash that is keyed by the field names. Once all LogParser output
312
+ # has been read, this will return nil.
313
+ def read_hash
314
+ self.data_hash(self.process_array_line(self.readline))
315
+ end
316
+
317
+ # Similar to read_hash, this method will parse a single return the LogParser
318
+ # output in an array. If no output remains, this will return nil.
319
+ def read_array_line
320
+ self.process_array_line(self.readline)
321
+ end
322
+
310
323
  end
311
- =begin
312
- @logparser = RubyLogParser.new
313
- @logparser.open_query('EVT','SELECT Top 2 SourceName INTO STDOUT From System','CSV',nil)
314
- temp = @logparser.read_array(true)
315
- p temp.length
316
- p "Stat info:"
317
- p @logparser.read_all
318
324
 
319
- =end
@@ -134,4 +134,26 @@ class Test_RubyLogParser < Test::Unit::TestCase
134
134
  assert_equal 2, temp.length
135
135
  end
136
136
 
137
+ def test_read_hash
138
+ @logparser.cmd_options['i'] = 'EVT'
139
+ @logparser.cmd_options['sql'] = 'SELECT Top 1 SourceName INTO STDOUT From System'
140
+ @logparser.cmd_options['o'] = 'CSV'
141
+ @logparser.build_command_string(nil)
142
+ @logparser.field_definitions("SourceName")
143
+ @logparser.create_process
144
+ temp = @logparser.read_hash
145
+ assert_not_equal nil, temp['SourceName']
146
+ end
147
+
148
+ def test_read_array_line
149
+ @logparser.cmd_options['i'] = 'EVT'
150
+ @logparser.cmd_options['sql'] = 'SELECT Top 1 SourceName INTO STDOUT From System'
151
+ @logparser.cmd_options['o'] = 'CSV'
152
+ @logparser.build_command_string(nil)
153
+ @logparser.field_definitions("SourceName")
154
+ @logparser.create_process
155
+ temp = @logparser.read_array_line
156
+ assert_not_equal nil, temp[0]
157
+ end
158
+
137
159
  end
metadata CHANGED
@@ -1,33 +1,39 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: rubylogparser
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2008-06-06 00:00:00 -07:00
8
- summary: RubyLogParser provides a wrapper around Microsoft's Log Parser executable.
9
- require_paths:
10
- - lib
11
- email: jimclark@ieee.org
12
- homepage: http://rubyforge.org/projects/rubylogparser/
13
- rubyforge_project: rubylogparser
14
- description: RubyLogParser enables the output from Microsoft's Log Parser to be processed by Ruby data structures (arrays and hashes).
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.1.3
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Jim Clark
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-27 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.2
24
+ version:
25
+ description: RubyLogParser enables the output from Microsoft's Log Parser to be processed by Ruby data structures (arrays and hashes).
26
+ email: jimclark@ieee.org
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - EXAMPLES.txt
33
+ - GUIDE.txt
34
+ - History.txt
35
+ - Manifest.txt
36
+ - README.txt
31
37
  files:
32
38
  - EXAMPLES.txt
33
39
  - GUIDE.txt
@@ -41,30 +47,32 @@ files:
41
47
  - examples/registry.rb
42
48
  - lib/rubylogparser.rb
43
49
  - test/test_rubylogparser.rb
44
- test_files:
45
- - test/test_rubylogparser.rb
50
+ has_rdoc: true
51
+ homepage: http://rubyforge.org/projects/rubylogparser/
52
+ post_install_message:
46
53
  rdoc_options:
47
54
  - --main
48
55
  - README.txt
49
- extra_rdoc_files:
50
- - EXAMPLES.txt
51
- - GUIDE.txt
52
- - History.txt
53
- - Manifest.txt
54
- - README.txt
55
- executables: []
56
-
57
- extensions: []
58
-
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
59
70
  requirements: []
60
71
 
61
- dependencies:
62
- - !ruby/object:Gem::Dependency
63
- name: hoe
64
- version_requirement:
65
- version_requirements: !ruby/object:Gem::Version::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: 1.5.3
70
- version:
72
+ rubyforge_project: rubylogparser
73
+ rubygems_version: 1.3.1
74
+ signing_key:
75
+ specification_version: 2
76
+ summary: RubyLogParser provides a wrapper around Microsoft's Log Parser executable.
77
+ test_files:
78
+ - test/test_rubylogparser.rb