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.
- checksums.yaml +4 -4
- data/config.rb +32 -32
- data/lib/aio/base/toolkit/excel_wps.rb +1 -0
- data/lib/aio/base/toolkit/hash.rb +95 -0
- data/lib/aio/base/toolkit/myers.rb +161 -0
- data/lib/aio/base/toolkit.rb +2 -0
- data/lib/aio/core/device/cmd_switch.rb +1 -1
- data/lib/aio/core/device/h3c.rb +2 -0
- data/lib/aio/core/device/maipu.rb +8 -0
- data/lib/aio/core/device/methods.rb +230 -228
- data/lib/aio/core/device/parent_device.rb +270 -267
- data/lib/aio/core/device_manager.rb +255 -202
- data/lib/aio/core/module/cmd.rb +155 -150
- data/lib/aio/core/module/compare.rb +39 -0
- data/lib/aio/core/module/output_style.rb +2 -0
- data/lib/aio/core/module.rb +1 -0
- data/lib/aio/core/module_loader.rb +11 -0
- data/lib/aio/core/parse/file.rb +12 -14
- data/lib/aio/core/parse/parser.rb +99 -87
- data/lib/aio/core/parse/parser_machine/has_device_state.rb +42 -42
- data/lib/aio/core/parse/parser_machine.rb +44 -44
- data/lib/aio/core/text/block.rb +88 -0
- data/lib/aio/core/text/compare.rb +109 -0
- data/lib/aio/core/text/context.rb +206 -206
- data/lib/aio/core/text/line_string.rb +17 -62
- data/lib/aio/core/text/match_string_info.rb +73 -0
- data/lib/aio/core/text/warning.rb +175 -175
- data/lib/aio/core/text.rb +3 -0
- data/lib/aio/core/warning/warning_summarize.rb +246 -229
- data/lib/aio/core.rb +3 -0
- data/lib/aio/ui/logger.rb +38 -0
- data/lib/aio/ui/verbose.rb +6 -2
- data/lib/aio/ui.rb +135 -134
- data/lib/modules/cmd/cisco/show_version.rb +84 -84
- data/lib/modules/cmd/h3c/display_cpu.rb +41 -41
- data/lib/modules/cmd/h3c/display_version.rb +43 -43
- data/lib/modules/cmd/maipu/show_clock.rb +32 -0
- data/lib/modules/cmd/maipu/show_cpu.rb +36 -0
- data/lib/modules/cmd/maipu/show_ip_interface_brief.rb +44 -0
- data/lib/modules/cmd/maipu/show_memory.rb +22 -22
- data/lib/modules/cmd/maipu/show_version.rb +40 -40
- data/lib/modules/input/style/compare_xml.rb +73 -73
- data/lib/modules/output/style/cmds.rb +3 -3
- data/lib/modules/output/style/compare_diff.rb +23 -0
- data/lib/modules/output/style/excel_table_office.rb +1 -0
- data/lib/modules/output/style/excel_table_wps.rb +1 -0
- data/lib/modules/output/style/summary_report.rb +2 -1
- data/lib/modules/special/style/compare.rb +153 -103
- data/lib/modules/special/style/compare_old.rb +121 -0
- data/lib/modules/special/style/compare_with_device_manager.rb +227 -0
- metadata +16 -3
@@ -3,108 +3,158 @@
|
|
3
3
|
require "aio/core"
|
4
4
|
|
5
5
|
class Aio::Module::SpecialStyle::Compare < Aio::Module::SpecialStyle
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
6
|
+
include Aio::Module
|
7
|
+
|
8
|
+
include Aio::Ui::Verbose
|
9
|
+
|
10
|
+
# 用于传递已经分析好的现有的device
|
11
|
+
attr_accessor :device_manager
|
12
|
+
|
13
|
+
# 用于传递由XML,Json生成并已经解析的Hash值
|
14
|
+
attr_accessor :input_benchmark
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
super({
|
18
|
+
:author => "Elin",
|
19
|
+
:description => "此模块用于解析两个Hash值的不同点,并发出警告",
|
20
|
+
})
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse
|
24
|
+
# 将device_manager 中的按照{device_name => useful} 形式重新编排
|
25
|
+
# cmds_useful为深度克隆信息,对本体无影响
|
26
|
+
device_warning = {}
|
27
|
+
total = device_manager.devices_number
|
28
|
+
print_good "总共 #{total} 台设备进行比较"
|
29
|
+
|
30
|
+
device_manager.each_devices_with_index do |device_name, device_klass, i|
|
31
|
+
|
32
|
+
device_warning[device_name] = Aio::Base::Toolkit::DeepClone.clone(device_klass.cmds_useful)
|
33
|
+
# 进度条
|
34
|
+
progress_bar(total, i+1, device_name)
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
@compare_hash = Aio::Module::Compare.new
|
39
|
+
clear_line
|
40
|
+
|
41
|
+
clear_other_info(device_warning, input_benchmark)
|
42
|
+
compare(device_warning, input_benchmark)
|
43
|
+
end
|
44
|
+
|
45
|
+
# 只留下要比较的两个数据有共同命令的交集,其他的命令就丢弃
|
46
|
+
# 因为即使是保留了,产生的也是大量的垃圾信息
|
47
|
+
def clear_other_info(device_warning, input_benchmark)
|
48
|
+
device_arr = {}
|
49
|
+
input_arr = {}
|
50
|
+
|
51
|
+
# 获得命令信息
|
52
|
+
device_warning.each_pair { |k, v| device_arr[k] = v.keys }
|
53
|
+
input_benchmark.each_pair { |k, v| input_arr[k] = v.keys }
|
54
|
+
|
55
|
+
# 删除 device_warning 中多余的命令信息
|
56
|
+
device_warning.each_pair do |name, hash|
|
57
|
+
hash.delete_if do |k, v|
|
58
|
+
next true unless input_arr.has_key?(name)
|
59
|
+
input_arr[name].include?(k) ? false : true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# 删除 input_benchmark 中多余的命令信息
|
64
|
+
input_benchmark.each_pair do |name, hash|
|
65
|
+
hash.delete_if do |k, v|
|
66
|
+
next true unless device_arr.has_key?(name)
|
67
|
+
device_arr[name].include?(k) ? false : true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def compare(cm1, cm2, opts={})
|
73
|
+
# NOTE 待加PASS
|
74
|
+
@config_compare = Aio::Config::Warning::Compare
|
75
|
+
|
76
|
+
cm1_arr = []
|
77
|
+
cm2_arr = []
|
78
|
+
Aio::Base::Toolkit::Hash.flat(cm1,
|
79
|
+
Aio::Base::Toolkit::Chain.new,
|
80
|
+
cm1_arr)
|
81
|
+
|
82
|
+
Aio::Base::Toolkit::Hash.flat(cm2,
|
83
|
+
Aio::Base::Toolkit::Chain.new,
|
84
|
+
cm2_arr)
|
85
|
+
|
86
|
+
cp = find_diff(cm1_arr, cm2_arr)
|
87
|
+
|
88
|
+
diff = { cm1: [], cm2: []}
|
89
|
+
# NOTE 还需要加入config_compare
|
90
|
+
# diff = {
|
91
|
+
# cm1: [ [device_name, cmd, str], .. ],
|
92
|
+
# cm2: [ [device_name, cmd, str], .. ]
|
93
|
+
# }
|
94
|
+
cp[:cm1].each do |e|
|
95
|
+
# 加入cmd
|
96
|
+
cmd = e[1]
|
97
|
+
diff[:cm1] << [e.first, cmd, e.last]
|
98
|
+
end
|
99
|
+
|
100
|
+
cp[:cm2].each do |e|
|
101
|
+
diff[e.first] ||= {}
|
102
|
+
# 加入cmd
|
103
|
+
cmd = e[1]
|
104
|
+
diff[:cm2] << [e.first, cmd, e.last]
|
105
|
+
end
|
106
|
+
|
107
|
+
diff
|
108
|
+
end
|
109
|
+
|
110
|
+
def find_diff(cm1, cm2)
|
111
|
+
res = {}
|
112
|
+
res[:cm1] = []
|
113
|
+
res[:cm2] = []
|
114
|
+
|
115
|
+
# res 为相同的内容
|
116
|
+
total = cm1.size
|
117
|
+
cm1.each_with_index do |link_1, i|
|
118
|
+
|
119
|
+
cm2.each do |link_2|
|
120
|
+
|
121
|
+
# 如果长度不一致,就下一个
|
122
|
+
if link_1.size != link_2.size
|
123
|
+
next
|
124
|
+
|
125
|
+
else
|
126
|
+
name_1 = long_name(link_1)
|
127
|
+
name_2 = long_name(link_2)
|
128
|
+
|
129
|
+
if name_1 == name_2
|
130
|
+
res[:cm1] << link_1
|
131
|
+
res[:cm2] << link_2
|
132
|
+
|
133
|
+
# 找到了相同的就跳出小循环
|
134
|
+
break
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# 进度条
|
141
|
+
progress_bar(total, i+1, '')
|
142
|
+
end
|
143
|
+
|
144
|
+
clear_line
|
145
|
+
|
146
|
+
# 获得不同的内容
|
147
|
+
res[:cm1] = cm1 - res[:cm1]
|
148
|
+
res[:cm2] = cm2 - res[:cm2]
|
149
|
+
|
150
|
+
res
|
151
|
+
end
|
152
|
+
|
153
|
+
# 将一个数组转化成一长串字符作为比较方式
|
154
|
+
def long_name(arr)
|
155
|
+
res = ''
|
156
|
+
arr.each { |x| res += x.to_s }
|
157
|
+
res
|
158
|
+
end
|
109
159
|
|
110
160
|
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
#coding=utf-8
|
2
|
+
|
3
|
+
require "aio/core"
|
4
|
+
|
5
|
+
class Aio::Module::SpecialStyle::CompareOld < Aio::Module::SpecialStyle
|
6
|
+
include Aio::Module
|
7
|
+
|
8
|
+
include Aio::Ui::Verbose
|
9
|
+
|
10
|
+
# 用于传递已经分析好的现有的device
|
11
|
+
attr_accessor :device_manager
|
12
|
+
|
13
|
+
# 用于传递由XML,Json生成并已经解析的Hash值
|
14
|
+
attr_accessor :input_benchmark
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
super({
|
18
|
+
:author => "Elin",
|
19
|
+
:description => "此模块用于解析两个Hash值的不同点,并发出警告,此模块废弃",
|
20
|
+
})
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse
|
24
|
+
# 将device_manager 中的按照{device_name => useful} 形式重新编排
|
25
|
+
# cmds_useful为深度克隆信息,对本体无影响
|
26
|
+
device_warning = {}
|
27
|
+
total = device_manager.devices_number
|
28
|
+
print_good "总共 #{total} 台设备进行比较"
|
29
|
+
|
30
|
+
device_manager.each_devices_with_index do |device_name, device_klass, i|
|
31
|
+
|
32
|
+
device_warning[device_name] = Aio::Base::Toolkit::DeepClone.clone(device_klass.cmds_useful)
|
33
|
+
# 进度条
|
34
|
+
progress_bar(total, i+1, device_name)
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
debugger
|
39
|
+
clear_line
|
40
|
+
clear_other_info(device_warning, input_benchmark)
|
41
|
+
delete(device_warning, input_benchmark)
|
42
|
+
end
|
43
|
+
|
44
|
+
# 只留下要比较的两个数据有共同命令的交集,其他的命令就丢弃
|
45
|
+
# 因为即使是保留了,产生的也是大量的垃圾信息
|
46
|
+
def clear_other_info(device_warning, input_benchmark)
|
47
|
+
device_arr = {}
|
48
|
+
input_arr = {}
|
49
|
+
|
50
|
+
# 获得命令信息
|
51
|
+
device_warning.each_pair { |k, v| device_arr[k] = v.keys }
|
52
|
+
input_benchmark.each_pair { |k, v| input_arr[k] = v.keys }
|
53
|
+
|
54
|
+
# 删除 device_warning 中多余的命令信息
|
55
|
+
device_warning.each_pair do |name, hash|
|
56
|
+
hash.delete_if do |k, v|
|
57
|
+
next true unless input_arr.has_key?(name)
|
58
|
+
input_arr[name].include?(k) ? false : true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# 删除 input_benchmark 中多余的命令信息
|
63
|
+
input_benchmark.each_pair do |name, hash|
|
64
|
+
hash.delete_if do |k, v|
|
65
|
+
next true unless device_arr.has_key?(name)
|
66
|
+
device_arr[name].include?(k) ? false : true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def delete(cm1, cm2)
|
72
|
+
compare = Aio::Config::Warning::Compare
|
73
|
+
|
74
|
+
cm1.delete_if do |key, val|
|
75
|
+
|
76
|
+
# 当末端是Hash时,迭代循环
|
77
|
+
if val.class == Hash
|
78
|
+
# 保证无论是Symbol 还是 String 都能互换
|
79
|
+
# 有可能整个val都不一样
|
80
|
+
unless cm2.has_key?(key)
|
81
|
+
cm2_val = cm2[key.to_sym] if key.kind_of? String
|
82
|
+
cm2_val = cm2[key.to_s] if key.kind_of? Symbol
|
83
|
+
next if cm2_val.nil?
|
84
|
+
else
|
85
|
+
cm2_val = cm2[key]
|
86
|
+
end
|
87
|
+
res = delete(cm1[key], cm2_val)
|
88
|
+
# 当有内容时,说明存在差异,则保留
|
89
|
+
res.empty? ? true : false
|
90
|
+
else
|
91
|
+
|
92
|
+
# 当末端不是Hash时,判断是否相等
|
93
|
+
|
94
|
+
unless cm2.has_key?(key)
|
95
|
+
cm2_val = cm2[key.to_sym] if key.kind_of? String
|
96
|
+
cm2_val = cm2[key.to_s] if key.kind_of? Symbol
|
97
|
+
next if cm2_val.nil?
|
98
|
+
else
|
99
|
+
cm2_val = cm2[key]
|
100
|
+
end
|
101
|
+
|
102
|
+
#cm1[key].eql?(cm2_val)
|
103
|
+
# 当配置中有信息时,那么只有当大于配置中的区间波动才会被记录
|
104
|
+
# 当有Pass值的时候,直接Pass
|
105
|
+
# 只有是数值才可以
|
106
|
+
if compare.has_key?(key)
|
107
|
+
compare[key] == "pass" ? true : (cm1[key].to_i < cm2_val.to_i + compare[key])
|
108
|
+
else
|
109
|
+
|
110
|
+
if cm1[key].eql?(cm2_val)
|
111
|
+
true
|
112
|
+
else
|
113
|
+
cm1[key].compare_val = cm2_val
|
114
|
+
false
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
@@ -0,0 +1,227 @@
|
|
1
|
+
#coding=utf-8
|
2
|
+
|
3
|
+
require "aio/core"
|
4
|
+
|
5
|
+
class Aio::Module::SpecialStyle::CompareWithDeviceManager < Aio::Module::SpecialStyle
|
6
|
+
include Aio::Module
|
7
|
+
|
8
|
+
include Aio::Ui::Verbose
|
9
|
+
|
10
|
+
# 用于传递已经分析好的现有的device
|
11
|
+
attr_accessor :device_manager
|
12
|
+
|
13
|
+
# 用于传递由上一次成的device_manager信息
|
14
|
+
attr_accessor :input_benchmark
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
super({
|
18
|
+
:author => "Elin",
|
19
|
+
:description => "此模块用于解析两次生成的device_manager值",
|
20
|
+
})
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse
|
24
|
+
# 将device_manager 中的按照{device_name => useful} 形式重新编排
|
25
|
+
# cmds_useful为深度克隆信息,对本体无影响
|
26
|
+
device_warning = {}
|
27
|
+
input_benchmark_device_warning = {}
|
28
|
+
total = device_manager.devices_number
|
29
|
+
print_good "总共 #{total} 台设备进行比较"
|
30
|
+
|
31
|
+
device_manager.each_devices_with_index do |device_name, device_klass, i|
|
32
|
+
|
33
|
+
device_warning[device_name] = Aio::Base::Toolkit::DeepClone.clone(device_klass.cmds_useful)
|
34
|
+
# 进度条
|
35
|
+
progress_bar(total, i+1, device_name)
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
input_benchmark.each_devices_with_index do |device_name, device_klass, i|
|
40
|
+
|
41
|
+
input_benchmark_device_warning[device_name] = Aio::Base::Toolkit::DeepClone.clone(device_klass.cmds_useful)
|
42
|
+
# 进度条
|
43
|
+
progress_bar(total, i+1, device_name)
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
clear_line
|
48
|
+
clear_other_info(device_warning, input_benchmark_device_warning)
|
49
|
+
compare(device_warning, input_benchmark_device_warning)
|
50
|
+
end
|
51
|
+
|
52
|
+
# 只留下要比较的两个数据有共同命令的交集,其他的命令就丢弃
|
53
|
+
# 因为即使是保留了,产生的也是大量的垃圾信息
|
54
|
+
def clear_other_info(device_warning, input_benchmark)
|
55
|
+
device_arr = {}
|
56
|
+
input_arr = {}
|
57
|
+
|
58
|
+
# 获得命令信息
|
59
|
+
device_warning.each_pair { |k, v| device_arr[k] = v.keys }
|
60
|
+
input_benchmark.each_pair { |k, v| input_arr[k] = v.keys }
|
61
|
+
|
62
|
+
# 删除 device_warning 中多余的命令信息
|
63
|
+
device_warning.each_pair do |name, hash|
|
64
|
+
hash.delete_if do |k, v|
|
65
|
+
next true unless input_arr.has_key?(name)
|
66
|
+
input_arr[name].include?(k) ? false : true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# 删除 input_benchmark 中多余的命令信息
|
71
|
+
input_benchmark.each_pair do |name, hash|
|
72
|
+
hash.delete_if do |k, v|
|
73
|
+
next true unless device_arr.has_key?(name)
|
74
|
+
device_arr[name].include?(k) ? false : true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def compare(cm1, cm2, opts={})
|
80
|
+
# NOTE 待加PASS
|
81
|
+
@config_compare = Aio::Config::Warning::Compare
|
82
|
+
|
83
|
+
cm1_arr = []
|
84
|
+
cm2_arr = []
|
85
|
+
Aio::Base::Toolkit::Hash.flat_cm1(cm1,
|
86
|
+
Aio::Base::Toolkit::Chain.new,
|
87
|
+
cm1_arr)
|
88
|
+
|
89
|
+
Aio::Base::Toolkit::Hash.flat_cm2(cm2,
|
90
|
+
Aio::Base::Toolkit::Chain.new,
|
91
|
+
cm2_arr)
|
92
|
+
|
93
|
+
cp = find_diff_2(cm1_arr, cm2_arr)
|
94
|
+
|
95
|
+
diff = { cm1: [], cm2: []}
|
96
|
+
# NOTE 还需要加入config_compare
|
97
|
+
# diff = {
|
98
|
+
# cm1: [ [device_name, cmd, key, str], .. ],
|
99
|
+
# cm2: [ [device_name, cmd, key, str], .. ]
|
100
|
+
# }
|
101
|
+
cp[:cm1].each do |e|
|
102
|
+
# 加入cmd
|
103
|
+
cmd = e[1]
|
104
|
+
diff[:cm1] << [e.first, cmd, e[-2], e.last]
|
105
|
+
end
|
106
|
+
|
107
|
+
cp[:cm2].each do |e|
|
108
|
+
diff[e.first] ||= {}
|
109
|
+
# 加入cmd
|
110
|
+
cmd = e[1]
|
111
|
+
diff[:cm2] << [e.first, cmd, e[-2], e.last]
|
112
|
+
end
|
113
|
+
|
114
|
+
#detect_pass?(diff)
|
115
|
+
|
116
|
+
diff
|
117
|
+
end
|
118
|
+
|
119
|
+
# 检查是否为需要忽略的项
|
120
|
+
def detect_pass?(diff)
|
121
|
+
|
122
|
+
# 当没有就返回false,表示不能跳过
|
123
|
+
diff.each_value do |elem|
|
124
|
+
|
125
|
+
# 取key值
|
126
|
+
elem.delete_if do |e|
|
127
|
+
|
128
|
+
key = e[2]
|
129
|
+
if @config_compare.has_key?(key.to_sym)
|
130
|
+
@config_compare[key] == 'pass' ? true : false
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
# 低效率的双循环结构
|
140
|
+
def find_diff(cm1, cm2)
|
141
|
+
res = {}
|
142
|
+
cm1_dup = cm1.dup
|
143
|
+
cm2_dup = cm2.dup
|
144
|
+
|
145
|
+
debugger
|
146
|
+
# res 为相同的内容
|
147
|
+
total = cm1.size
|
148
|
+
cm1.each_with_index do |link_1, i|
|
149
|
+
|
150
|
+
cm2.each do |link_2|
|
151
|
+
|
152
|
+
# 如果长度不一致,就下一个
|
153
|
+
if link_1.size != link_2.size
|
154
|
+
next
|
155
|
+
|
156
|
+
else
|
157
|
+
name_1 = long_name(link_1)
|
158
|
+
name_2 = long_name(link_2)
|
159
|
+
|
160
|
+
if name_1 == name_2
|
161
|
+
cm1_dup.delete link_1
|
162
|
+
cm2_dup.delete link_2
|
163
|
+
|
164
|
+
# 找到了相同的就跳出小循环
|
165
|
+
break
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
# 进度条
|
172
|
+
progress_bar(total, i+1, '')
|
173
|
+
end
|
174
|
+
|
175
|
+
clear_line
|
176
|
+
|
177
|
+
# 获得不同的内容
|
178
|
+
res[:cm1] = cm1_dup
|
179
|
+
res[:cm2] = cm2_dup
|
180
|
+
|
181
|
+
res
|
182
|
+
end
|
183
|
+
|
184
|
+
# 将一个数组转化成一长串字符作为比较方式
|
185
|
+
def long_name(arr)
|
186
|
+
res = ''
|
187
|
+
arr.each { |x| res += x.to_s }
|
188
|
+
res
|
189
|
+
end
|
190
|
+
|
191
|
+
# 排序后循环,效率更高
|
192
|
+
def find_diff_2(cm1, cm2)
|
193
|
+
cm1.concat(cm2)
|
194
|
+
cm1.sort! { |x, y| x.string <=> y.string }
|
195
|
+
|
196
|
+
tmp = []
|
197
|
+
bool = false
|
198
|
+
cm1.each_with_index do |e, i|
|
199
|
+
# 当为真的时候,说明是重复的,就跳过
|
200
|
+
if bool
|
201
|
+
bool = false
|
202
|
+
next
|
203
|
+
end
|
204
|
+
|
205
|
+
# 当相等的时候,将bool 设置为true,跳过
|
206
|
+
if e.eql? cm1[i+1]
|
207
|
+
bool = true
|
208
|
+
next
|
209
|
+
end
|
210
|
+
|
211
|
+
# 如果和下一个不相等,则说明是单独的,那么就记录
|
212
|
+
tmp << e
|
213
|
+
end
|
214
|
+
|
215
|
+
res = { cm1: [], cm2: [] }
|
216
|
+
tmp.each do |e|
|
217
|
+
case e.cm_type
|
218
|
+
when :cm1
|
219
|
+
res[:cm1] << e.line
|
220
|
+
when :cm2
|
221
|
+
res[:cm2] << e.line
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
res
|
226
|
+
end
|
227
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aio_elin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 网络设备巡检工具
|
14
14
|
email: 365433079@qq.com
|
@@ -31,7 +31,9 @@ files:
|
|
31
31
|
- lib/aio/base/toolkit/excel_office.rb
|
32
32
|
- lib/aio/base/toolkit/excel_wps.rb
|
33
33
|
- lib/aio/base/toolkit/excel_wps.rb.bak
|
34
|
+
- lib/aio/base/toolkit/hash.rb
|
34
35
|
- lib/aio/base/toolkit/ipaddr.rb
|
36
|
+
- lib/aio/base/toolkit/myers.rb
|
35
37
|
- lib/aio/base/toolkit/os.rb
|
36
38
|
- lib/aio/base/toolkit/regexp.rb
|
37
39
|
- lib/aio/base/toolkit/string.rb
|
@@ -54,6 +56,7 @@ files:
|
|
54
56
|
- lib/aio/core/device_manager.rb
|
55
57
|
- lib/aio/core/module.rb
|
56
58
|
- lib/aio/core/module/cmd.rb
|
59
|
+
- lib/aio/core/module/compare.rb
|
57
60
|
- lib/aio/core/module/description.rb
|
58
61
|
- lib/aio/core/module/input_style.rb
|
59
62
|
- lib/aio/core/module/output_style.rb
|
@@ -78,8 +81,11 @@ files:
|
|
78
81
|
- lib/aio/core/parse/parser_machine/no_device_state.rb
|
79
82
|
- lib/aio/core/parse/parser_machine/parent_state.rb
|
80
83
|
- lib/aio/core/text.rb
|
84
|
+
- lib/aio/core/text/block.rb
|
85
|
+
- lib/aio/core/text/compare.rb
|
81
86
|
- lib/aio/core/text/context.rb
|
82
87
|
- lib/aio/core/text/line_string.rb
|
88
|
+
- lib/aio/core/text/match_string_info.rb
|
83
89
|
- lib/aio/core/text/warning.rb
|
84
90
|
- lib/aio/core/warning.rb
|
85
91
|
- lib/aio/core/warning/description.rb
|
@@ -90,6 +96,7 @@ files:
|
|
90
96
|
- lib/aio/resource/logo.png
|
91
97
|
- lib/aio/ui.rb
|
92
98
|
- lib/aio/ui/banner.rb
|
99
|
+
- lib/aio/ui/logger.rb
|
93
100
|
- lib/aio/ui/readable_text.rb
|
94
101
|
- lib/aio/ui/verbose.rb
|
95
102
|
- lib/aio/ui/version.rb
|
@@ -120,7 +127,10 @@ files:
|
|
120
127
|
- lib/modules/cmd/h3c/display_power.rb
|
121
128
|
- lib/modules/cmd/h3c/display_version.rb
|
122
129
|
- lib/modules/cmd/h3c/display_vrrp_verbose.rb
|
130
|
+
- lib/modules/cmd/maipu/show_clock.rb
|
131
|
+
- lib/modules/cmd/maipu/show_cpu.rb
|
123
132
|
- lib/modules/cmd/maipu/show_env.rb
|
133
|
+
- lib/modules/cmd/maipu/show_ip_interface_brief.rb
|
124
134
|
- lib/modules/cmd/maipu/show_ip_route.rb
|
125
135
|
- lib/modules/cmd/maipu/show_ip_route_statistic.rb
|
126
136
|
- lib/modules/cmd/maipu/show_memory.rb
|
@@ -142,6 +152,7 @@ files:
|
|
142
152
|
- lib/modules/input/style/xinhua_nat.rb
|
143
153
|
- lib/modules/output/style/boc_day.rb
|
144
154
|
- lib/modules/output/style/cmds.rb
|
155
|
+
- lib/modules/output/style/compare_diff.rb
|
145
156
|
- lib/modules/output/style/compare_json.rb
|
146
157
|
- lib/modules/output/style/compare_report.rb
|
147
158
|
- lib/modules/output/style/compare_xml.rb
|
@@ -149,6 +160,8 @@ files:
|
|
149
160
|
- lib/modules/output/style/excel_table_wps.rb
|
150
161
|
- lib/modules/output/style/summary_report.rb
|
151
162
|
- lib/modules/special/style/compare.rb
|
163
|
+
- lib/modules/special/style/compare_old.rb
|
164
|
+
- lib/modules/special/style/compare_with_device_manager.rb
|
152
165
|
homepage: http://rubygems.org/gems/aio
|
153
166
|
licenses:
|
154
167
|
- NGPL
|
@@ -169,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
182
|
version: '0'
|
170
183
|
requirements: []
|
171
184
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.7.
|
185
|
+
rubygems_version: 2.7.7
|
173
186
|
signing_key:
|
174
187
|
specification_version: 4
|
175
188
|
summary: Aio Tool
|