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/content_view_filters.rb
14 14
      REPOSITORIES = 'Repositories'
15 15
      RULES = 'Rules'
16 16

  
17
      def export
18
        CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
19
          csv << [NAME, CONTENTVIEW, ORGANIZATION, TYPE, DESCRIPTION, REPOSITORIES, RULES]
20
          @api.resource(:organizations).call(:index, {
21
              :per_page => 999999
22
          })['results'].each do |organization|
23
            next if option_organization && organization['name'] != option_organization
24

  
25
            @api.resource(:content_views).call(:index, {
26
                'per_page' => 999999,
27
                'organization_id' => organization['id'],
28
                'nondefault' => true
29
            })['results'].each do |contentview|
30
              @api.resource(:content_view_filters).call(:index, {
31
                  'content_view_id' => contentview['id']
32
              })['results'].collect do |filter|
33
                filter_type = "#{filter['inclusion'] == true ? 'Include' : 'Exclude'} #{export_filter_type(filter['type'])}"
34

  
35
                rules = nil
36
                case filter['type']
37
                when /rpm/
38
                  rules = export_rpm_rules(filter)
39
                when /erratum/
40
                  rules = export_erratum_rules(filter)
41
                when /package_group/
42
                  rules = export_package_group_rules(filter)
43
                else
44
                  raise "Unknown filter rule type '#{filter['type']}'"
45
                end
46

  
47
                name = filter['name']
48
                repositories = export_column(filter, 'repositories', 'name')
49
                csv << [name, contentview['name'], organization['name'], filter_type, filter['description'],
50
                        repositories, rules]
17
      def export(csv)
18
        csv << [NAME, CONTENTVIEW, ORGANIZATION, TYPE, DESCRIPTION, REPOSITORIES, RULES]
19
        @api.resource(:organizations).call(:index, {
20
            :per_page => 999999
21
        })['results'].each do |organization|
22
          next if option_organization && organization['name'] != option_organization
23

  
24
          @api.resource(:content_views).call(:index, {
25
              'per_page' => 999999,
26
              'organization_id' => organization['id'],
27
              'nondefault' => true
28
          })['results'].each do |contentview|
29
            @api.resource(:content_view_filters).call(:index, {
30
                'content_view_id' => contentview['id']
31
            })['results'].collect do |filter|
32
              filter_type = "#{filter['inclusion'] == true ? 'Include' : 'Exclude'} #{export_filter_type(filter['type'])}"
33

  
34
              rules = nil
35
              case filter['type']
36
              when /rpm/
37
                rules = export_rpm_rules(filter)
38
              when /erratum/
39
                rules = export_erratum_rules(filter)
40
              when /package_group/
41
                rules = export_package_group_rules(filter)
42
              else
43
                raise "Unknown filter rule type '#{filter['type']}'"
51 44
              end
45

  
46
              name = filter['name']
47
              repositories = export_column(filter, 'repositories', 'name')
48
              csv << [name, contentview['name'], organization['name'], filter_type, filter['description'],
49
                      repositories, rules]
52 50
            end
53 51
          end
54 52
        end

Also available in: Unified diff