class Zypper::Upgraderepo::RepositoryList

Constants

REPOSITORY_PATH

Attributes

list[R]
max_col[R]

Public Class Methods

new(options) click to toggle source
# 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 = []

  Dir.glob(File.join(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

  load_overrides(options.filename) if options.filename
end

Public Instance Methods

each_with_number(options = {}) { |x, x| ... } click to toggle source
# File lib/zypper/upgraderepo/repository.rb, line 48
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?() click to toggle source
# File lib/zypper/upgraderepo/repository.rb, line 37
def only_enabled?
  @only_enabled
end
resolve_variables!(version) click to toggle source
# File lib/zypper/upgraderepo/repository.rb, line 64
def resolve_variables!(version)
  each_with_number do |r|
    if r.url =~ /\$/
      r.url = r.url.gsub(/\$releasever_major/, version.split('.')[0])
                   .gsub(/\$releasever_minor/, version.split('.')[1])
                   .gsub(/\$releasever/, version)
    end
  end

  self
end
save() click to toggle source
# File lib/zypper/upgraderepo/repository.rb, line 76
def save
  @list.each do |i|
    i.save
  end
end
upgrade!(version) click to toggle source
# File lib/zypper/upgraderepo/repository.rb, line 41
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

Private Instance Methods

load_overrides(filename) click to toggle source
# File lib/zypper/upgraderepo/repository.rb, line 85
def load_overrides(filename)
  raise FileNotFound, filename unless File.exist?(filename)
  ini = IniParse.parse(File.read(filename))
  each_with_number(only_invalid: false) do |repo, num|
    if x = ini["repository_#{num}"]
      repo.enable!(x['enabled'])
      raise UnmatchingOverrides, { num: num, ini: x, repo: repo } if repo.url != x['old_url']
      if (@repos.only_enabled?)
        raise MissingOverride, { num: num, ini: x } unless x['url'] || x['enabled'] =~ /no|false|0/i
      else
        raise MissingOverride, { num: num, ini: x } unless x['url']
      end
      @overrides[num] = x['url'] if x['url']
    end
  end
end