]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
better reporting of puppet progress (supply_drop hack)
authorelijah <elijah@riseup.net>
Sun, 4 Nov 2012 09:22:23 +0000 (01:22 -0800)
committerelijah <elijah@riseup.net>
Sun, 4 Nov 2012 09:22:23 +0000 (01:22 -0800)
lib/leap_cli/commands/deploy.rb
lib/leap_cli/util.rb
vendor/supply_drop/lib/supply_drop/writer/streaming.rb

index f820e5aec3a70a0dde8cee74b6b8008c1b3efb9c..13fcb1dcc1f6735c437e9e9521d4aaa6e460fa8f 100644 (file)
@@ -39,11 +39,10 @@ module LeapCli
           #
           ssh.set :puppet_source, [Path.platform, 'puppet'].join('/')
           ssh.set :puppet_destination, '/srv/leap'
-          ssh.set :puppet_command, '/usr/bin/puppet apply'
+          ssh.set :puppet_command, '/usr/bin/puppet apply --color=false'
           ssh.set :puppet_lib, "puppet/modules"
           ssh.set :puppet_parameters, '--confdir puppet puppet/manifests/site.pp'
-          #cap.set :puppet_stream_output, false
-          #puppet_cmd = "cd #{puppet_destination} && #{sudo_cmd} #{puppet_command} --modulepath=#{puppet_lib} #{puppet_parameters}"
+          ssh.set :puppet_stream_output, true
           ssh.apply_puppet
         end
       end
index 909dc0a4897d927bbc2c4abb368a3acd47e4f631..ba888912cb02e1648605108f6d1f409687e49d86 100644 (file)
@@ -1,4 +1,5 @@
 require 'digest/md5'
+require 'paint'
 
 module LeapCli
 
@@ -112,19 +113,19 @@ module LeapCli
     end
 
     def progress_created(path)
-      progress 'created %s' % relative_path(path)
+      progress Paint['created', :green, :bold] + ' ' + relative_path(path)
     end
 
     def progress_updated(path)
-      progress 'updated %s' % relative_path(path)
+      progress Paint['updated', :cyan, :bold] + ' ' + relative_path(path)
     end
 
     def progress_nochange(path)
-      progress2 'no change %s' % relative_path(path)
+      progress2 Paint['no change', :white, :bold] + ' ' + relative_path(path)
     end
 
     def progress_removed(path)
-      progress 'removed %s' % relative_path(path)
+      progress Paint['removed', :red, :bold] + ' ' + relative_path(path)
     end
 
     #
index e180ec8068525bb650e80dc423f6d6f71b443f22..334a41e4d9a1205fb7c5b92e97bdb5d48303b88c 100644 (file)
@@ -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