Sha256: b9174234b4601b646b2cf98e436e2f99ced5f173d35ef7a9cb32dbe4874921fa

Contents?: true

Size: 1.83 KB

Versions: 15

Compression:

Stored size: 1.83 KB

Contents

require 'kafo_configure/lib/kafo/puppet/report_wrapper'

module Puppet::Parser::Functions
  newfunction(:add_progress) do |args|
    loaded = false
    begin
      require 'puppet/transaction'
      loaded = true
    rescue LoadError
      ::Puppet.warning 'Unable to load puppet/transaction for progress bar support, this version may not be supported'
    end

    if loaded
      # Monkey patch the transaction to put our wrapper around the report object
      class Puppet::Transaction
        attr_accessor :in_main_catalog

        def is_interesting?(resource)
          ![:schedule, :class, :stage, :filebucket, :anchor, :'kafo_configure::yaml_to_class'].include?(resource.to_s.split('[')[0].downcase.to_sym)
        end

        def tracked_resources
          @tracked_resources ||= catalog.vertices.select { |resource| is_interesting?(resource) }.map(&:to_s)
        end

        def evaluate_with_trigger(*args, &block)
          if catalog.version
            self.in_main_catalog = true
            ::Puppet.info "START #{tracked_resources.size}"
          end
          evaluate_without_trigger(*args, &block)
          self.in_main_catalog = false if catalog.version
        end

        def report_with_wrapper
          unless @report_wrapper
            @report_wrapper = Kafo::Puppet::ReportWrapper.new(self, report_without_wrapper)
          end
          @report_wrapper
        end

        if method_defined?(:evaluate) && method_defined?(:report)
          alias_method :evaluate_without_trigger, :evaluate
          alias_method :evaluate, :evaluate_with_trigger
          alias_method :report_without_wrapper, :report
          alias_method :report, :report_with_wrapper
        else
          ::Puppet.warning 'Unable to patch Puppet transactions for progress bar support, this version may not be supported'
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
kafo-1.0.4 modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb
kafo-0.9.8 modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb
kafo-1.0.3 modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb
kafo-0.9.7 modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb
kafo-1.0.2 modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb
kafo-1.0.1 modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb
kafo-1.0.0 modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb
kafo-0.9.6 modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb
kafo-0.9.5 modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb
kafo-0.9.4 modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb
kafo-0.9.3 modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb
kafo-0.9.2 modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb
kafo-0.9.1 modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb
kafo-0.9.0 modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb
kafo-0.8.2 modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb