Class: Zypper::Upgraderepo::RepositoryList

Inherits:
Object
  • Object
show all
Defined in:
lib/zypper/upgraderepo/repository.rb

Constant Summary collapse

REPOSITORY_PATH =
'/etc/zypp/repos.d'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ RepositoryList

Returns a new instance of RepositoryList.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/zypper/upgraderepo/repository.rb', line 13

def initialize(options)
  @alias = options.alias
  @name = options.name
  @only_repo = options.only_repo
  @only_enabled = options.only_enabled
  @only_invalid = options.only_invalid
  @only_protocols = options.only_protocols
  @overrides = options.overrides
  @upgrade_options = {alias: options.alias, name: options.name}
  @list = []
  @cpu_arch, @arch = `rpm --eval "%cpu_arch;%_arch"`.tr("\n", '').split(';')

  Dir.glob(File.join(self.class::REPOSITORY_PATH, '*.repo')).each do |i|
    r = Request.build(Repository.new(i), options.timeout)
    @list << r
  end
  @max_col = @list.max_by { |r| r.name.length }.name.length

  @list = @list.sort_by { |r| r.alias }.map.with_index(1) { |r, i| { num: i, repo: r } }

  @list.sort_by! { |x| x[:repo].send(options.sort_by) } if options.sort_by != :alias

  @only_repo = select_repos(@only_repo) unless @only_repo.nil?

  load_overrides(options.overrides_filename) if options.overrides_filename
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



11
12
13
# File 'lib/zypper/upgraderepo/repository.rb', line 11

def list
  @list
end

#max_colObject (readonly)

Returns the value of attribute max_col.



11
12
13
# File 'lib/zypper/upgraderepo/repository.rb', line 11

def max_col
  @max_col
end

Instance Method Details

#each_with_number(options = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/zypper/upgraderepo/repository.rb', line 51

def each_with_number(options = {})
  only_repo = options[:only_repo].nil? ? @only_repo : options[:only_repo]
  only_enabled = options[:only_enabled].nil? ? @only_enabled : options[:only_enabled]
  only_invalid = options[:only_invalid].nil? ? @only_invalid : options[:only_invalid]
  only_protocols = options[:only_protocols].nil? ? @only_protocols : options[:only_protocols]

  @list.each do |x|
    next if only_repo && !only_repo.include?(x[:num])
    next if only_enabled && !x[:repo].enabled?
    next if only_invalid && x[:repo].available?
    next if only_protocols && (!only_protocols.include?(x[:repo].protocol))

    yield x[:repo], x[:num] if block_given?
  end
end

#only_enabled?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/zypper/upgraderepo/repository.rb', line 40

def only_enabled?
  @only_enabled
end

#resolve_variables!(version) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/zypper/upgraderepo/repository.rb', line 67

def resolve_variables!(version)
  each_with_number do |r|
    if r.url =~ /\$/
      r.url = expand_variables(r.url, version)
    end
    r.name = expand_variables(r.name, version)
    r.alias = expand_variables(r.alias, version)
  end

  self
end

#saveObject



79
80
81
82
83
# File 'lib/zypper/upgraderepo/repository.rb', line 79

def save
  @list.each do |i|
    i[:repo].save
  end
end

#upgrade!(version) ⇒ Object



44
45
46
47
48
49
# File 'lib/zypper/upgraderepo/repository.rb', line 44

def upgrade!(version)
  each_with_number(only_invalid: false) do |repo, num|
    repo.upgrade! version, @upgrade_options.merge(url_override: @overrides[num])
    repo.cache!
  end
end