lib/aio/ui.rb in aio_elin-0.0.1 vs lib/aio/ui.rb in aio_elin-1.0.0

- old
+ new

@@ -1,138 +1,139 @@ #coding=utf-8 module Aio::Ui - require "aio/ui/version" - require "aio/ui/banner" - require "aio/ui/readable_text" - require "aio/ui/verbose" + require "aio/ui/version" + require "aio/ui/banner" + require "aio/ui/readable_text" + require "aio/ui/verbose" + require "aio/ui/logger" - class Console + class Console - include Aio::Ui::Verbose - - # Aio::ModuleManager - attr_accessor :module_manager + include Aio::Ui::Verbose - # Aio::DeviceManager - attr_accessor :device_manager + # Aio::ModuleManager + attr_accessor :module_manager - # Aio::Parse::Parser - attr_accessor :parser + # Aio::DeviceManager + attr_accessor :device_manager - # Aio::Ui::Banner - attr_accessor :banner + # Aio::Parse::Parser + attr_accessor :parser - DefaultCompare = "special/style/compare" + # Aio::Ui::Banner + attr_accessor :banner - DefaultInputComapreXML = "input/style/compare_xml" + DefaultCompare = "special/style/compare" - def initialize(args) - self.banner = Banner.new.parse(args) - end + DefaultInputComapreXML = "input/style/compare_xml" - def process - case self.banner.mode - when 0 - proc_0 - when 1 - proc_1 - end - end + def initialize(args) + self.banner = Banner.new.parse(args) + end - # 输出模块表 - def proc_0 - case banner.type - when "cmd" - mods = module_manager.get_modules_by_type("cmd") - print ReadableText.dump_module_cmds(mods) - when "input" - mods = module_manager.get_modules_by_type("input") - print ReadableText.dump_module_inputs(mods) - when "output" - mods = module_manager.get_modules_by_type("output") - print ReadableText.dump_module_outputs(mods) - else - mods = module_manager.get_modules_by_type("cmd") - print ReadableText.dump_module_cmds(mods) - - mods = module_manager.get_modules_by_type("input") - print ReadableText.dump_module_inputs(mods) + def process + case self.banner.mode + when 0 + proc_0 + when 1 + proc_1 + end + end - mods = module_manager.get_modules_by_type("output") - print ReadableText.dump_module_outputs(mods) - end - end + # 输出模块表 + def proc_0 + case banner.type + when "cmd" + mods = module_manager.get_modules_by_type("cmd") + print ReadableText.dump_module_cmds(mods) + when "input" + mods = module_manager.get_modules_by_type("input") + print ReadableText.dump_module_inputs(mods) + when "output" + mods = module_manager.get_modules_by_type("output") + print ReadableText.dump_module_outputs(mods) + else + mods = module_manager.get_modules_by_type("cmd") + print ReadableText.dump_module_cmds(mods) - # 通过选择的输入输出模块进行操作 - def proc_1 + mods = module_manager.get_modules_by_type("input") + print ReadableText.dump_module_inputs(mods) - # 当完全没有指定input的时候,是可以跳过的 - if banner.has_input? - input_klass = module_manager.get_module_klass_by_name(banner.input_style) - input_klass.input_file = banner.input - input_klass.ext_info = {:cmds_reg => device_manager.just_cmds_reg} + mods = module_manager.get_modules_by_type("output") + print ReadableText.dump_module_outputs(mods) + end + end - parser.input_klass = input_klass - parser.parse_by_module + # 通过选择的输入输出模块进行操作 + def proc_1 - # 当有compare选项的时候,同时解析compare模块,并合并warning信息 - if banner.compare - print_good "正在加载比较模块" - if banner.compare =~ /\.xml$/ - input_klass_compare = module_manager.get_module_klass_by_name(DefaultInputComapreXML) - else - print_error "请确认 -c 参数文件后缀" - banner.banner - end + # 当完全没有指定input的时候,是可以跳过的 + if banner.has_input? + input_klass = module_manager.get_module_klass_by_name(banner.input_style) + input_klass.input_file = banner.input + input_klass.ext_info = {:cmds_reg => device_manager.just_cmds_reg} - input_klass_compare.input_file = banner.compare - compare_klass = module_manager.get_module_klass_by_name(DefaultCompare) + parser.input_klass = input_klass + parser.parse_by_module - print_good "比较模块加载成功" - print_good "正在进行对比..." - parser.input_klass = input_klass_compare - parser.parse_by_compare(compare_klass) - print_good "对比分析完成" - - end - - # Debug 处 - if Aio::Base::Debug.ui_enable? #or true - puts "[Debug UI]" - device_manager.devices.each_pair{|name, device_klass| - pp name - pp device_klass.cmds_useful["show version"] - #pp device_klass.device_name - #pp device_klass.cmds_useful - #pp device_klass.warning_klass.warning_info - puts - } - puts "[/Debug UI]" - end + # 当有compare选项的时候,同时解析compare模块,并合并warning信息 + if banner.compare + print_good "正在加载比较模块" + if banner.compare =~ /\.xml$/ + input_klass_compare = module_manager.get_module_klass_by_name(DefaultInputComapreXML) + else + print_error "请确认 -c 参数文件后缀" + banner.banner + end - device_manager.warning_summarize_tidy - end # 判断没有没 input 尾部 + input_klass_compare.input_file = banner.compare + compare_klass = module_manager.get_module_klass_by_name(DefaultCompare) - print_good "正在加载输出模块 #{banner.output_style}" - output_klass = module_manager.get_module_klass_by_name(banner.output_style) + print_good "比较模块加载成功" + print_good "正在进行对比..." + parser.input_klass = input_klass_compare + parser.parse_by_compare(compare_klass) + print_good "对比分析完成" - pn = Pathname.new(banner.output) - dir, base = pn.split - base = base.to_s - unless base =~ /\./ - suffix = output_klass.file_suffix - unless suffix == "" or /(?i)null/ =~ suffix - base << "." + suffix - end - end + end - print_good "正在输出文件 #{dir + base}" - output_klass.device_manager = device_manager - output_klass.module_manager = module_manager - output_klass.output_file = banner.output - output_klass.generate - print_good "输出文件完成" - end + # Debug 处 + if Aio::Base::Debug.ui_enable? #or true + puts "[Debug UI]" + device_manager.devices.each_pair{|name, device_klass| + pp name + pp device_klass.cmds_useful["show version"] + #pp device_klass.device_name + #pp device_klass.cmds_useful + #pp device_klass.warning_klass.warning_info + puts + } + puts "[/Debug UI]" + end - end + device_manager.warning_summarize_tidy + end # 判断没有没 input 尾部 + + print_good "正在加载输出模块 #{banner.output_style}" + output_klass = module_manager.get_module_klass_by_name(banner.output_style) + + pn = Pathname.new(banner.output) + dir, base = pn.split + base = base.to_s + unless base =~ /\./ + suffix = output_klass.file_suffix + unless suffix == "" or /(?i)null/ =~ suffix + base << "." + suffix + end + end + + print_good "正在输出文件 #{dir + base}" + output_klass.device_manager = device_manager + output_klass.module_manager = module_manager + output_klass.output_file = banner.output + output_klass.generate + print_good "输出文件完成" + end + + end end