Class: Zypper::Upgraderepo::RepositoryList
- Inherits:
-
Object
- Object
- Zypper::Upgraderepo::RepositoryList
- Defined in:
- lib/zypper/upgraderepo/repository.rb
Instance Attribute Summary collapse
-
#list ⇒ Object
readonly
Returns the value of attribute list.
-
#max_col ⇒ Object
readonly
Returns the value of attribute max_col.
Instance Method Summary collapse
- #backup ⇒ Object
-
#initialize(options) ⇒ RepositoryList
constructor
A new instance of RepositoryList.
- #save ⇒ Object
- #upgrade(version) ⇒ Object
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() @alias = .alias @name = .name @overrides = .overrides @list = [] @backup_path = .backup_path Dir.glob('/etc/zypp/repos.d/*.repo').each do |i| r = Repository.new(i) next if .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(.sort_by) } if .sort_by != :alias end |
Instance Attribute Details
#list ⇒ Object (readonly)
Returns the value of attribute list.
11 12 13 |
# File 'lib/zypper/upgraderepo/repository.rb', line 11 def list @list end |
#max_col ⇒ Object (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
#backup ⇒ Object
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 |
#save ⇒ Object
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 |