aio_elin 0.0.1 → 1.0.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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/config.rb +32 -32
  3. data/lib/aio/base/toolkit/excel_wps.rb +1 -0
  4. data/lib/aio/base/toolkit/hash.rb +95 -0
  5. data/lib/aio/base/toolkit/myers.rb +161 -0
  6. data/lib/aio/base/toolkit.rb +2 -0
  7. data/lib/aio/core/device/cmd_switch.rb +1 -1
  8. data/lib/aio/core/device/h3c.rb +2 -0
  9. data/lib/aio/core/device/maipu.rb +8 -0
  10. data/lib/aio/core/device/methods.rb +230 -228
  11. data/lib/aio/core/device/parent_device.rb +270 -267
  12. data/lib/aio/core/device_manager.rb +255 -202
  13. data/lib/aio/core/module/cmd.rb +155 -150
  14. data/lib/aio/core/module/compare.rb +39 -0
  15. data/lib/aio/core/module/output_style.rb +2 -0
  16. data/lib/aio/core/module.rb +1 -0
  17. data/lib/aio/core/module_loader.rb +11 -0
  18. data/lib/aio/core/parse/file.rb +12 -14
  19. data/lib/aio/core/parse/parser.rb +99 -87
  20. data/lib/aio/core/parse/parser_machine/has_device_state.rb +42 -42
  21. data/lib/aio/core/parse/parser_machine.rb +44 -44
  22. data/lib/aio/core/text/block.rb +88 -0
  23. data/lib/aio/core/text/compare.rb +109 -0
  24. data/lib/aio/core/text/context.rb +206 -206
  25. data/lib/aio/core/text/line_string.rb +17 -62
  26. data/lib/aio/core/text/match_string_info.rb +73 -0
  27. data/lib/aio/core/text/warning.rb +175 -175
  28. data/lib/aio/core/text.rb +3 -0
  29. data/lib/aio/core/warning/warning_summarize.rb +246 -229
  30. data/lib/aio/core.rb +3 -0
  31. data/lib/aio/ui/logger.rb +38 -0
  32. data/lib/aio/ui/verbose.rb +6 -2
  33. data/lib/aio/ui.rb +135 -134
  34. data/lib/modules/cmd/cisco/show_version.rb +84 -84
  35. data/lib/modules/cmd/h3c/display_cpu.rb +41 -41
  36. data/lib/modules/cmd/h3c/display_version.rb +43 -43
  37. data/lib/modules/cmd/maipu/show_clock.rb +32 -0
  38. data/lib/modules/cmd/maipu/show_cpu.rb +36 -0
  39. data/lib/modules/cmd/maipu/show_ip_interface_brief.rb +44 -0
  40. data/lib/modules/cmd/maipu/show_memory.rb +22 -22
  41. data/lib/modules/cmd/maipu/show_version.rb +40 -40
  42. data/lib/modules/input/style/compare_xml.rb +73 -73
  43. data/lib/modules/output/style/cmds.rb +3 -3
  44. data/lib/modules/output/style/compare_diff.rb +23 -0
  45. data/lib/modules/output/style/excel_table_office.rb +1 -0
  46. data/lib/modules/output/style/excel_table_wps.rb +1 -0
  47. data/lib/modules/output/style/summary_report.rb +2 -1
  48. data/lib/modules/special/style/compare.rb +153 -103
  49. data/lib/modules/special/style/compare_old.rb +121 -0
  50. data/lib/modules/special/style/compare_with_device_manager.rb +227 -0
  51. metadata +16 -3
@@ -1,44 +1,44 @@
1
1
  module Aio::Parse
2
- class HasDeviceState < ParentState
3
-
4
- def get_device(opts)
5
- self.device_manager.add_device(opts)
6
- end
7
-
8
- def get_full(opts)
9
-
10
- if ! check_full(opts)
11
- no_full
12
- elsif
13
- @machine.to_full_state
14
- end
15
-
16
- end
17
-
18
- def no_full
19
- end
20
-
21
- # 验证是否有cmd和context了
22
- def check_full(opts={})
23
- device_name = opts[:device_name]
24
- device_klass = self.device_manager.devices[device_name]
25
-
26
- org_cmd = opts[:cmd]
27
- org_context = opts[:context]
28
- org_cmd_reg = Aio::Base::Toolkit::Regexp.to_reg(org_cmd)
29
- device_klass.cmds_context.each_pair do |cmd, context|
30
-
31
- # 只有当有cmd, 并且context不为空的时候才算有
32
- # :NOTE 可以在这里的context类加入.check_avlid? 查看是否有效
33
- if org_cmd_reg.match(cmd)
34
- if ! context.empty?
35
- return true
36
- end
37
- end
38
-
39
- end
40
- return false
41
- end
42
-
43
- end
2
+ class HasDeviceState < ParentState
3
+
4
+ def get_device(opts)
5
+ self.device_manager.add_device(opts)
6
+ end
7
+
8
+ def get_full(opts)
9
+
10
+ if ! check_full(opts)
11
+ no_full
12
+ elsif
13
+ @machine.to_full_state
14
+ end
15
+
16
+ end
17
+
18
+ def no_full
19
+ end
20
+
21
+ # 验证是否有cmd和context了
22
+ def check_full(opts={})
23
+ device_name = opts[:device_name]
24
+ device_klass = self.device_manager.devices[device_name]
25
+
26
+ org_cmd = opts[:cmd]
27
+ org_context = opts[:context]
28
+ org_cmd_reg = Aio::Base::Toolkit::Regexp.to_reg(org_cmd)
29
+ device_klass.cmds_context.each_pair do |cmd, context|
30
+
31
+ # 只有当有cmd, 并且context不为空的时候才算有
32
+ # FIXME 可以在这里的context类加入.check_avlid? 查看是否有效
33
+ if org_cmd_reg.match(cmd)
34
+ if ! context.empty?
35
+ return true
36
+ end
37
+ end
38
+
39
+ end
40
+ return false
41
+ end
42
+
43
+ end
44
44
  end
@@ -1,47 +1,47 @@
1
1
  module Aio::Parse
2
-
3
- require "aio/core/parse/parser_machine/parent_state"
4
- require "aio/core/parse/parser_machine/no_device_state"
5
- require "aio/core/parse/parser_machine/has_device_state"
6
- require "aio/core/parse/parser_machine/full_state"
7
-
8
- class ParserMachine
9
- # 保存状态机的状态
10
- attr_reader :state
11
-
12
- # device_manager
13
- attr_reader :device_manager
14
-
15
- def initialize(device_manager)
16
- @device_manager = device_manager
17
-
18
- @no_device_state = Aio::Parse::NoDeviceState.new(self)
19
- @has_device_state = Aio::Parse::HasDeviceState.new(self)
20
- @full_state = Aio::Parse::FullState.new(self)
21
-
22
- @state = @no_device_state
23
- end
24
-
25
- def get_device(opts)
26
- @state.get_device(opts)
27
- end
28
-
29
- def get_full(opts)
30
- @state.get_full(opts)
31
- end
32
-
33
- # 状态的切换
34
- def to_no_device_state
35
- @state = @no_device_state
36
- end
37
-
38
- def to_has_device_state
39
- @state = @has_device_state
40
- end
41
-
42
- def to_full_state
43
- @state = @full_state
44
- end
45
- end
2
+
3
+ require "aio/core/parse/parser_machine/parent_state"
4
+ require "aio/core/parse/parser_machine/no_device_state"
5
+ require "aio/core/parse/parser_machine/has_device_state"
6
+ require "aio/core/parse/parser_machine/full_state"
7
+
8
+ class ParserMachine
9
+ # 保存状态机的状态
10
+ attr_reader :state
11
+
12
+ # device_manager
13
+ attr_reader :device_manager
14
+
15
+ def initialize(device_manager)
16
+ @device_manager = device_manager
17
+
18
+ @no_device_state = Aio::Parse::NoDeviceState.new(self)
19
+ @has_device_state = Aio::Parse::HasDeviceState.new(self)
20
+ @full_state = Aio::Parse::FullState.new(self)
21
+
22
+ @state = @no_device_state
23
+ end
24
+
25
+ def get_device(opts)
26
+ @state.get_device(opts)
27
+ end
28
+
29
+ def get_full(opts)
30
+ @state.get_full(opts)
31
+ end
32
+
33
+ # 状态的切换
34
+ def to_no_device_state
35
+ @state = @no_device_state
36
+ end
37
+
38
+ def to_has_device_state
39
+ @state = @has_device_state
40
+ end
41
+
42
+ def to_full_state
43
+ @state = @full_state
44
+ end
45
+ end
46
46
  end
47
47
 
@@ -0,0 +1,88 @@
1
+ module Aio::Text
2
+ class Block
3
+ attr_accessor :content, :line
4
+
5
+ def initialize(block)
6
+ @block = block
7
+ end
8
+
9
+ def inspect
10
+ @block.inspect
11
+ end
12
+
13
+ def nil?
14
+ @block.nil?
15
+ end
16
+
17
+ def [](sym)
18
+ @block[sym]
19
+ end
20
+
21
+ # 有两种更新的方式,不加str 那么就是从block中的提取
22
+ # 如果有str, 则直接使用str
23
+ def update(info, sym, str=nil)
24
+ sym = sym.to_sym
25
+ if info.nil?
26
+ print_error "请检查update中的第一个参数是否定义"
27
+ pp caller
28
+ end
29
+
30
+ if str.nil?
31
+ info[sym] = match_string(self[sym].strip)
32
+ else
33
+ info[sym] = match_string(str.to_s.strip)
34
+ end
35
+ end
36
+
37
+ def update_arr(info, sym)
38
+ sym = sym.to_sym
39
+ info[sym] ||= []
40
+ info[sym] << match_string(self[sym].strip)
41
+ end
42
+
43
+ def update_hash(info, sym, key, val)
44
+ sym = sym.to_sym
45
+ info[sym] ||= {}
46
+ info[sym][key] = match_string(val.strip)
47
+ end
48
+
49
+ # 参数info 放置useful
50
+ # 参数sym 为Symbol类型的标示
51
+ # 参数level 为 :serious 或 :ordinary
52
+ # 参数mod 一般为self
53
+ # 参数opt[:string] 当block中没有sym项时使用
54
+ def warning(info, sym, level, mod, opt={})
55
+ sym = sym.to_sym
56
+ self.update(info, sym, opt[:string])
57
+ # Aio::Text::Warning 类中的warning方法
58
+ mod.warning_klass.warning(info, sym, level, mod, opt[:force])
59
+ end
60
+
61
+ def warning_serious(info, sym, mod, opt={})
62
+ sym = sym.to_sym
63
+ self.update(info, sym, opt[:string])
64
+ mod.warning_klass.warning_serious(info, sym, mod, opt[:force])
65
+ end
66
+
67
+ def warning_ordinary(info, sym, mod, opt={})
68
+ sym = sym.to_sym
69
+ self.update(info, sym, opt[:string])
70
+ mod.warning_klass.warning_ordinary(info, sym, mod, opt[:force])
71
+ end
72
+
73
+ # 加入content和行数信息
74
+ def match_string(str)
75
+ MatchStringInfo.new(str, content, line)
76
+ end
77
+
78
+ def method_missing(m, *args)
79
+ if @block.respond_to? m
80
+ @block.send(m, args)
81
+
82
+ else
83
+ super
84
+ end
85
+ end
86
+
87
+ end
88
+ end
@@ -0,0 +1,109 @@
1
+ # 对Compare信息进行处理
2
+ module Aio::Text
3
+ class Compare
4
+
5
+ attr_accessor :cmd
6
+
7
+ # 比较和被比较的差异值
8
+ def initialize
9
+ @cmd = {}
10
+ end
11
+
12
+ # 以每个cmd分类比较信息
13
+ def <<(info)
14
+ cmd_name = info[:e].shift
15
+
16
+ cmd[cmd_name] ||= CompareDiff.new
17
+ cmd[cmd_name] << info
18
+ end
19
+
20
+ def clear
21
+ @cmd = {}
22
+ end
23
+
24
+ def size
25
+ res = 0
26
+ cmd.values do |cd|
27
+ res += cd.size
28
+ end
29
+ res
30
+ end
31
+
32
+ def empty?
33
+ cmd.empty?
34
+ end
35
+
36
+ def each_cmd_with_diff
37
+ @cmd.each_pair do |c, e|
38
+ yield c, e
39
+ end
40
+ end
41
+ end
42
+
43
+ class CompareDiff
44
+
45
+ # cm1 = [ MatchStringInfo_A, MatchStringInfo_A, .. ]
46
+ attr_accessor :cm1, :cm2
47
+
48
+ def initialize
49
+ @cm1 = []
50
+ @cm2 = []
51
+ end
52
+
53
+ # info #=> { :cm => :cm1, :e => [cmd, key, match_string_info] }
54
+ def <<(info)
55
+ case info[:cm]
56
+ when :cm1
57
+ @cm1 << info[:e].pop
58
+ when :cm2
59
+ @cm2 << info[:e].pop
60
+ end
61
+ end
62
+
63
+ # 两个文本集合
64
+ def content_muster
65
+ { cm1: content, cm2: compare_content }
66
+ end
67
+
68
+ # 文本
69
+ def content
70
+ return [""] if cm1.first.nil?
71
+ cm1.first.content
72
+ end
73
+
74
+ # 比较的文本
75
+ def content_compare
76
+ return [""] if cm2.first.nil?
77
+ cm2.first.content
78
+ end
79
+
80
+ def size
81
+ cm1.size
82
+ end
83
+
84
+ def lines
85
+ res = []
86
+ cm1.each do |e|
87
+ res << e.line
88
+ end
89
+
90
+ res.uniq
91
+ end
92
+
93
+ def lines_compare
94
+ res = []
95
+ cm2.each do |e|
96
+ res << e.line
97
+ end
98
+
99
+ res.uniq
100
+ end
101
+
102
+ # 所有不同行的集合
103
+ def lines_muster
104
+ { cm1: lines, cm2: lines_compare }
105
+ end
106
+
107
+ end
108
+ end
109
+