lib/kafo/kafo_configure.rb in kafo-0.0.17 vs lib/kafo/kafo_configure.rb in kafo-0.1.0
- old
+ new
@@ -7,18 +7,19 @@
require 'kafo/logger'
require 'kafo/string_helper'
require 'kafo/wizard'
require 'kafo/system_checker'
require 'kafo/puppet_command'
+require 'kafo/progress_bar'
class KafoConfigure < Clamp::Command
include StringHelper
attr_reader :logger
class << self
attr_accessor :config, :root_dir, :config_file, :gem_root, :temp_config_file,
- :modules_dir, :kafo_modules_dir
+ :modules_dir, :kafo_modules_dir, :verbose
end
def initialize(*args)
self.class.config_file = config_file
self.class.config = Configuration.new(self.class.config_file)
@@ -27,10 +28,11 @@
self.class.modules_dir = File.expand_path(modules_dir)
self.class.gem_root = File.join(File.dirname(__FILE__), '../../')
self.class.kafo_modules_dir = self.class.config.app[:kafo_modules_dir] || (self.class.gem_root + '/modules')
Logger.setup
@logger = Logging.logger.root
+ @progress_bar = nil
super
set_parameters
set_options
end
@@ -40,12 +42,14 @@
def execute
catch :exit do
parse_cli_arguments
- if verbose?
+ if (self.class.verbose = verbose?)
logger.appenders = logger.appenders << ::Logging.appenders.stdout(:layout => Logger::COLOR_LAYOUT)
+ else
+ @progress_bar = ProgressBar.new
end
unless SystemChecker.check
puts "Your system does not meet configuration criteria"
exit(:invalid_system)
@@ -202,11 +206,14 @@
options.push '--noop' if noop?
begin
command = PuppetCommand.new('include kafo_configure', options).command
PTY.spawn(command) do |stdin, stdout, pid|
begin
- stdin.each { |line| puppet_log(line) }
+ stdin.each do |line|
+ puppet_log(*puppet_parse(line))
+ @progress_bar.update(line) if @progress_bar
+ end
rescue Errno::EIO
if PTY.respond_to?(:check) # ruby >= 1.9.2
exit_code = PTY.check(pid, true).exitstatus
else # ruby < 1.9.2
Process.wait(pid) rescue Errno::ECHILD
@@ -215,16 +222,22 @@
end
end
rescue PTY::ChildExited => e
exit_code = e.status.exitstatus
end
+ @progress_bar.close if @progress_bar
logger.info "Puppet has finished, bye!"
FileUtils.rm(temp_config_file, :force => true)
exit(exit_code)
end
- def puppet_log(line)
+ def puppet_log(method, message)
+ @progress_bar.print ANSI::Code.red { message + "\n" } if method == :error && @progress_bar
+ Logging.logger['puppet'].send(method, message)
+ end
+
+ def puppet_parse(line)
method, message = case
when line =~ /^Error:(.*)/i || line =~ /^Err:(.*)/i
[:error, $1]
when line =~ /^Warning:(.*)/i || line =~ /^Notice:(.*)/i
[:warn, $1]
@@ -233,10 +246,11 @@
when line =~ /^Debug:(.*)/i
[:debug, $1]
else
[:info, line]
end
- Logging.logger['puppet'].send(method, message.chomp)
+
+ return [method, message.chomp]
end
def unset
params.select { |p| p.module.enabled? && p.value_set.nil? }
end