zypper-upgraderepo 1.8.1 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,22 @@
1
- require 'zypper/upgraderepo/repository'
2
- require 'zypper/upgraderepo/request'
3
- require 'zypper/upgraderepo/os_release'
4
- require 'zypper/upgraderepo/utils'
5
- require 'zypper/upgraderepo/view'
6
- require 'zlib'
7
- require 'minitar'
1
+ # frozen_string_literal: true
8
2
 
3
+ require "zypper/upgraderepo/repository"
4
+ require "zypper/upgraderepo/request"
5
+ require "zypper/upgraderepo/os_release"
6
+ require "zypper/upgraderepo/utils"
7
+ require "zypper/upgraderepo/view"
8
+ require "zlib"
9
+ require "minitar"
9
10
 
10
11
  module Zypper
11
12
  module Upgraderepo
12
-
13
+ #
14
+ # Facade class for all the operations.
15
+ #
13
16
  class Builder
14
17
  def initialize(options)
15
18
  @os_release = OsRelease.new(options)
16
- @repos = RepositoryList.new(options).resolve_variables!(@os_release.current)
19
+ @repos = RepositoryList.new(options, RepositoryVariables.new(@os_release.current))
17
20
  @print_hint = options.hint
18
21
  @view_class = Zypper::Upgraderepo::View.const_get options.view.to_s.capitalize
19
22
 
@@ -23,11 +26,11 @@ module Zypper
23
26
  end
24
27
 
25
28
  def backup
26
- filename = File.join(@backup_path, "repos-backup-#{Time.now.to_s.delete(': +-')[0..-5]}.tgz")
29
+ filename = File.join(@backup_path, "repos-backup-#{Time.now.to_s.delete(": +-")[0..-5]}.tgz")
27
30
 
28
31
  raise InvalidWritePermissions, filename unless File.writable? @backup_path
29
32
 
30
- Minitar.pack(RepositoryList::REPOSITORY_PATH, Zlib::GzipWriter.new(File.open(filename, 'wb')))
33
+ Minitar.pack(RepositoryList::REPOSITORY_PATH, Zlib::GzipWriter.new(File.open(filename, "wb")))
31
34
 
32
35
  Messages.ok "Backup file generated at #{filename.bold.green}"
33
36
  end
@@ -38,7 +41,8 @@ module Zypper
38
41
  end
39
42
 
40
43
  def check_next
41
- raise AlreadyUpgraded, 'latest' if @os_release.last?
44
+ raise AlreadyUpgraded, "latest" if @os_release.last?
45
+
42
46
  @repos.upgrade!(@os_release.next)
43
47
  check_repos(@os_release.next)
44
48
  end
@@ -49,25 +53,69 @@ module Zypper
49
53
  end
50
54
 
51
55
  def check_last
52
- raise AlreadyUpgraded, 'latest' if @os_release.last?
56
+ raise AlreadyUpgraded, "latest" if @os_release.last?
57
+
53
58
  @repos.upgrade!(@os_release.last)
54
59
  check_repos(@os_release.last)
55
60
  end
56
61
 
62
+ def duplicates
63
+ dups = {}
64
+ dcount = 0
65
+ @view_class.duplicates_header(@repos.max_col)
66
+ @view_class.separator(@repos.max_col, "=", :yellow)
67
+ @repos.each_with_number do |repo, num|
68
+ uri = URI.parse(repo.url)
69
+ hostname = uri.hostname.split(".")[-2..-1].join(".")
70
+ idx = URI::HTTP.build(path: uri.path, host: hostname).to_s.gsub(%r{^http://}, "").gsub(%r{/$}, "")
71
+ dups[idx] ||= []
72
+ dups[idx] << { num: num, repo: repo }
73
+ end
74
+ dups.each do |_key, list|
75
+ next if list.count < 2
76
+
77
+ dcount += list.count.pred
78
+ list.each_with_index do |l, i|
79
+ @view_class.duplicates_item(l[:num], i.next, list.count, l[:repo], @repos.max_col)
80
+ @view_class.separator(@repos.max_col) unless i == list.count.pred
81
+ end
82
+ @view_class.separator(@repos.max_col, "=", :yellow)
83
+ end
84
+ @view_class.duplicates_footer(dcount, @repos.list.count)
85
+ end
86
+
87
+ def unused
88
+ ucount = 0
89
+ @view_class.unused_header(@repos.max_col)
90
+ @view_class.separator(@repos.max_col)
91
+ @repos.each_with_number do |repo, num|
92
+ packs = `zypper -q pa -i -r #{num} 2>/dev/null|grep "^i"|wc -l`.strip.to_i
93
+ next unless packs.zero?
94
+
95
+ ucount += 1
96
+ @view_class.unused_item(num, ucount, repo, @repos.max_col)
97
+ @view_class.separator(@repos.max_col)
98
+ end
99
+ @view_class.unused_footer(ucount, @repos.list.count)
100
+ end
101
+
57
102
  def upgrade_to_next
58
- raise AlreadyUpgraded, 'latest' if @os_release.last?
103
+ raise AlreadyUpgraded, "latest" if @os_release.last?
104
+
59
105
  @repos.upgrade!(@os_release.next)
60
106
  upgrade_repos(@os_release.next)
61
107
  end
62
108
 
63
109
  def upgrade_to
64
110
  raise AlreadyUpgraded, @os_release.custom if @os_release.current?(@os_release.custom)
111
+
65
112
  @repos.upgrade!(@os_release.custom)
66
113
  upgrade_repos(@os_release.custom)
67
114
  end
68
115
 
69
116
  def upgrade_to_last
70
- raise AlreadyUpgraded, 'latest' if @os_release.last?
117
+ raise AlreadyUpgraded, "latest" if @os_release.last?
118
+
71
119
  @repos.upgrade!(@os_release.last)
72
120
  upgrade_repos(@os_release.last)
73
121
  end
@@ -91,13 +139,13 @@ module Zypper
91
139
  @view_class.header(@repos.max_col)
92
140
 
93
141
  @repos.each_with_number do |repo, num|
94
-
95
- @view_class.separator
142
+ @view_class.separator @repos.max_col
96
143
 
97
144
  if repo.available?
98
145
  @view_class.available num, repo, @repos.max_col
99
146
  else
100
147
  raise UnableToUpgrade, { num: num, repo: repo } if @exit_on_fail
148
+
101
149
  if repo.redirected?
102
150
  @view_class.redirected num, repo, @repos.max_col, repo.redirected_to
103
151
  elsif repo.not_found?
@@ -110,19 +158,20 @@ module Zypper
110
158
  @view_class.forbidden num, repo, @repos.max_col
111
159
  elsif repo.timeout?
112
160
  @view_class.timeout num, repo, @repos.max_col
161
+ else
162
+ @view_class.server_error num, repo, @repos.max_col
113
163
  end
114
164
  end
115
165
  end
116
166
 
117
- @view_class.footer
167
+ @view_class.footer @repos.max_col
118
168
  end
119
169
 
120
- def upgrade_repos(version)
121
- @view_class.header(@repos.max_col, true)
170
+ def upgrade_repos(_version)
171
+ @view_class.header(@repos.max_col, upgrade: true)
122
172
 
123
173
  @repos.each_with_number do |repo, num|
124
-
125
- @view_class.separator
174
+ @view_class.separator @repos.max_col
126
175
 
127
176
  if repo.upgraded?
128
177
  @view_class.upgraded num, repo, @repos.max_col
@@ -131,13 +180,11 @@ module Zypper
131
180
  end
132
181
  end
133
182
 
134
- @view_class.separator
183
+ @view_class.separator @repos.max_col
135
184
 
136
185
  @repos.save
137
- Messages.ok 'Repositories upgraded!'
186
+ Messages.ok "Repositories upgraded!"
138
187
  end
139
-
140
188
  end
141
-
142
189
  end
143
190
  end
@@ -1,40 +1,38 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'zypper/upgraderepo/version'
3
+ require_relative "lib/zypper/upgraderepo/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = 'zypper-upgraderepo'
8
- spec.version = Zypper::Upgraderepo::VERSION
9
- spec.authors = ['Fabio Mucciante']
10
- spec.email = ['fabio.mucciante@gmail.com']
6
+ spec.name = "zypper-upgraderepo"
7
+ spec.version = Zypper::Upgraderepo::VERSION
8
+ spec.authors = ["Fabio Mucciante"]
9
+ spec.email = ["fabio.mucciante@gmail.com"]
11
10
 
12
- spec.summary = %q{Zypper addon to check and upgrade local repositories.}
13
- spec.description = %q{This is just a complement to zypper command which helps to upgrade the local repositories before executing zypper dup.}
14
- spec.homepage = 'https://github.com/fabiomux/zypper-upgraderepo'
15
- spec.license = 'GPL-3.0'
11
+ spec.summary = "Zypper addon to check and upgrade local repositories."
12
+ spec.description = "A complement to the zypper CLI tool to upgrade the repositories before executing zypper dup."
13
+ spec.homepage = "https://github.com/fabiomux/zypper-upgraderepo"
14
+ spec.license = "GPL-3.0"
15
+ spec.required_ruby_version = ">= 2.5.0"
16
16
 
17
- spec.metadata = {
18
- "bug_tracker_uri" => 'https://github.com/fabiomux/zypper-upgraderepo/issues',
19
- "changelog_uri" => 'https://freeaptitude.altervista.org/projects/zypper-upgraderepo.html#changelog',
20
- "documentation_uri" => "https://www.rubydoc.info/gems/zypper-upgraderepo/#{spec.version}",
21
- "homepage_uri" => 'https://freeaptitude.altervista.org/projects/zypper-upgraderepo.html',
22
- #"mailing_list_uri" => '',
23
- "source_code_uri" => 'https://github.com/fabiomux/zypper-upgraderepo',
24
- "wiki_uri" => 'https://github.com/fabiomux/zypper-upgraderepo/wiki'
17
+ spec.metadata = {
18
+ "homepage_uri" => spec.homepage,
19
+ "source_code_uri" => "https://github.com/fabiomux/zypper-upgraderepo",
20
+ "changelog_uri" => "https://freeaptitude.altervista.org/projects/zypper-upgraderepo.html#changelog",
21
+ "wiki_uri" => "https://github.com/fabiomux/zypper-upgraderepo/wiki",
22
+ "rubygems_mfa_required" => "true"
25
23
  }
26
24
 
27
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
26
  f.match(%r{^(test|spec|features|.github)/|(.gitignore|.travis.yml|CODE_OF_CONDUCT.md)$})
29
27
  end
30
- spec.bindir = 'exe'
28
+ spec.bindir = "exe"
31
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
- spec.require_paths = ['lib']
30
+ spec.require_paths = ["lib"]
33
31
 
34
- spec.add_development_dependency 'bundler', '~> 2.0'
35
- spec.add_development_dependency 'rake', '~> 13.0'
36
- spec.add_development_dependency 'rspec', '~> 3.0'
32
+ spec.add_development_dependency "bundler", "~> 2.0"
33
+ spec.add_development_dependency "rake", "~> 13.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
37
35
 
38
- spec.add_runtime_dependency 'iniparse'
39
- spec.add_runtime_dependency 'minitar'
36
+ spec.add_runtime_dependency "iniparse"
37
+ spec.add_runtime_dependency "minitar"
40
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zypper-upgraderepo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Mucciante
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-08 00:00:00.000000000 Z
11
+ date: 2024-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,8 +80,8 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: This is just a complement to zypper command which helps to upgrade the
84
- local repositories before executing zypper dup.
83
+ description: A complement to the zypper CLI tool to upgrade the repositories before
84
+ executing zypper dup.
85
85
  email:
86
86
  - fabio.mucciante@gmail.com
87
87
  executables:
@@ -90,6 +90,7 @@ extensions: []
90
90
  extra_rdoc_files: []
91
91
  files:
92
92
  - ".rspec"
93
+ - ".rubocop.yml"
93
94
  - Gemfile
94
95
  - Gemfile.lock
95
96
  - LICENSE
@@ -114,12 +115,11 @@ homepage: https://github.com/fabiomux/zypper-upgraderepo
114
115
  licenses:
115
116
  - GPL-3.0
116
117
  metadata:
117
- bug_tracker_uri: https://github.com/fabiomux/zypper-upgraderepo/issues
118
- changelog_uri: https://freeaptitude.altervista.org/projects/zypper-upgraderepo.html#changelog
119
- documentation_uri: https://www.rubydoc.info/gems/zypper-upgraderepo/1.8.1
120
- homepage_uri: https://freeaptitude.altervista.org/projects/zypper-upgraderepo.html
118
+ homepage_uri: https://github.com/fabiomux/zypper-upgraderepo
121
119
  source_code_uri: https://github.com/fabiomux/zypper-upgraderepo
120
+ changelog_uri: https://freeaptitude.altervista.org/projects/zypper-upgraderepo.html#changelog
122
121
  wiki_uri: https://github.com/fabiomux/zypper-upgraderepo/wiki
122
+ rubygems_mfa_required: 'true'
123
123
  post_install_message:
124
124
  rdoc_options: []
125
125
  require_paths:
@@ -128,14 +128,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: '0'
131
+ version: 2.5.0
132
132
  required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - ">="
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
137
  requirements: []
138
- rubygems_version: 3.2.3
138
+ rubygems_version: 3.4.3
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: Zypper addon to check and upgrade local repositories.