Class: Zypper::Upgraderepo::Builder
- Inherits:
-
Object
- Object
- Zypper::Upgraderepo::Builder
- Defined in:
- lib/zypper/upgraderepo.rb
Overview
Facade class for all the operations.
Instance Method Summary collapse
- #backup ⇒ Object
- #check_current ⇒ Object
- #check_for ⇒ Object
- #check_last ⇒ Object
- #check_next ⇒ Object
- #duplicates ⇒ Object
-
#initialize(options) ⇒ Builder
constructor
A new instance of Builder.
- #reset ⇒ Object
- #status ⇒ Object
- #unused ⇒ Object
- #update ⇒ Object
- #upgrade_to ⇒ Object
- #upgrade_to_last ⇒ Object
- #upgrade_to_next ⇒ Object
Constructor Details
#initialize(options) ⇒ Builder
Returns a new instance of Builder.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/zypper/upgraderepo.rb', line 17 def initialize() @os_release = OsRelease.new() @repos = RepositoryList.new(, RepositoryVariables.new(@os_release.current)) @print_hint = .hint @view_class = Zypper::Upgraderepo::View.const_get .view.to_s.capitalize @backup_path = .backup_path @exit_on_fail = .exit_on_fail end |
Instance Method Details
#backup ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/zypper/upgraderepo.rb', line 28 def backup filename = File.join(@backup_path, "repos-backup-#{Time.now.to_s.delete(": +-")[0..-5]}.tgz") raise InvalidWritePermissions, filename unless File.writable? @backup_path Minitar.pack(RepositoryList::REPOSITORY_PATH, Zlib::GzipWriter.new(File.open(filename, "wb"))) Messages.ok "Backup file generated at #{filename.bold.green}" end |
#check_current ⇒ Object
38 39 40 41 |
# File 'lib/zypper/upgraderepo.rb', line 38 def check_current @repos.upgrade!(@os_release.current) check_repos(@os_release.current) end |
#check_for ⇒ Object
50 51 52 53 |
# File 'lib/zypper/upgraderepo.rb', line 50 def check_for @repos.upgrade!(@os_release.custom) check_repos(@os_release.custom) end |
#check_last ⇒ Object
55 56 57 58 59 60 |
# File 'lib/zypper/upgraderepo.rb', line 55 def check_last raise AlreadyUpgraded, "latest" if @os_release.last? @repos.upgrade!(@os_release.last) check_repos(@os_release.last) end |
#check_next ⇒ Object
43 44 45 46 47 48 |
# File 'lib/zypper/upgraderepo.rb', line 43 def check_next raise AlreadyUpgraded, "latest" if @os_release.last? @repos.upgrade!(@os_release.next) check_repos(@os_release.next) end |
#duplicates ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/zypper/upgraderepo.rb', line 62 def duplicates dups = {} dcount = 0 @view_class.duplicates_header(@repos.max_col) @view_class.separator(@repos.max_col, "=", :yellow) @repos.each_with_number do |repo, num| uri = URI.parse(repo.url) hostname = uri.hostname.split(".")[-2..-1].join(".") idx = URI::HTTP.build(path: uri.path, host: hostname).to_s.gsub(%r{^http://}, "").gsub(%r{/$}, "") dups[idx] ||= [] dups[idx] << { num: num, repo: repo } end dups.each do |_key, list| next if list.count < 2 dcount += list.count.pred list.each_with_index do |l, i| @view_class.duplicates_item(l[:num], i.next, list.count, l[:repo], @repos.max_col) @view_class.separator(@repos.max_col) unless i == list.count.pred end @view_class.separator(@repos.max_col, "=", :yellow) end @view_class.(dcount, @repos.list.count) end |
#reset ⇒ Object
123 124 125 |
# File 'lib/zypper/upgraderepo.rb', line 123 def reset upgrade_repos(@os_release.current) end |
#status ⇒ Object
127 128 129 |
# File 'lib/zypper/upgraderepo.rb', line 127 def status @view_class.status(@os_release) end |
#unused ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/zypper/upgraderepo.rb', line 87 def unused ucount = 0 @view_class.unused_header(@repos.max_col) @view_class.separator(@repos.max_col) @repos.each_with_number do |repo, num| packs = `zypper -q pa -i -r #{num} 2>/dev/null|grep "^i"|wc -l`.strip.to_i next unless packs.zero? ucount += 1 @view_class.unused_item(num, ucount, repo, @repos.max_col) @view_class.separator(@repos.max_col) end @view_class.(ucount, @repos.list.count) end |
#update ⇒ Object
131 132 133 134 |
# File 'lib/zypper/upgraderepo.rb', line 131 def update @repos.upgrade!(@os_release.current) upgrade_repos(@os_release.current) end |
#upgrade_to ⇒ Object
109 110 111 112 113 114 |
# File 'lib/zypper/upgraderepo.rb', line 109 def upgrade_to raise AlreadyUpgraded, @os_release.custom if @os_release.current?(@os_release.custom) @repos.upgrade!(@os_release.custom) upgrade_repos(@os_release.custom) end |
#upgrade_to_last ⇒ Object
116 117 118 119 120 121 |
# File 'lib/zypper/upgraderepo.rb', line 116 def upgrade_to_last raise AlreadyUpgraded, "latest" if @os_release.last? @repos.upgrade!(@os_release.last) upgrade_repos(@os_release.last) end |
#upgrade_to_next ⇒ Object
102 103 104 105 106 107 |
# File 'lib/zypper/upgraderepo.rb', line 102 def upgrade_to_next raise AlreadyUpgraded, "latest" if @os_release.last? @repos.upgrade!(@os_release.next) upgrade_repos(@os_release.next) end |