zypper-upgraderepo 1.11.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e642faca5400e4b8ed243726b9349740a1211207245d9cc9e72ee391bc12a71d
4
- data.tar.gz: f4d8995a91cc4149db25129004e682afba03ffded92f4d812f980e2460bc839c
3
+ metadata.gz: e33496c6f52e625ef76cdb05a0428921a5b382398a081d8c2e180d2d6954f11c
4
+ data.tar.gz: 1c2b1ec8862bc2d7e601ee7f81d69ccc0f40a57e5de7b9c2650ae375147cfb40
5
5
  SHA512:
6
- metadata.gz: 2d1e4c172bb8ce5cced6fd2fbfc932274b669aec69881d9b6069c9eefe308fd75b4ea78ecf385a8bb22550fbc7a4f1806b586e7ff8272d599f5f3a5cfebd0d86
7
- data.tar.gz: c8d2563ba33b03e6417ad91f15a7f911c4f8438aad414b9558b859a821a4d88cfb9af4c2903c94e3bf2385c972ae872495449c763e2f0bbb745a485d5fba45ba
6
+ metadata.gz: 1a99ec07a90c68575998a9fdefe6b7dca5faa3fcf60ccd9c3f48b5897a05917f37ff7dfdbb32af2f5ff700bf2036656ee5850d56894837c410002ddc44bf0ce0
7
+ data.tar.gz: a958c51806aa971129fb1da35fb693dd3438254831ed7894c745344941146ff83c5d858882c8c09e6c12f521f636ba7879d9f26da54eb0fc80e8a83f356b09ee
data/.rubocop.yml CHANGED
@@ -1,11 +1,12 @@
1
+ # plugins:
2
+ # - rubocop-rake
3
+ # - rubocop-rspec
4
+
1
5
  AllCops:
2
6
  TargetRubyVersion: 2.5
3
7
  NewCops: enable
4
8
  SuggestExtensions: false
5
9
 
6
- Style/ClassVars:
7
- Enabled: false
8
-
9
10
  Style/StringLiterals:
10
11
  Enabled: true
11
12
  EnforcedStyle: double_quotes
@@ -17,50 +18,33 @@ Style/StringLiteralsInInterpolation:
17
18
  Layout/LineLength:
18
19
  Max: 120
19
20
 
20
- Naming/FileName:
21
- Enabled: false
22
-
23
21
  Metrics/MethodLength:
24
- Enabled: false
22
+ Exclude:
23
+ - './lib/**/view.rb'
24
+ - './lib/**/cli.rb'
25
+ - './lib/**/traversable.rb'
25
26
 
26
27
  Metrics/AbcSize:
27
- Enabled: false
28
-
29
- Lint/DuplicateBranch:
30
- Enabled: false
28
+ Exclude:
29
+ - './lib/**/view.rb'
30
+ - './lib/**/traversable.rb'
31
+ - './lib/**/cli.rb'
31
32
 
32
33
  Metrics/ClassLength:
33
- Enabled: true
34
34
  Exclude:
35
- - './lib/**/cli.rb'
36
- - './lib/**/repository.rb'
37
- - './lib/**/upgraderepo.rb'
35
+ - './lib/**/cli.rb'
36
+ - './lib/**/upgraderepo.rb'
38
37
 
39
38
  Metrics/BlockLength:
40
- Enabled: true
41
39
  Exclude:
42
- - '*.gemspec'
43
- - './lib/**/cli.rb'
44
- - './lib/**/repository.rb'
45
- - './spec/**/*'
40
+ - './lib/**/cli.rb'
46
41
 
47
42
  Metrics/PerceivedComplexity:
48
- Enabled: true
49
43
  Exclude:
50
- - './lib/**/upgraderepo.rb'
51
- - './lib/**/repository.rb'
52
- - './lib/**/view.rb'
53
- - './lib/**/traversable.rb'
44
+ - './lib/**/view.rb'
45
+ - './lib/**/traversable.rb'
54
46
 
55
47
  Metrics/CyclomaticComplexity:
56
- Enabled: true
57
- Exclude:
58
- - './lib/**/upgraderepo.rb'
59
- - './lib/**/repository.rb'
60
- - './lib/**/view.rb'
61
- - './lib/**/traversable.rb'
62
-
63
- Style/MixinUsage:
64
- Enabled: true
65
48
  Exclude:
66
- - './spec/**/*'
49
+ - './lib/**/view.rb'
50
+ - './lib/**/traversable.rb'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zypper-upgraderepo (1.11.0)
4
+ zypper-upgraderepo (1.12.0)
5
5
  iniparse
6
6
  minitar
7
7
 
@@ -11,33 +11,33 @@ GEM
11
11
  ast (2.4.3)
12
12
  diff-lcs (1.6.2)
13
13
  iniparse (1.5.0)
14
- json (2.12.2)
14
+ json (2.18.0)
15
15
  language_server-protocol (3.17.0.5)
16
16
  lint_roller (1.1.0)
17
- minitar (0.12.1)
17
+ minitar (1.1.0)
18
18
  parallel (1.27.0)
19
- parser (3.3.8.0)
19
+ parser (3.3.10.0)
20
20
  ast (~> 2.4.1)
21
21
  racc
22
- prism (1.4.0)
22
+ prism (1.6.0)
23
23
  racc (1.8.1)
24
24
  rainbow (3.1.1)
25
- rake (13.3.0)
26
- regexp_parser (2.10.0)
27
- rspec (3.13.1)
25
+ rake (13.3.1)
26
+ regexp_parser (2.11.3)
27
+ rspec (3.13.2)
28
28
  rspec-core (~> 3.13.0)
29
29
  rspec-expectations (~> 3.13.0)
30
30
  rspec-mocks (~> 3.13.0)
31
- rspec-core (3.13.4)
31
+ rspec-core (3.13.6)
32
32
  rspec-support (~> 3.13.0)
33
33
  rspec-expectations (3.13.5)
34
34
  diff-lcs (>= 1.2.0, < 2.0)
35
35
  rspec-support (~> 3.13.0)
36
- rspec-mocks (3.13.5)
36
+ rspec-mocks (3.13.7)
37
37
  diff-lcs (>= 1.2.0, < 2.0)
38
38
  rspec-support (~> 3.13.0)
39
- rspec-support (3.13.4)
40
- rubocop (1.76.0)
39
+ rspec-support (3.13.6)
40
+ rubocop (1.82.0)
41
41
  json (~> 2.3)
42
42
  language_server-protocol (~> 3.17.0.2)
43
43
  lint_roller (~> 1.1.0)
@@ -45,16 +45,16 @@ GEM
45
45
  parser (>= 3.3.0.2)
46
46
  rainbow (>= 2.2.2, < 4.0)
47
47
  regexp_parser (>= 2.9.3, < 3.0)
48
- rubocop-ast (>= 1.45.0, < 2.0)
48
+ rubocop-ast (>= 1.48.0, < 2.0)
49
49
  ruby-progressbar (~> 1.7)
50
50
  unicode-display_width (>= 2.4.0, < 4.0)
51
- rubocop-ast (1.45.0)
51
+ rubocop-ast (1.48.0)
52
52
  parser (>= 3.3.7.2)
53
53
  prism (~> 1.4)
54
54
  rubocop-capybara (2.22.1)
55
55
  lint_roller (~> 1.1)
56
56
  rubocop (~> 1.72, >= 1.72.1)
57
- rubocop-factory_bot (2.27.1)
57
+ rubocop-factory_bot (2.28.0)
58
58
  lint_roller (~> 1.1)
59
59
  rubocop (~> 1.72, >= 1.72.1)
60
60
  rubocop-rake (0.6.0)
@@ -67,12 +67,12 @@ GEM
67
67
  rubocop-rspec_rails (2.29.1)
68
68
  rubocop (~> 1.61)
69
69
  ruby-progressbar (1.13.0)
70
- unicode-display_width (3.1.4)
71
- unicode-emoji (~> 4.0, >= 4.0.4)
72
- unicode-emoji (4.0.4)
70
+ unicode-display_width (3.2.0)
71
+ unicode-emoji (~> 4.1)
72
+ unicode-emoji (4.2.0)
73
73
 
74
74
  PLATFORMS
75
- ruby
75
+ x86_64-linux-gnu
76
76
 
77
77
  DEPENDENCIES
78
78
  bundler (~> 2.0)
@@ -84,4 +84,4 @@ DEPENDENCIES
84
84
  zypper-upgraderepo!
85
85
 
86
86
  BUNDLED WITH
87
- 2.4.3
87
+ 2.4.22
@@ -10,14 +10,14 @@ module Zypper
10
10
  :operation, :backup_path, :only_enabled, :alias, :name, :hint,
11
11
  :overrides, :version, :sorting_by, :view, :only_repo, :timeout,
12
12
  :exit_on_fail, :overrides_filename, :only_invalid, :only_protocols,
13
- :allow_unstable
13
+ :allow_unstable, :only_used
14
14
  )
15
15
 
16
16
  #
17
17
  # Parsing the input data.
18
18
  #
19
19
  class OptParseMain
20
- def self.parse(_args)
20
+ def self.parse(args)
21
21
  options = CliOptions.new
22
22
  options.operation = :check_current
23
23
  options.backup_path = Dir.home
@@ -36,6 +36,7 @@ module Zypper
36
36
  options.only_invalid = false
37
37
  options.only_protocols = nil
38
38
  options.allow_unstable = false
39
+ options.only_used = nil
39
40
 
40
41
  opt_parser = OptionParser.new do |opt|
41
42
  opt.banner = if ENV["ZYPPER_UPGRADEREPO"]
@@ -148,7 +149,7 @@ module Zypper
148
149
 
149
150
  opt.on("--only-repo <NUMBER|NAME|@ALIAS|#URL|&ANY>[,NUMBER2|NAME2|@ALIAS2|#URL2|&ANY2,...]",
150
151
  "Include only the repositories specified by a NUMBER or a string matching the NAME, " \
151
- "@ALIAS, #URL, or &ANY of them") do |o|
152
+ "@ALIAS, #URL, or ?ANY of them") do |o|
152
153
  options.only_repo = o.split(",")
153
154
  end
154
155
 
@@ -161,6 +162,10 @@ module Zypper
161
162
  options.only_protocols = o
162
163
  end
163
164
 
165
+ opt.on("--only-used", "Show only used repositories") do |_o|
166
+ options.only_used = true
167
+ end
168
+
164
169
  opt.separator ""
165
170
  opt.separator "View options:"
166
171
 
@@ -208,11 +213,11 @@ module Zypper
208
213
  end
209
214
  end
210
215
 
211
- if ARGV.empty?
216
+ if args.empty?
212
217
  puts opt_parser
213
218
  exit
214
219
  else
215
- opt_parser.parse!(ARGV)
220
+ opt_parser.parse!(args)
216
221
  end
217
222
 
218
223
  options
@@ -22,21 +22,9 @@ module Zypper
22
22
  "15.0", "15.1", "15.2", "15.3", "15.4", "15.5", "15.6",
23
23
  "16.0"]
24
24
 
25
- if options.allow_unstable
26
- raise NoUnstableVersionAvailable if UNSTABLE_VERSION.empty?
25
+ load_unstable if options.allow_unstable
27
26
 
28
- @os_versions << UNSTABLE_VERSION
29
- @unstable = true
30
- end
31
-
32
- fname = if File.exist? self.class::OS_RELEASE_FILE
33
- self.class::OS_RELEASE_FILE
34
- elsif File.exist? self.class::SUSE_RELEASE_FILE
35
- self.class::SUSE_RELEASE_FILE
36
- else
37
- raise ReleaseFileNotFound
38
- end
39
- @release = IniParse.parse(File.read(fname))
27
+ @release = IniParse.parse(File.read(release_filename))
40
28
  @current_idx = @os_versions.index(@release["__anonymous__"]["VERSION"].delete('"'))
41
29
 
42
30
  return unless options.version
@@ -96,6 +84,40 @@ module Zypper
96
84
  def current?(version)
97
85
  @os_versions.index(version) == @current_idx
98
86
  end
87
+
88
+ def requires_v2?(version)
89
+ if `uname -m` =~ /x86_64/
90
+ @os_versions.index(version) > 11
91
+ else
92
+ false
93
+ end
94
+ end
95
+
96
+ def v2?
97
+ flags = `cat /proc/cpuinfo`.split("\n").grep(/^flags.*:/).first.split
98
+ %w[cx16 lahf_lm popcnt sse4_1 sse4_2 ssse3].reduce(true) do |res, f|
99
+ flags.include?(f) && res
100
+ end
101
+ end
102
+
103
+ private
104
+
105
+ def release_filename
106
+ if File.exist? self.class::OS_RELEASE_FILE
107
+ self.class::OS_RELEASE_FILE
108
+ elsif File.exist? self.class::SUSE_RELEASE_FILE
109
+ self.class::SUSE_RELEASE_FILE
110
+ else
111
+ raise ReleaseFileNotFound
112
+ end
113
+ end
114
+
115
+ def load_unstable
116
+ raise NoUnstableVersionAvailable if UNSTABLE_VERSION.empty?
117
+
118
+ @os_versions << UNSTABLE_VERSION
119
+ @unstable = true
120
+ end
99
121
  end
100
122
  end
101
123
  end
@@ -40,32 +40,22 @@ module Zypper
40
40
  #
41
41
  # Handle the repository collection.
42
42
  #
43
+ # rubocop: disable Metrics/ClassLength
43
44
  class RepositoryList
44
45
  REPOSITORY_PATH = "/etc/zypp/repos.d"
45
46
 
46
47
  attr_reader :list, :max_col
47
48
 
48
49
  def initialize(options, variables)
49
- @alias = options.alias
50
- @name = options.name
51
- @only_repo = options.only_repo
52
- @only_enabled = options.only_enabled
53
- @only_invalid = options.only_invalid
54
- @only_protocols = options.only_protocols
55
- @overrides = options.overrides
56
- @upgrade_options = { alias: options.alias, name: options.name }
57
- @list = []
50
+ initialize_options(options)
58
51
 
59
52
  @variables = variables
60
- Dir.glob(File.join(self.class::REPOSITORY_PATH, "*.repo")).each do |i|
61
- r = Request.build(Repository.new(i, @variables), options.timeout)
62
- @list << r
63
- end
64
- @max_col = @list.max_by { |r| r.name.length }.name.length
65
53
 
66
- @list = @list.sort_by(&:alias).map.with_index(1) { |r, i| { num: i, repo: r } }
54
+ initialize_list(options)
67
55
 
68
- @list.sort_by! { |x| x[:repo].send(options.sorting_by) } if options.sorting_by != :alias
56
+ @max_col = @list.max_by { |r| r.name.length }.name.length
57
+
58
+ sort_list(options)
69
59
 
70
60
  @only_repo = select_repos(@only_repo) unless @only_repo.nil?
71
61
 
@@ -84,16 +74,10 @@ module Zypper
84
74
  end
85
75
 
86
76
  def each_with_number(options = {})
87
- only_repo = options[:only_repo].nil? ? @only_repo : options[:only_repo]
88
- only_enabled = options[:only_enabled].nil? ? @only_enabled : options[:only_enabled]
89
- only_invalid = options[:only_invalid].nil? ? @only_invalid : options[:only_invalid]
90
- only_protocols = options[:only_protocols].nil? ? @only_protocols : options[:only_protocols]
77
+ f_o = filter_options(options)
91
78
 
92
79
  @list.each do |x|
93
- next if only_repo && !only_repo.include?(x[:num])
94
- next if only_enabled && !x[:repo].enabled?
95
- next if only_invalid && x[:repo].available?
96
- next if only_protocols && !only_protocols.include?(x[:repo].protocol)
80
+ next if next_repo? x[:repo], x[:num], f_o
97
81
 
98
82
  yield x[:repo], x[:num] if block_given?
99
83
  end
@@ -105,43 +89,130 @@ module Zypper
105
89
  end
106
90
  end
107
91
 
92
+ def duplicates
93
+ group_for_url.delete_if { |_, v| v.length < 2 }
94
+ end
95
+
108
96
  private
109
97
 
98
+ def initialize_list(options)
99
+ @list = []
100
+ Dir.glob(File.join(self.class::REPOSITORY_PATH, "*.repo")).each do |i|
101
+ r = Request.build(Repository.new(i, @variables), options.timeout)
102
+ @list << r
103
+ end
104
+ end
105
+
106
+ def sort_list(options)
107
+ @list = @list.sort_by(&:alias).map.with_index(1) { |r, i| { num: i, repo: r } }
108
+ @list.sort_by! { |x| x[:repo].send(options.sorting_by) } if options.sorting_by != :alias
109
+ end
110
+
111
+ def initialize_options(options)
112
+ @alias = options.alias
113
+ @name = options.name
114
+ @only_repo = options.only_repo
115
+ @only_enabled = options.only_enabled
116
+ @only_invalid = options.only_invalid
117
+ @only_protocols = options.only_protocols
118
+ @only_used = options.only_used
119
+ @overrides = options.overrides
120
+ @upgrade_options = { alias: options.alias, name: options.name }
121
+ end
122
+
123
+ def filter_options(options)
124
+ {
125
+ only_repo: options[:only_repo].nil? ? @only_repo : options[:only_repo],
126
+ only_enabled: options[:only_enabled].nil? ? @only_enabled : options[:only_enabled],
127
+ only_invalid: options[:only_invalid].nil? ? @only_invalid : options[:only_invalid],
128
+ only_protocols: options[:only_protocols].nil? ? @only_protocols : options[:only_protocols],
129
+ only_used: options[:only_used].nil? ? @only_used : options[:only_used]
130
+ }
131
+ end
132
+
133
+ # rubocop: disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
134
+ def next_repo?(repo, num, options)
135
+ (options[:only_repo] && !options[:only_repo].include?(num)) ||
136
+ (options[:only_enabled] && !repo.enabled?) ||
137
+ (options[:only_invalid] && repo.available?) ||
138
+ (options[:only_protocols] && !options[:only_protocols].include?(repo.protocol)) ||
139
+ (options[:only_used] && repo.unused?)
140
+ end
141
+ # rubocop: enable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
142
+
143
+ def group_for_url
144
+ dups = {}
145
+ each_with_number do |repo, num|
146
+ uri = URI.parse(repo.url)
147
+ hostname = uri.hostname.split(".")[-2..-1].join(".")
148
+ idx = URI::HTTP.build(path: uri.path, host: hostname).to_s.gsub(%r{^http://}, "").gsub(%r{/$}, "")
149
+ dups[idx] ||= []
150
+ dups[idx] << { num: num, repo: repo }
151
+ end
152
+ dups
153
+ end
154
+
155
+ def select_for_name(str)
156
+ regexp = Regexp.new(str.strip, "i")
157
+ @list.select do |x|
158
+ yield x[:repo], x[:num] if x[:repo].name.match?(regexp) && block_given?
159
+ end
160
+ end
161
+
162
+ def select_for_alias(str)
163
+ regexp = Regexp.new(str.gsub("@", "").strip, "i")
164
+ @list.select do |x|
165
+ yield x[:repo], x[:num] if x[:repo].alias.match?(regexp)
166
+ end
167
+ end
168
+
169
+ def select_for_url(str)
170
+ regexp = Regexp.new(str.gsub("#", "").strip, "i")
171
+ @list.select do |x|
172
+ yield x[:repo], x[:num] if x[:repo].url.match?(regexp)
173
+ end
174
+ end
175
+
176
+ def select_for_any(str)
177
+ regexp = Regexp.new(str.gsub("?", "").strip, "i")
178
+ @list.select do |x|
179
+ yield x[:repo], x[:num] if x[:repo].name.match?(regexp) ||
180
+ x[:repo].alias.match?(regexp) ||
181
+ x[:repo].url.match?(regexp)
182
+ end
183
+ end
184
+
185
+ # rubocop: disable Metrics/AbcSize, Metrics/MethodLength
110
186
  def select_repos(repos)
111
187
  res = []
112
188
  repos.each do |r|
113
189
  if r.to_i.positive?
114
190
  res.push r.to_i
115
191
  elsif r =~ /^\ *@.*/
116
- a = r.gsub(/@/, "").strip
117
- @list.select { |x| x[:repo].alias.match?(Regexp.new(a, "i")) }.each do |l|
118
- res.push l[:num]
119
- end
192
+ select_for_alias(r) { |_, num| res.push num }
120
193
  elsif r =~ /^\ *\#.*/
121
- u = r.gsub("#", "").strip
122
- @list.select { |x| x[:repo].url.match?(Regexp.new(u, "i")) }.each do |l|
123
- res.push l[:num]
124
- end
125
- elsif r =~ /^\ *&.*/
126
- s = r.gsub("&", "").strip
127
- sel = @list.select do |x|
128
- x[:repo].alias.match?(Regexp.new(s, "i")) ||
129
- x[:repo].name.match?(Regexp.new(s, "i")) ||
130
- x[:repo].url.match?(Regexp.new(s, "i"))
131
- end
132
- sel.each do |l|
133
- res.push l[:num]
134
- end
194
+ select_for_url(r) { |_, num| res.push num }
195
+ elsif r =~ /^\ *\?.*/
196
+ select_for_any(r) { |_, num| res.push num }
135
197
  else
136
- n = r.strip
137
- @list.select { |x| x[:repo].name.match?(Regexp.new(n, "i")) }.each do |l|
138
- res.push l[:num]
139
- end
198
+ puts r
199
+ select_for_name(r) { |_, num| res.push num }
140
200
  end
141
201
  end
142
202
 
143
203
  res.uniq
144
204
  end
205
+ # rubocop: enable Metrics/AbcSize, Metrics/MethodLength
206
+
207
+ def check_for_override(repo, num, ini)
208
+ raise UnmatchingOverrides, { num: num, ini: ini, repo: repo } if repo.url != ini["old_url"]
209
+
210
+ if only_enabled?
211
+ raise MissingOverride, { num: num, ini: ini } unless ini["url"] || ini["enabled"] =~ /no|false|0/i
212
+ else
213
+ raise MissingOverride, { num: num, ini: ini } unless ini["url"]
214
+ end
215
+ end
145
216
 
146
217
  def load_overrides(filename)
147
218
  raise FileNotFound, filename unless File.exist?(filename)
@@ -151,17 +222,12 @@ module Zypper
151
222
  next unless (x = ini["repository_#{num}"])
152
223
 
153
224
  repo.enable!(x["enabled"])
154
- raise UnmatchingOverrides, { num: num, ini: x, repo: repo } if repo.url != x["old_url"]
155
-
156
- if only_enabled?
157
- raise MissingOverride, { num: num, ini: x } unless x["url"] || x["enabled"] =~ /no|false|0/i
158
- else
159
- raise MissingOverride, { num: num, ini: x } unless x["url"]
160
- end
225
+ check_for_override(repo, num, x)
161
226
  @overrides[num] = x["url"] if x["url"]
162
227
  end
163
228
  end
164
229
  end
230
+ # rubocop: enable Metrics/ClassLength
165
231
 
166
232
  #
167
233
  # Single repository class.
@@ -232,6 +298,7 @@ module Zypper
232
298
  @key = read_key
233
299
  end
234
300
 
301
+ # rubocop: disable Metrics/AbcSize
235
302
  def upgrade!(version, args = {})
236
303
  @old_url ||= url
237
304
  @old_alias ||= self.alias
@@ -242,6 +309,7 @@ module Zypper
242
309
  self.alias = self.alias.gsub(/\d\d\.\d/, version) if args[:alias]
243
310
  self.name = name.gsub(/\d\d\.\d/, version) if args[:name]
244
311
  end
312
+ # rubocop: enable Metrics/AbcSize
245
313
 
246
314
  def upgraded?(item = :url)
247
315
  !send("old_#{item}").nil? && (send("old_#{item}") != send(item))
@@ -256,6 +324,14 @@ module Zypper
256
324
  @repo.save(@filename)
257
325
  end
258
326
 
327
+ def unused?
328
+ `zypper -q pa -i -r "#{name}" 2>/dev/null|grep -c "^i"`.strip.to_i.zero?
329
+ end
330
+
331
+ def used?
332
+ !unused?
333
+ end
334
+
259
335
  private
260
336
 
261
337
  def resolve_variables!(variables)
@@ -12,6 +12,7 @@ module Zypper
12
12
  # achieve the request..
13
13
  #
14
14
  class Request
15
+ # rubocop: disable Style/ClassVars
15
16
  def self.build(repo, timeout)
16
17
  @@registry ||= load_requests
17
18
 
@@ -19,6 +20,7 @@ module Zypper
19
20
 
20
21
  Object.const_get(find_class(repo)).new(repo, timeout)
21
22
  end
23
+ # rubocop: enable Style/ClassVars
22
24
 
23
25
  def self.protocols
24
26
  load_requests.keys
@@ -68,6 +68,7 @@ module Zypper
68
68
  http.request(request)
69
69
  end
70
70
 
71
+ # rubocop: disable Metrics/MethodLength
71
72
  def ping(uri = nil, head: true, cache: true)
72
73
  begin
73
74
  if @page.nil? || uri
@@ -84,6 +85,7 @@ module Zypper
84
85
  end
85
86
  cache ? @page : unpage
86
87
  end
88
+ # rubocop: enable Metrics/MethodLength
87
89
  end
88
90
 
89
91
  module Requests
@@ -111,6 +111,7 @@ module Zypper
111
111
  # Color the error message.
112
112
  #
113
113
  class Messages
114
+ # rubocop: disable Metrics/AbcSize
114
115
  def self.error(err)
115
116
  if err.instance_of?(String)
116
117
  puts " [E] ".bold.red + err
@@ -120,6 +121,7 @@ module Zypper
120
121
  warn "Error! ".bold.red + err.message
121
122
  end
122
123
  end
124
+ # rubocop: enable Metrics/AbcSize
123
125
 
124
126
  def self.ok(msg)
125
127
  puts " [V] ".bold.green + msg
@@ -262,6 +264,7 @@ module Zypper
262
264
 
263
265
  #
264
266
  # No internet connection.
267
+ #
265
268
  class NoConnection < StandardError
266
269
  def initialize
267
270
  super("Internet connection has some trouble")
@@ -272,6 +275,19 @@ module Zypper
272
275
  end
273
276
  end
274
277
 
278
+ #
279
+ # No support for x86_64-v2 instructions.
280
+ #
281
+ class UnsupportedV2 < StandardError
282
+ def initialize
283
+ super("The CPU doesn't support the x86_64-v2 instruction set required by openSUSE 16.0 and sup.")
284
+ end
285
+
286
+ def error_code
287
+ 16
288
+ end
289
+ end
290
+
275
291
  #
276
292
  # Ctrl + C message error.
277
293
  #
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Zypper
4
4
  module Upgraderepo
5
- VERSION = "1.11.0"
5
+ VERSION = "1.12.0"
6
6
  end
7
7
  end
@@ -348,7 +348,6 @@ module Zypper
348
348
  end
349
349
 
350
350
  def self.info(num, status, repo, valid: true, suggested: "")
351
- @@number = num
352
351
  puts "[repository_#{num}]"
353
352
  puts "name=#{repo.name}"
354
353
  puts "alias=#{repo.alias}"
@@ -427,7 +426,6 @@ module Zypper
427
426
  end
428
427
 
429
428
  def self.info(num, status, repo, valid: true, suggested: "")
430
- @@number = num
431
429
  puts "[repository_#{num}]"
432
430
  puts "name=#{repo.name}"
433
431
  puts "alias=#{repo.alias}"
@@ -60,26 +60,12 @@ module Zypper
60
60
  end
61
61
 
62
62
  def duplicates
63
- dups = {}
64
- dcount = 0
65
63
  @view_class.duplicates_header(@repos.max_col)
66
64
  @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_value do |list|
75
- next if list.count < 2
76
-
65
+ dcount = 0
66
+ @repos.duplicates.each_value do |list|
77
67
  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)
68
+ print_duplicates list
83
69
  end
84
70
  @view_class.duplicates_footer(dcount, @repos.list.count)
85
71
  end
@@ -89,8 +75,7 @@ module Zypper
89
75
  @view_class.unused_header(@repos.max_col)
90
76
  @view_class.separator(@repos.max_col)
91
77
  @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?
78
+ next unless repo.unused?
94
79
 
95
80
  ucount += 1
96
81
  @view_class.unused_item(num, ucount, repo, @repos.max_col)
@@ -135,7 +120,38 @@ module Zypper
135
120
 
136
121
  private
137
122
 
123
+ def print_duplicates(list)
124
+ list.each_with_index do |l, i|
125
+ @view_class.duplicates_item(l[:num], i.next, list.count, l[:repo], @repos.max_col)
126
+ @view_class.separator(@repos.max_col) unless i == list.count.pred
127
+ end
128
+ @view_class.separator(@repos.max_col, "=", :yellow)
129
+ end
130
+
131
+ # rubocop: disable Metrics/AbcSize, Metrics/MethodLength
132
+ def print_checked_repo(num, repo, version)
133
+ if repo.redirected?
134
+ @view_class.redirected num, repo, @repos.max_col, repo.redirected_to
135
+ elsif repo.not_found?
136
+ if @print_hint
137
+ @view_class.alternative num, repo, @repos.max_col, repo.evaluate_alternative(version)
138
+ else
139
+ @view_class.not_found num, repo, @repos.max_col
140
+ end
141
+ elsif repo.forbidden?
142
+ @view_class.forbidden num, repo, @repos.max_col
143
+ elsif repo.timeout?
144
+ @view_class.timeout num, repo, @repos.max_col
145
+ else
146
+ @view_class.server_error num, repo, @repos.max_col
147
+ end
148
+ end
149
+ # rubocop: enable Metrics/AbcSize, Metrics/MethodLength
150
+
151
+ # rubocop: disable Metrics/MethodLength
138
152
  def check_repos(version)
153
+ check_requirements(version)
154
+
139
155
  @view_class.header(@repos.max_col)
140
156
 
141
157
  @repos.each_with_number do |repo, num|
@@ -146,28 +162,17 @@ module Zypper
146
162
  else
147
163
  raise UnableToUpgrade, { num: num, repo: repo } if @exit_on_fail
148
164
 
149
- if repo.redirected?
150
- @view_class.redirected num, repo, @repos.max_col, repo.redirected_to
151
- elsif repo.not_found?
152
- if @print_hint
153
- @view_class.alternative num, repo, @repos.max_col, repo.evaluate_alternative(version)
154
- else
155
- @view_class.not_found num, repo, @repos.max_col
156
- end
157
- elsif repo.forbidden?
158
- @view_class.forbidden num, repo, @repos.max_col
159
- elsif repo.timeout?
160
- @view_class.timeout num, repo, @repos.max_col
161
- else
162
- @view_class.server_error num, repo, @repos.max_col
163
- end
165
+ print_checked_repo num, repo, version
164
166
  end
165
167
  end
166
-
167
168
  @view_class.footer @repos.max_col
168
169
  end
170
+ # rubocop: enable Metrics/MethodLength
171
+
172
+ # rubocop: disable Metrics/MethodLength
173
+ def upgrade_repos(version)
174
+ check_requirements(version)
169
175
 
170
- def upgrade_repos(_version)
171
176
  @view_class.header(@repos.max_col, upgrade: true)
172
177
 
173
178
  @repos.each_with_number do |repo, num|
@@ -185,6 +190,13 @@ module Zypper
185
190
  @repos.save
186
191
  Messages.ok "Repositories upgraded!"
187
192
  end
193
+ # rubocop: enable Metrics/MethodLength
194
+
195
+ def check_requirements(version)
196
+ return unless @os_release.requires_v2?(version)
197
+
198
+ raise UnsupportedV2 unless @os_release.v2?
199
+ end
188
200
  end
189
201
  end
190
202
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zypper-upgraderepo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Mucciante
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-11-11 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: iniparse
@@ -78,7 +77,6 @@ metadata:
78
77
  changelog_uri: https://freeaptitude.altervista.org/projects/zypper-upgraderepo.html#changelog
79
78
  wiki_uri: https://github.com/fabiomux/zypper-upgraderepo/wiki
80
79
  rubygems_mfa_required: 'true'
81
- post_install_message:
82
80
  rdoc_options: []
83
81
  require_paths:
84
82
  - lib
@@ -93,8 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
91
  - !ruby/object:Gem::Version
94
92
  version: '0'
95
93
  requirements: []
96
- rubygems_version: 3.1.6
97
- signing_key:
94
+ rubygems_version: 3.6.7
98
95
  specification_version: 4
99
96
  summary: Zypper addon to check and upgrade local repositories.
100
97
  test_files: []