aio_elin 1.0.1 → 1.0.2
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/lib/aio/base/toolkit/myers.rb +8 -0
- data/lib/modules/input/style/console.rb +215 -214
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: ec78b85511d7bf50150105a4a9c4668ce103ea9f4440b5536e1af0c2be9d309f
         | 
| 4 | 
            +
              data.tar.gz: ca257da733025cf4ccb5dc2297da2ea088b286bf27375fb8c2e53e58c0575020
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: f90bd170d42af4e816ab04fc345a9b54bee66ea65c757c432290ca692997b4713299f1b0f8b2f18e83707774790a0a7e0460891b41e2c48c0629329d781d943a
         | 
| 7 | 
            +
              data.tar.gz: ee6f3299b774d705de437a1a7fcadd4428e665630a9656ad80860e954e1a21d2198a982d7314c19ca2ffd3fab2870eef06ff7d8b9192894018d1ba5834a5ba18
         | 
| @@ -3,220 +3,221 @@ | |
| 3 3 | 
             
            require "aio/core"
         | 
| 4 4 |  | 
| 5 5 | 
             
            class Aio::Module::InputStyle::Console < Aio::Module::InputStyle
         | 
| 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 | 
            -
             | 
| 109 | 
            -
             | 
| 110 | 
            -
             | 
| 111 | 
            -
             | 
| 112 | 
            -
             | 
| 113 | 
            -
             | 
| 114 | 
            -
             | 
| 115 | 
            -
             | 
| 116 | 
            -
             | 
| 117 | 
            -
             | 
| 118 | 
            -
             | 
| 119 | 
            -
             | 
| 120 | 
            -
             | 
| 121 | 
            -
             | 
| 122 | 
            -
             | 
| 123 | 
            -
             | 
| 124 | 
            -
             | 
| 125 | 
            -
             | 
| 126 | 
            -
             | 
| 127 | 
            -
             | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
             | 
| 131 | 
            -
             | 
| 132 | 
            -
             | 
| 133 | 
            -
             | 
| 134 | 
            -
             | 
| 135 | 
            -
             | 
| 136 | 
            -
             | 
| 137 | 
            -
             | 
| 138 | 
            -
             | 
| 139 | 
            -
             | 
| 140 | 
            -
             | 
| 141 | 
            -
             | 
| 142 | 
            -
             | 
| 143 | 
            -
             | 
| 144 | 
            -
             | 
| 145 | 
            -
             | 
| 146 | 
            -
             | 
| 147 | 
            -
             | 
| 148 | 
            -
             | 
| 149 | 
            -
             | 
| 150 | 
            -
             | 
| 151 | 
            -
             | 
| 152 | 
            -
             | 
| 153 | 
            -
             | 
| 154 | 
            -
             | 
| 155 | 
            -
             | 
| 156 | 
            -
             | 
| 157 | 
            -
             | 
| 158 | 
            -
             | 
| 159 | 
            -
             | 
| 160 | 
            -
             | 
| 161 | 
            -
             | 
| 162 | 
            -
             | 
| 163 | 
            -
             | 
| 164 | 
            -
             | 
| 165 | 
            -
             | 
| 166 | 
            -
             | 
| 167 | 
            -
             | 
| 168 | 
            -
             | 
| 169 | 
            -
             | 
| 170 | 
            -
             | 
| 171 | 
            -
             | 
| 172 | 
            -
             | 
| 173 | 
            -
             | 
| 174 | 
            -
             | 
| 175 | 
            -
             | 
| 176 | 
            -
             | 
| 177 | 
            -
             | 
| 178 | 
            -
             | 
| 179 | 
            -
             | 
| 180 | 
            -
             | 
| 181 | 
            -
             | 
| 182 | 
            -
             | 
| 183 | 
            -
             | 
| 184 | 
            -
             | 
| 185 | 
            -
             | 
| 186 | 
            -
             | 
| 187 | 
            -
             | 
| 188 | 
            -
             | 
| 189 | 
            -
             | 
| 190 | 
            -
             | 
| 191 | 
            -
             | 
| 192 | 
            -
             | 
| 193 | 
            -
             | 
| 194 | 
            -
             | 
| 195 | 
            -
             | 
| 196 | 
            -
             | 
| 197 | 
            -
             | 
| 198 | 
            -
             | 
| 199 | 
            -
             | 
| 200 | 
            -
             | 
| 201 | 
            -
             | 
| 202 | 
            -
             | 
| 203 | 
            -
             | 
| 204 | 
            -
             | 
| 205 | 
            -
             | 
| 206 | 
            -
             | 
| 207 | 
            -
             | 
| 208 | 
            -
             | 
| 209 | 
            -
             | 
| 210 | 
            -
             | 
| 211 | 
            -
             | 
| 212 | 
            -
             | 
| 213 | 
            -
             | 
| 214 | 
            -
             | 
| 215 | 
            -
             | 
| 216 | 
            -
             | 
| 217 | 
            -
             | 
| 218 | 
            -
             | 
| 219 | 
            -
             | 
| 6 | 
            +
              include Aio::Module
         | 
| 7 | 
            +
              include Aio::Ui::Verbose
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              class Machine
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                attr_accessor :regs, :state
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def initialize
         | 
| 14 | 
            +
                  @cmd_state = CmdState.new(self)
         | 
| 15 | 
            +
                  @context_state = ContextState.new(self)
         | 
| 16 | 
            +
                  @empty_state = EmptyState.new(self)
         | 
| 17 | 
            +
                  @cmd_context = CmdContext.new
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  @state = @empty_state
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def state
         | 
| 23 | 
            +
                  @state.class
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                def cmd_context
         | 
| 27 | 
            +
                  @cmd_context
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                def to_cmd_state
         | 
| 31 | 
            +
                  @state = @cmd_state
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                def to_context_state
         | 
| 35 | 
            +
                  @state = @context_state
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                def to_empty_state
         | 
| 39 | 
            +
                  @state = @empty_state
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                def parse_line(line)
         | 
| 43 | 
            +
                  @state.parse_line(line)
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
              end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              class CmdContext
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                attr_accessor :device_name, :cmd, :context
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                # all_info = [[device_name, cmd, context] ... ]
         | 
| 52 | 
            +
                attr_accessor :all_info
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                def initialize
         | 
| 55 | 
            +
                  @device_name = ""
         | 
| 56 | 
            +
                  @cmd = ""
         | 
| 57 | 
            +
                  @context = []
         | 
| 58 | 
            +
                  @all_info = []
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                def done
         | 
| 62 | 
            +
                  # 当之前有cmd内容的时候,比较两个的长度
         | 
| 63 | 
            +
                  # 长的保留
         | 
| 64 | 
            +
                  info_idx = has_cmd?
         | 
| 65 | 
            +
                  if info_idx
         | 
| 66 | 
            +
                    if @all_info[info_idx][2].size < context.size
         | 
| 67 | 
            +
                      @all_info[info_idx][2] = context
         | 
| 68 | 
            +
                    end
         | 
| 69 | 
            +
                  else
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                    # 如果都没有,那么就直接添加
         | 
| 72 | 
            +
                    @all_info << [device_name, cmd, context]
         | 
| 73 | 
            +
                  end
         | 
| 74 | 
            +
                  self.clear
         | 
| 75 | 
            +
                end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                def has_cmd?
         | 
| 78 | 
            +
                  @all_info.each_with_index do |info, idx|
         | 
| 79 | 
            +
                    next unless info[0] == device_name
         | 
| 80 | 
            +
                    return idx if info[1] == cmd
         | 
| 81 | 
            +
                  end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                  return nil
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                def clear
         | 
| 87 | 
            +
                  @device_name = ""
         | 
| 88 | 
            +
                  @cmd = ""
         | 
| 89 | 
            +
                  @context = []
         | 
| 90 | 
            +
                end
         | 
| 91 | 
            +
              end
         | 
| 92 | 
            +
             | 
| 93 | 
            +
              class State
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                include Aio::Ui::Verbose
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                def initialize(machine)
         | 
| 98 | 
            +
                  @machine = machine
         | 
| 99 | 
            +
                end
         | 
| 100 | 
            +
             | 
| 101 | 
            +
                def cmd_context
         | 
| 102 | 
            +
                  @machine.cmd_context
         | 
| 103 | 
            +
                end
         | 
| 104 | 
            +
              end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
              class EmptyState < State
         | 
| 107 | 
            +
                def parse_line(line)
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                  # 当前是空的状态
         | 
| 110 | 
            +
                  # 判断当前行有没有模块中的命令
         | 
| 111 | 
            +
                  line = Aio::Base::Toolkit::String.safe(line)
         | 
| 112 | 
            +
                  return unless @machine.regs.match(line)
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                  @machine.to_cmd_state
         | 
| 115 | 
            +
                  @machine.parse_line(line)
         | 
| 116 | 
            +
                end
         | 
| 117 | 
            +
              end
         | 
| 118 | 
            +
             | 
| 119 | 
            +
              class CmdState < State
         | 
| 120 | 
            +
                def parse_line(line)
         | 
| 121 | 
            +
                  # 判断是不是cmd命令行
         | 
| 122 | 
            +
                  res = /^[\[|<]?(?<name>.*)(#|>|\])(?<cmd>.*)/.match(line)
         | 
| 123 | 
            +
                  if res.nil?
         | 
| 124 | 
            +
                    @machine.to_empty_state
         | 
| 125 | 
            +
                    return
         | 
| 126 | 
            +
                  end
         | 
| 127 | 
            +
             | 
| 128 | 
            +
                  # 当已经发现了是cmd行,那么紧接下来就是收集文本内容
         | 
| 129 | 
            +
                  cmd_context.device_name = res[:name]
         | 
| 130 | 
            +
                  cmd_context.cmd = res[:cmd]
         | 
| 131 | 
            +
                  @machine.to_context_state
         | 
| 132 | 
            +
                end
         | 
| 133 | 
            +
              end
         | 
| 134 | 
            +
             | 
| 135 | 
            +
              class ContextState < State
         | 
| 136 | 
            +
             | 
| 137 | 
            +
                def parse_line(line)
         | 
| 138 | 
            +
                  # 如果这行是命令行格式,那么就代表上一个cmd内容结束
         | 
| 139 | 
            +
                  tmp_reg = ::Regexp.new "^[\\[|<]?#{cmd_context.device_name}(#|>|\\])"
         | 
| 140 | 
            +
             | 
| 141 | 
            +
                  # 可能会出现UTF-8识别不出摄氏度符号的问题
         | 
| 142 | 
            +
                  # 已经通过安全字符解决
         | 
| 143 | 
            +
                  begin
         | 
| 144 | 
            +
                    if tmp_reg.match(line)
         | 
| 145 | 
            +
                      cmd_context.done
         | 
| 146 | 
            +
             | 
| 147 | 
            +
                      # 完成后将状态设置为空,并且重新分析这一行
         | 
| 148 | 
            +
                      # 毕竟如果这行也cmd行呢
         | 
| 149 | 
            +
                      @machine.to_empty_state
         | 
| 150 | 
            +
                      return @machine.parse_line(line)
         | 
| 151 | 
            +
                    end
         | 
| 152 | 
            +
                  rescue => e
         | 
| 153 | 
            +
                    print_error cmd_context.device_name + " 设备巡检信息编码出现问题"
         | 
| 154 | 
            +
                    print_error line + " : " + e.message
         | 
| 155 | 
            +
                  end
         | 
| 156 | 
            +
             | 
| 157 | 
            +
             | 
| 158 | 
            +
                  cmd_context.context << line
         | 
| 159 | 
            +
                end
         | 
| 160 | 
            +
              end
         | 
| 161 | 
            +
             | 
| 162 | 
            +
              def initialize
         | 
| 163 | 
            +
                super({
         | 
| 164 | 
            +
                  :author				=> "Elin",
         | 
| 165 | 
            +
                  :description 	=> "这个模块用于对命令行格式的输入处理",
         | 
| 166 | 
            +
                  :platform 		=> "all",
         | 
| 167 | 
            +
                })
         | 
| 168 | 
            +
                @machine = Machine.new
         | 
| 169 | 
            +
              end
         | 
| 170 | 
            +
             | 
| 171 | 
            +
              def parse
         | 
| 172 | 
            +
                dir = self.input_file
         | 
| 173 | 
            +
                dir_pn = Pathname.new(dir)
         | 
| 174 | 
            +
             | 
| 175 | 
            +
                # 加载所有的cmd正则表达式
         | 
| 176 | 
            +
                @machine.regs = merge_regs(ext_info[:cmds_reg])
         | 
| 177 | 
            +
             | 
| 178 | 
            +
                # 如果是单个文件的话,直接进入文件解析模式
         | 
| 179 | 
            +
                if dir_pn.file?
         | 
| 180 | 
            +
                  parse_file(dir_pn)
         | 
| 181 | 
            +
                else
         | 
| 182 | 
            +
             | 
| 183 | 
            +
                  # 如果是文件夹的话,那么就对每个文件进行解析
         | 
| 184 | 
            +
                  Find.find(dir) do |file|
         | 
| 185 | 
            +
                    fn = Pathname.new(file)
         | 
| 186 | 
            +
                    parse_file(file) if fn.file?
         | 
| 187 | 
            +
                  end
         | 
| 188 | 
            +
                end
         | 
| 189 | 
            +
             | 
| 190 | 
            +
                @machine.cmd_context.all_info.each do |info|
         | 
| 191 | 
            +
                  yield info[0], info[1], info[2]
         | 
| 192 | 
            +
                end
         | 
| 193 | 
            +
              end
         | 
| 194 | 
            +
             | 
| 195 | 
            +
              def parse_file(file)
         | 
| 196 | 
            +
                fo = File.open(file, "r+", :encoding => "utf-8")
         | 
| 197 | 
            +
             | 
| 198 | 
            +
                fo.each_line do |line|
         | 
| 199 | 
            +
                  begin 
         | 
| 200 | 
            +
                    line = Aio::Base::Toolkit::String.safe(line)
         | 
| 201 | 
            +
                    line = line.strip
         | 
| 202 | 
            +
                  rescue => e
         | 
| 203 | 
            +
                    print_error line + " : " + e.message
         | 
| 204 | 
            +
                  end
         | 
| 205 | 
            +
             | 
| 206 | 
            +
                  @machine.parse_line(line)
         | 
| 207 | 
            +
                end
         | 
| 208 | 
            +
             | 
| 209 | 
            +
                # 如果最后没有done结束,则手动结束
         | 
| 210 | 
            +
                if @machine.state == ContextState
         | 
| 211 | 
            +
                  @machine.cmd_context.done 
         | 
| 212 | 
            +
                  @machine.to_cmd_state
         | 
| 213 | 
            +
                end
         | 
| 214 | 
            +
              end
         | 
| 215 | 
            +
             | 
| 216 | 
            +
              def merge_regs(arr_regs)
         | 
| 217 | 
            +
                regs = Aio::Base::Toolkit::Regexp.merge(arr_regs).to_s
         | 
| 218 | 
            +
                regs.gsub!('(^', '(')
         | 
| 219 | 
            +
                ::Regexp.new(regs)
         | 
| 220 | 
            +
              end
         | 
| 220 221 | 
             
            end
         | 
| 221 222 |  | 
| 222 223 |  | 
    
        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: 1.0. | 
| 4 | 
            +
              version: 1.0.2
         | 
| 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-12-04 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 13 | 
             
            description: 网络设备巡检工具
         | 
| 14 14 | 
             
            email: 365433079@qq.com
         |