summaryrefslogtreecommitdiff
path: root/vendor/supply_drop
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-11-04 01:22:23 -0800
committerelijah <elijah@riseup.net>2012-11-04 01:22:23 -0800
commitdc3eeb6d98a48ab1834dc2d76514664a204b3619 (patch)
tree3132ea48a3b7ba555ba2b83e2fb208aca6386f9c /vendor/supply_drop
parent05f4f6944e8b44ea92eaf55c7368261478ee41ea (diff)
better reporting of puppet progress (supply_drop hack)
Diffstat (limited to 'vendor/supply_drop')
-rw-r--r--vendor/supply_drop/lib/supply_drop/writer/streaming.rb48
1 files changed, 47 insertions, 1 deletions
diff --git a/vendor/supply_drop/lib/supply_drop/writer/streaming.rb b/vendor/supply_drop/lib/supply_drop/writer/streaming.rb
index e180ec8..334a41e 100644
--- a/vendor/supply_drop/lib/supply_drop/writer/streaming.rb
+++ b/vendor/supply_drop/lib/supply_drop/writer/streaming.rb
@@ -1,12 +1,58 @@
+begin
+ require 'paint'
+rescue
+end
+
module SupplyDrop
module Writer
class Streaming
def initialize(logger)
+ @mode = Capistrano::Logger::DEBUG
@logger = logger
end
def collect_output(host, data)
- @logger.debug data, host
+ if data =~ /^(notice|err|warning):/
+ @mode = $1
+
+ # force the printing of 'finished catalog run' if there have not been any errors
+ if @mode == 'notice' && !@error_encountered && data =~ /Finished catalog run/
+ @mode = 'forced_notice'
+ elsif @mode == 'err'
+ @error_encountered = true
+ end
+ end
+
+ # log each line, colorizing the hostname
+ data.lines.each do |line|
+ if line =~ /\w/
+ @logger.log log_level, line.sub(/\n$/,''), colorize(host)
+ end
+ end
+ end
+
+ def log_level
+ case @mode
+ when 'err' then Capistrano::Logger::IMPORTANT
+ when 'warning' then Capistrano::Logger::INFO
+ when 'notice' then Capistrano::Logger::DEBUG
+ else Capistrano::Logger::IMPORTANT
+ end
+ end
+
+ def colorize(str)
+ if defined? Paint
+ color = case @mode
+ when 'err' then :red
+ when 'warning' then :yellow
+ when 'notice' then :cyan
+ when 'forced_notice' then :cyan
+ else :clear
+ end
+ Paint[str, color, :bold]
+ else
+ str
+ end
end
def all_output_collected