Project

General

Profile

Revision c06f1783

Added by Thomas McKay over 6 years ago

fixes #15743 - import and export of subscriptions one-per-line

View differences:

lib/hammer_cli_csv/products.rb
14 14
      REPOSITORY_URL = 'Repository Url'
15 15
      DESCRIPTION = 'Description'
16 16

  
17
      def export
18
        CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
19
          csv << [NAME, LABEL, ORGANIZATION, DESCRIPTION, REPOSITORY, REPOSITORY_TYPE,
20
                  CONTENT_SET, RELEASE, REPOSITORY_URL]
21
          # TODO: DOWNLOAD_POLICY
22
          @api.resource(:organizations).call(:index, {
23
              :per_page => 999999
24
          })['results'].each do |organization|
25
            next if option_organization && organization['name'] != option_organization
26
            @api.resource(:products).call(:index, {
27
                'per_page' => 999999,
28
                'enabled' => true,
17
      def export(csv)
18
        csv << [NAME, LABEL, ORGANIZATION, DESCRIPTION, REPOSITORY, REPOSITORY_TYPE,
19
                CONTENT_SET, RELEASE, REPOSITORY_URL]
20
        # TODO: DOWNLOAD_POLICY
21
        @api.resource(:organizations).call(:index, {
22
            :per_page => 999999
23
        })['results'].each do |organization|
24
          next if option_organization && organization['name'] != option_organization
25
          @api.resource(:products).call(:index, {
26
              'per_page' => 999999,
27
              'enabled' => true,
28
              'organization_id' => organization['id']
29
          })['results'].each do |product|
30
            @api.resource(:repositories).call(:index, {
31
                'product_id' => product['id'],
29 32
                'organization_id' => organization['id']
30
            })['results'].each do |product|
31
              @api.resource(:repositories).call(:index, {
32
                  'product_id' => product['id'],
33
                  'organization_id' => organization['id']
34
              })['results'].each do |repository|
35
                repository = @api.resource(:repositories).call(:show, {:id => repository['id']})
36
                if repository['product_type'] == 'custom'
37
                  repository_type = "Custom #{repository['content_type'].capitalize}"
38
                  content_set = nil
39
                else
40
                  repository_type = "Red Hat #{repository['content_type'].capitalize}"
41
                  content_set = get_content_set(organization, product, repository)
42
                end
43
                release = repository['minor'] #=~ /Server/ ? repository['minor'] : "#{repository['major']}.#{repository['minor']}"
44
                csv << [product['name'], product['label'], organization['name'],
45
                        product['description'], repository['name'], repository_type,
46
                        content_set, release, repository['url']]
33
            })['results'].each do |repository|
34
              repository = @api.resource(:repositories).call(:show, {:id => repository['id']})
35
              if repository['product_type'] == 'custom'
36
                repository_type = "Custom #{repository['content_type'].capitalize}"
37
                content_set = nil
38
              else
39
                repository_type = "Red Hat #{repository['content_type'].capitalize}"
40
                content_set = get_content_set(organization, product, repository)
47 41
              end
42
              release = repository['minor'] #=~ /Server/ ? repository['minor'] : "#{repository['major']}.#{repository['minor']}"
43
              csv << [product['name'], product['label'], organization['name'],
44
                      product['description'], repository['name'], repository_type,
45
                      content_set, release, repository['url']]
48 46
            end
49 47
          end
50 48
        end

Also available in: Unified diff