Sha256: c0cf380c34f53b843b24d213fbb1aaf29d7c739412e5902da73596fe5ace57a0

Contents?: true

Size: 1.45 KB

Versions: 79

Compression:

Stored size: 1.45 KB

Contents

module Katello
  module Pulp
    class ContentCountsCalculator
      def initialize(repos)
        @repos = repos
      end

      def calculate
        counts = {
          :yum_repositories => 0,
          :packages => 0,
          :package_groups => 0,
          :errata => 0,
          :puppet_repositories => 0,
          :puppet_modules => 0,
          :docker_repositories => 0,
          :docker_images => 0
        }

        @repos.each do |repo|
          case
          when repo_type?(repo, 'rpm')
            counts[:yum_repositories] += 1
            counts[:packages] += get_unit_count(repo, 'rpm')
            counts[:package_groups] += get_unit_count(repo, 'package_group')
            counts[:errata] += get_unit_count(repo, 'erratum')
          when repo_type?(repo, 'docker')
            counts[:docker_repositories] += 1
            counts[:docker_images] += get_unit_count(repo, 'docker_image')
          when repo_type?(repo, 'puppet')
            counts[:puppet_repositories] += 1
            counts[:puppet_modules] += get_unit_count(repo, 'puppet_module')
          end
        end

        counts
      end

      protected

      def repo_type?(repo, repo_type)
        repo['notes'] && (repo['notes']['_repo-type'] == "#{repo_type}-repo")
      end

      def get_unit_count(repo, unit_type)
        if repo['content_unit_counts']
          repo['content_unit_counts'][unit_type] || 0
        else
          0
        end
      end
    end
  end
end

Version data entries

79 entries across 79 versions & 1 rubygems

Version Path
katello-3.5.0.rc2 app/services/katello/pulp/content_counts_calculator.rb
katello-3.5.0.rc1 app/services/katello/pulp/content_counts_calculator.rb
katello-3.4.5 app/services/katello/pulp/content_counts_calculator.rb
katello-3.4.4 app/services/katello/pulp/content_counts_calculator.rb
katello-3.4.2 app/services/katello/pulp/content_counts_calculator.rb
katello-3.4.1 app/services/katello/pulp/content_counts_calculator.rb
katello-3.4.0.2 app/services/katello/pulp/content_counts_calculator.rb
katello-3.4.0.1 app/services/katello/pulp/content_counts_calculator.rb
katello-3.3.2 app/services/katello/pulp/content_counts_calculator.rb
katello-3.4.0 app/services/katello/pulp/content_counts_calculator.rb
katello-3.4.0.rc2 app/services/katello/pulp/content_counts_calculator.rb
katello-3.4.0.rc1 app/services/katello/pulp/content_counts_calculator.rb
katello-3.3.1.1 app/services/katello/pulp/content_counts_calculator.rb
katello-3.3.1 app/services/katello/pulp/content_counts_calculator.rb
katello-3.3.0.1 app/services/katello/pulp/content_counts_calculator.rb
katello-3.3.0 app/services/katello/pulp/content_counts_calculator.rb
katello-3.3.0.rc2 app/services/katello/pulp/content_counts_calculator.rb
katello-3.3.0.rc1.1 app/services/katello/pulp/content_counts_calculator.rb
katello-3.3.0.rc1 app/services/katello/pulp/content_counts_calculator.rb
katello-3.2.1.1 app/services/katello/pulp/content_counts_calculator.rb