Class: Zypper::Upgraderepo::RepositoryList

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

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
# File 'lib/zypper/upgraderepo/repository.rb', line 13

def initialize(options)
  @alias = options.alias
  @name = options.name
  @overrides = options.overrides
  @list = []
  @backup_path = options.backup_path

  Dir.glob('/etc/zypp/repos.d/*.repo').each do |i|
    r = Repository.new(i)
    next if options.only_enabled && (!r.enabled?)
    @list << r
  end
  @max_col = @list.max_by { |x| x.name.length }.name.length

  @list.sort_by! { |x| x.alias }
  @list.sort_by! { |x| x.send(options.sort_by) } if options.sort_by != :alias
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

#backupObject

Raises:



31
32
33
34
35
36
# File 'lib/zypper/upgraderepo/repository.rb', line 31

def backup
  filename = File.join(@backup_path, "repos-backup-#{Time.now.to_s.delete(': +-')[0..-5]}.tgz")
  raise InvalidPermissions, filename unless File.writable? @backup_path
  Minitar.pack('/etc/zypp/repos.d',
               Zlib::GzipWriter.new(File.open(filename, 'wb'))) 
end

#saveObject



50
51
52
53
54
# File 'lib/zypper/upgraderepo/repository.rb', line 50

def save
  @list.each do |i|
    i.save
  end
end

#upgrade(version) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/zypper/upgraderepo/repository.rb', line 38

def upgrade(version)
  @list.each_with_index do |repo, i|
    if @overrides.has_key? i.next.to_s
      repo.url = @overrides[i.next.to_s]
    else
      repo.url = repo.url.gsub(/\d\d\.\d/, version)
    end
    repo.alias = repo.alias.gsub(/\d\d\.\d/, version) if @alias
    repo.name = repo.name.gsub(/\d\d\.\d/, version) if @name
  end
end