fix_protocol_tools 1.1.2 → 1.2.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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTE3YTM3NjAzM2FmYWJhNDU4ZDY0ZWQ4N2QzMThlMTM2NDg5MWMzYg==
4
+ MDg5Y2MxMzczNWRjMWRlNzhjOWNkMTYxZDE5NDUxNTNjYjJmYjBhZA==
5
5
  data.tar.gz: !binary |-
6
- ZTZjNGQzN2EwOTgyNmU3NTMxN2MwOWQzMGE5NzQyNDQwZTlmN2U3YQ==
6
+ M2I4NjdjYzY0YjY1MTFmOTQ3MzRmNDNhZGMzMjI5OTQ5NGY1MTJiOA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZWU4OTUyOThiYTNlZGYwNzZjNGI2NjYwMDYwNWY3ZDJjNjdiODVhODM3OGQx
10
- ZjlhMzZmMDgzNjNmZmEwMjgwNmQ4MjQ5M2U0ZjdkOTQwMDNhMjYyZmUyNmUw
11
- YzhmMzRjM2EzMjhmODQxYjYwZTVjMDBlZmU5MDRmZDJkM2ZlNjQ=
9
+ ZWRmZGFlMWI3Mjg2OTIyOGFjNzk4ZmFiZjIzMmZlZGVjOGVhYzliMjlkNWIz
10
+ YjRkYWE0NDllN2VkYjQ4Mzc3M2YxN2Q3YWM5ZjM0ZmVkNTg4OTJjYWRmZDRi
11
+ ZWJlZTc4YzY5MDEyZjczZTYxZTc1ZTZhZmY4NmJmNWVlNGFlZjQ=
12
12
  data.tar.gz: !binary |-
13
- OTYzZThkNjE0ODIzNWEzZmZiNjljZWU3ZjI5NjNjZDMzYzRhYjgzMTIyOTk5
14
- NDIyZjZkOGJiNTEyNmE5NTU3YzYxYTU5MGZjZTY0ZTc1ZjU3YjVmNWY2NDIz
15
- NzBmNTY1ODk0YjY2N2YwYzMzNjgxODdhMjY2MzM0MDU0MjNhYmM=
13
+ OWEwNjI1ZTRlYzVhYjUyNDNiNWVjMzg2MjQ2ZjMyNWU1NjJiN2U0NWY4YTZk
14
+ MDcyNzRhYWUyYmRiM2FiMzdiMzNiZjQzYjU5NDJmYWU5OTE0MTAxZjAxZWE3
15
+ Yjk4Y2E4ZGZkNzA5ZDlhOWY0OWY4NWRiYTc3MzMxYmRlZWU3YjY=
@@ -6,4 +6,4 @@ $LOAD_PATH.unshift(path) unless $LOAD_PATH.include? path
6
6
  require 'optparse'
7
7
  require 'fix_protocol_tools'
8
8
 
9
- FixProtocolTools::Runner.new.grep!
9
+ FixProtocolTools::Runner.new.run!
@@ -10,8 +10,10 @@ module FixProtocolTools
10
10
  def initialize(options)
11
11
  @spec = nil
12
12
  @is_even_line = true
13
- @output = init_output_chanel options
13
+ @output = STDOUT
14
14
  @grep = options[:grep]
15
+ @highlights = options[:highlights] || []
16
+ @heartbeats = options[:heartbeats]
15
17
 
16
18
  if options[:dictionary]
17
19
  @spec = Specification::Dictionary.new(Specification::Reader.read_file(options[:dictionary]))
@@ -39,8 +41,6 @@ module FixProtocolTools
39
41
  end
40
42
 
41
43
  process_line(buffer) if buffer
42
-
43
- @output.close
44
44
  end
45
45
 
46
46
  private
@@ -56,7 +56,7 @@ module FixProtocolTools
56
56
 
57
57
  @spec ||= resolve_specification(fields)
58
58
  rows = []
59
- is_found = @grep.nil?
59
+ show_message = @grep.nil?
60
60
  message_name = 'Undefined'
61
61
  sender = 'Undefined'
62
62
  target = 'Undefined'
@@ -74,13 +74,15 @@ module FixProtocolTools
74
74
 
75
75
  if @grep && (value_name.include?(@grep) || value_id.include?(@grep))
76
76
  value_name = red(value_name)
77
- is_found = true
77
+ show_message = true
78
78
  end
79
79
 
80
+ show_message = false if !@heartbeats && @spec.heartbeat?(field_id, value_id)
81
+
80
82
  rows << formatted_row(field_id, value_id, field_name, value_name, field_name_padding)
81
83
  end
82
84
 
83
- if is_found
85
+ if show_message
84
86
  @is_even_line = false
85
87
  @output.puts ''
86
88
  @output.puts("[#{red(message_name + " #{sender} >>> #{target}")}]" +
@@ -90,9 +92,15 @@ module FixProtocolTools
90
92
  end
91
93
 
92
94
  def formatted_row(field_id, value_id, field_name, value_name, field_name_padding)
93
- field_name + ' = '.rjust(field_name_padding) + value_name +
95
+ row = field_name + ' = '.rjust(field_name_padding) + value_name +
94
96
  ' '.rjust(35 - value_name.length) +
95
97
  field_id + '=' + value_id
98
+
99
+ if @highlights and @highlights.include?(field_name)
100
+ yellow(row)
101
+ else
102
+ row
103
+ end
96
104
  end
97
105
 
98
106
  def resolve_specification(fields)
@@ -112,16 +120,6 @@ module FixProtocolTools
112
120
  nil
113
121
  end
114
122
  end
115
-
116
- def init_output_chanel(options)
117
- if options[:less]
118
- cmd = 'less'
119
- cmd += ' -r' if options[:color]
120
- IO.popen(cmd, 'w')
121
- else
122
- STDOUT
123
- end
124
- end
125
123
  end
126
124
  end
127
125
 
@@ -6,69 +6,61 @@ module FixProtocolTools
6
6
  class Runner
7
7
  DEFAULTS = {
8
8
  :color => Term::ANSIColor::coloring = STDOUT.isatty,
9
- :dictionary => ENV['FPT_DICT']
9
+ :dictionary => ENV['FPT_DICT'],
10
+ :highlights => ENV['FPT_HIGHLIGHTS'],
11
+ :heartbeats => false
10
12
  }
11
13
 
12
14
  def initialize
13
- @options = DEFAULTS
15
+ @options = DEFAULTS
14
16
  end
15
17
 
16
- def less!
17
- @options.merge!(:less => false)
18
+ def run!
18
19
  opt_parse = OptionParser.new do |opts|
19
- opts.banner = "Usage: fixless [options] [fixlogfile]"
20
+ opts.banner = "Usage: #{File.basename($0)} [options] [file]"
20
21
 
21
- opts.on('-l', '--[no-]less', 'Use less command for output') do |color|
22
- @options[:less] = color
22
+ opts.on('--dictionary PATH_TO_DICTIONARY', 'You can set up FPT_DICT env variable instead') do |dictionary|
23
+ @options[:dictionary] = dictionary
23
24
  end
24
25
 
25
- dictionary(opts)
26
- color(opts)
27
- help(opts)
28
- end
26
+ opts.on('--highlight field1,field2', Array, 'Highlight number of fields, you can set FPT_HIGHLIGHTS env variable instead') do |highlights|
27
+ @options[:highlights] = highlights
28
+ end
29
29
 
30
- opt_parse.parse!
30
+ opts.on('-c', '--[no-]color', 'Generate color output') do |color|
31
+ Term::ANSIColor::coloring = color
32
+ @options[:color] = color
33
+ end
31
34
 
32
- MessagesProcessor.new(@options).process
33
- end
35
+ opts.on('--grep', 'Grep by field id or name') do |pattern|
36
+ @options[:grep] = pattern
37
+ end
34
38
 
35
- def grep!
36
- opt_parse = OptionParser.new do |opts|
37
- opts.banner = "Usage: fixgrep -v value [options] [fixlogfile]"
39
+ opts.on('--[no-]heartbeats', 'Show full report on heartbeat messages') do |heartbeats|
40
+ @options[:heartbeats] = heartbeats
41
+ end
38
42
 
39
- opts.on('-v', '--v value') do |pattern|
40
- @options[:grep] = pattern
43
+ opts.on_tail('-h', '--help', 'Display help message') do
44
+ puts opts
45
+ exit
41
46
  end
42
47
 
43
- dictionary(opts)
44
- color(opts)
45
- help(opts)
48
+ opts.on_tail('-v', '--version', 'Display version message') do
49
+ puts FixProtocolTools::VERSION
50
+ exit
51
+ end
46
52
  end
47
53
 
48
54
  opt_parse.parse!
49
- MessagesProcessor.new(@options).process
50
- end
51
55
 
52
- private
53
-
54
- def help(opts)
55
- opts.on('--help', '-h', 'Display help message') do
56
- puts opts
57
- exit
58
- end
59
- end
60
-
61
- def color(opts)
62
- opts.on('-c', '--[no-]color', 'Generate color output') do |color|
63
- Term::ANSIColor::coloring = color
64
- @options[:color] = color
56
+ ARGV.each do |f|
57
+ unless File.exists?(f)
58
+ puts "File #{f} does not exists"
59
+ exit false
60
+ end
65
61
  end
66
- end
67
62
 
68
- def dictionary(opts)
69
- opts.on('-d', '--dictionary PATH_TO_DICTIONARY', 'You can set up FPT_DICT env variable instead') do |dictionary|
70
- @options[:dictionary] = dictionary
71
- end
63
+ MessagesProcessor.new(@options).process
72
64
  end
73
65
  end
74
66
  end
@@ -31,6 +31,10 @@ module FixProtocolTools::Specification
31
31
  tag == '56'
32
32
  end
33
33
 
34
+ def heartbeat?(tag, value)
35
+ message_type?(tag) && value == '0'
36
+ end
37
+
34
38
  def enum_value(field, enum_id)
35
39
  enum = @enums[field]
36
40
 
@@ -1,3 +1,3 @@
1
1
  module FixProtocolTools
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fix_protocol_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luxor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-09 00:00:00.000000000 Z
11
+ date: 2013-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: term-ansicolor
@@ -56,13 +56,11 @@ description: log viewer for fix protocol logs
56
56
  email:
57
57
  - atuzov@gmail.com
58
58
  executables:
59
- - fixgrep
60
- - fixless
59
+ - fixlogviewer
61
60
  extensions: []
62
61
  extra_rdoc_files: []
63
62
  files:
64
- - bin/fixgrep
65
- - bin/fixless
63
+ - bin/fixlogviewer
66
64
  - lib/fix_protocol_tools.rb
67
65
  - lib/fix_protocol_tools/messages_processor.rb
68
66
  - lib/fix_protocol_tools/runner.rb
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- path = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
- $LOAD_PATH.unshift(path) unless $LOAD_PATH.include? path
5
-
6
- require 'optparse'
7
- require 'fix_protocol_tools'
8
-
9
- FixProtocolTools::Runner.new.less!