zypper-upgraderepo 1.9.0 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ceec1a1b9750d49b3c32863595d7b83c615dc140458a65a55dc93b115d5e3f3
4
- data.tar.gz: 857477ddec8c0457e0082583a98a68de4ee62ebca1e4972a578fceb6ba74ca57
3
+ metadata.gz: 32ebc8e9633b6f8316573b56759c1044bd9db702cd4a2289508665420935e054
4
+ data.tar.gz: 89effc0e8a22e7f1019a2ac29337e5882b518f1c0de9dc7844b72cac0fa36608
5
5
  SHA512:
6
- metadata.gz: 490758a8241038010a130c18b97d926744e289d6fe82462647b2d7fe149143e2efbb78dafd1b50cf769cdcde3a3d31099da87743ac77990d4be8aa8017113e4f
7
- data.tar.gz: 51731e28707401f36a825e34d06ecce3753bfd96fa03a14c35997a6113b1c62ddfd142b54df6d27d8f81863afb560964209a42f020e6ff2b693c1f201adc3d90
6
+ metadata.gz: 36dcbddb43e6ec7ede6aace2f03f2ed2be72c0e870c54252cbeec70c0715daf91d88bd3868e9936b3f60d77ced08df655987428fcc13bb15d3fc094913e8ee47
7
+ data.tar.gz: 10bb399234182d2705e9e498891d67c3727a5f4de68ef40166451e3e9dfd4275cb3fe788fa83254917172f18baf7921d5909c7331a659c9d7e4104ed066f6ebf
data/.rubocop.yml CHANGED
@@ -34,6 +34,7 @@ Metrics/ClassLength:
34
34
  Exclude:
35
35
  - './lib/**/cli.rb'
36
36
  - './lib/**/repository.rb'
37
+ - './lib/**/upgraderepo.rb'
37
38
 
38
39
  Metrics/BlockLength:
39
40
  Enabled: true
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zypper-upgraderepo (1.9.0)
4
+ zypper-upgraderepo (1.10.0)
5
5
  iniparse
6
6
  minitar
7
7
 
@@ -95,6 +95,14 @@ module Zypper
95
95
  options.operation = :status
96
96
  end
97
97
 
98
+ opt.on("-d", "--duplicates", "Detect the duplicates comparing the URL addresses") do |_o|
99
+ options.operation = :duplicates
100
+ end
101
+
102
+ opt.on("-z", "--unused", "Prints the unused repositories with zero packages installed") do |_o|
103
+ options.operation = :unused
104
+ end
105
+
98
106
  opt.separator ""
99
107
  opt.separator "Options:"
100
108
 
@@ -110,7 +118,7 @@ module Zypper
110
118
  options.alias = false
111
119
  end
112
120
 
113
- opt.on("--no-hint", "Don't find a working URL when the current is invalid") do |_o|
121
+ opt.on("--no-hint", "Don't find a working URL when the current is not valid") do |_o|
114
122
  options.hint = false
115
123
  end
116
124
 
@@ -118,7 +126,7 @@ module Zypper
118
126
  options.overrides[r[0].to_i] = r[1]
119
127
  end
120
128
 
121
- opt.on("--load-overrides <FILENAME>", "Check the URLs in the exported FILENAME") do |f|
129
+ opt.on("--load-overrides <FILENAME>", "Load the repositories' overrides from FILENAME") do |f|
122
130
  options.overrides_filename = f
123
131
  end
124
132
 
@@ -156,19 +164,19 @@ module Zypper
156
164
  opt.separator ""
157
165
  opt.separator "View options:"
158
166
 
159
- opt.on("--sort-by-alias", "Sort repositories by alias (Default)") do |_o|
167
+ opt.on("--sort-by-alias", "Sort the repositories by alias (Default)") do |_o|
160
168
  options.sorting_by = :alias
161
169
  end
162
170
 
163
- opt.on("--sort-by-name", "Sort repositories by name") do |_o|
171
+ opt.on("--sort-by-name", "Sort the repositories by name") do |_o|
164
172
  options.sorting_by = :name
165
173
  end
166
174
 
167
- opt.on("--sort-by-priority", "Sort repositories by priority") do |_o|
175
+ opt.on("--sort-by-priority", "Sort the repositories by priority") do |_o|
168
176
  options.sorting_by = :priority
169
177
  end
170
178
 
171
- opt.on("--ini", "Output the result as INI format") do |_o|
179
+ opt.on("--ini", "Output the result in the INI format") do |_o|
172
180
  options.view = :ini
173
181
  end
174
182
 
@@ -176,11 +184,11 @@ module Zypper
176
184
  options.view = :quiet
177
185
  end
178
186
 
179
- opt.on("--report", "View the data as report") do |_o|
187
+ opt.on("--report", "View the data as a report") do |_o|
180
188
  options.view = :report
181
189
  end
182
190
 
183
- opt.on("--solved", "Output as INI with the suggestions for the invalid repositories applied") do |_o|
191
+ opt.on("--solved", "Output as INI and the URLs' suggestions applied") do |_o|
184
192
  options.view = :solved
185
193
  end
186
194
 
@@ -193,7 +201,7 @@ module Zypper
193
201
  exit
194
202
  end
195
203
 
196
- opt.on_tail("-v", "--version", "Show version") do |_o|
204
+ opt.on_tail("-v", "--version", "Show the version") do |_o|
197
205
  puts VERSION
198
206
  exit
199
207
  end
@@ -4,6 +4,39 @@ require "iniparse"
4
4
 
5
5
  module Zypper
6
6
  module Upgraderepo
7
+ #
8
+ # Calculate and apply the variables that can be
9
+ # declared within the repository metadata.
10
+ #
11
+ class RepositoryVariables
12
+ VARIABLE_PATH = "/etc/zypp/vars.d"
13
+
14
+ VAR_CPU_ARCH, VAR_ARCH = `rpm --eval "%cpu_arch;%_arch"`.tr("\n", "").split(";")
15
+
16
+ attr_reader :variables
17
+
18
+ def initialize(version)
19
+ @variables = {
20
+ releasever_major: version.split(".")[0],
21
+ releasever_minor: version.split(".")[1],
22
+ releasever: version,
23
+ basearch: VAR_ARCH,
24
+ arch: VAR_CPU_ARCH
25
+ }
26
+
27
+ Dir.glob(File.join(self.class::VARIABLE_PATH, "*")).each do |i|
28
+ @variables[File.basename(i).to_sym] = File.read(i).strip
29
+ end
30
+ end
31
+
32
+ def apply(str)
33
+ str.gsub(/\${?([a-zA-Z0-9_]+)}?/) do
34
+ last = Regexp.last_match(1)
35
+ @variables[last.to_sym] || "<Unknown var: $#{last}>"
36
+ end
37
+ end
38
+ end
39
+
7
40
  #
8
41
  # Handle the repository collection.
9
42
  #
@@ -12,7 +45,7 @@ module Zypper
12
45
 
13
46
  attr_reader :list, :max_col
14
47
 
15
- def initialize(options)
48
+ def initialize(options, variables)
16
49
  @alias = options.alias
17
50
  @name = options.name
18
51
  @only_repo = options.only_repo
@@ -22,10 +55,10 @@ module Zypper
22
55
  @overrides = options.overrides
23
56
  @upgrade_options = { alias: options.alias, name: options.name }
24
57
  @list = []
25
- @cpu_arch, @arch = `rpm --eval "%cpu_arch;%_arch"`.tr("\n", "").split(";")
26
58
 
59
+ @variables = variables
27
60
  Dir.glob(File.join(self.class::REPOSITORY_PATH, "*.repo")).each do |i|
28
- r = Request.build(Repository.new(i), options.timeout)
61
+ r = Request.build(Repository.new(i, @variables), options.timeout)
29
62
  @list << r
30
63
  end
31
64
  @max_col = @list.max_by { |r| r.name.length }.name.length
@@ -66,16 +99,6 @@ module Zypper
66
99
  end
67
100
  end
68
101
 
69
- def resolve_variables!(version)
70
- each_with_number do |r|
71
- r.url = expand_variables(r.url, version) if r.url =~ /\$/
72
- r.name = expand_variables(r.name, version)
73
- r.alias = expand_variables(r.alias, version)
74
- end
75
-
76
- self
77
- end
78
-
79
102
  def save
80
103
  @list.each do |i|
81
104
  i[:repo].save
@@ -120,14 +143,6 @@ module Zypper
120
143
  res.uniq
121
144
  end
122
145
 
123
- def expand_variables(str, version)
124
- str.gsub(/\$releasever_major/, version.split(".")[0])
125
- .gsub(/\$releasever_minor/, version.split(".")[1])
126
- .gsub(/\$releasever/, version)
127
- .gsub(/\$basearch/, @arch)
128
- .gsub(/\$arch/, @cpu_arch)
129
- end
130
-
131
146
  def load_overrides(filename)
132
147
  raise FileNotFound, filename unless File.exist?(filename)
133
148
 
@@ -154,13 +169,14 @@ module Zypper
154
169
  class Repository
155
170
  attr_reader :filename, :old_url, :old_alias, :old_name
156
171
 
157
- def initialize(filename)
172
+ def initialize(filename, variables)
158
173
  @filename = filename
159
174
  @repo = IniParse.parse(File.read(filename))
160
175
  @key = read_key
161
176
  @old_url = nil
162
177
  @old_name = nil
163
178
  @old_alias = nil
179
+ resolve_variables!(variables)
164
180
  end
165
181
 
166
182
  def enabled?
@@ -242,6 +258,14 @@ module Zypper
242
258
 
243
259
  private
244
260
 
261
+ def resolve_variables!(variables)
262
+ self.url = variables.apply(url) if url =~ /\$/
263
+ self.name = variables.apply(name) if name =~ /\$/
264
+ self.alias = variables.apply(self.alias) if self.alias =~ /\$/
265
+
266
+ self
267
+ end
268
+
245
269
  def libzypp_process
246
270
  libpath = `ldd /usr/bin/zypper | grep "libzypp.so"`.split(" => ")[1].split.shift
247
271
  process = `sudo lsof #{libpath} | tail -n 1`
@@ -92,6 +92,10 @@ module Zypper
92
92
  def new_line
93
93
  "\n#{self}"
94
94
  end
95
+
96
+ def none
97
+ self
98
+ end
95
99
  end
96
100
 
97
101
  #
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Zypper
4
4
  module Upgraderepo
5
- VERSION = "1.9.0"
5
+ VERSION = "1.10.0"
6
6
  end
7
7
  end
@@ -57,8 +57,8 @@ module Zypper
57
57
  info(repo)
58
58
  end
59
59
 
60
- def self.separator(max_col)
61
- puts "-" * (max_col + 20)
60
+ def self.separator(max_col, char = "-", color = :none)
61
+ puts (char * (max_col + 20)).send(color)
62
62
  end
63
63
 
64
64
  def self.header(_max_col, _upgrade: false)
@@ -91,6 +91,32 @@ module Zypper
91
91
  puts " #{" " * 2} | #{repo.enabled? ? "Enabled: Yes" : "Enabled: No".yellow}"
92
92
  puts " #{" " * 2} | Filename: #{repo.filename}"
93
93
  end
94
+
95
+ def self.duplicates_header(_max_col)
96
+ puts " # | Duplicated repositories"
97
+ end
98
+
99
+ def self.duplicates_item(num, dnum, dcount, repo, _max_col)
100
+ puts " #{num.to_s.rjust(2).bold.yellow} | Duplicated repository n.#{dnum.to_s.bold}/#{dcount.to_s.bold}"
101
+ info(repo)
102
+ end
103
+
104
+ def self.duplicates_footer(dcount, total)
105
+ puts "Total duplicated repositories: #{dcount.to_s.bold.yellow}/#{total}"
106
+ end
107
+
108
+ def self.unused_header(_max_col)
109
+ puts " # | Unused repositories"
110
+ end
111
+
112
+ def self.unused_item(num, unum, repo, _max_col)
113
+ puts " #{num.to_s.rjust(2).bold.yellow} | Unused repository n.#{unum.to_s.bold}"
114
+ info(repo)
115
+ end
116
+
117
+ def self.unused_footer(ucount, total)
118
+ puts "Total unused repositories: #{ucount.to_s.bold.yellow}/#{total}"
119
+ end
94
120
  end
95
121
 
96
122
  #
@@ -150,8 +176,8 @@ module Zypper
150
176
  "| #{repo.enabled? ? " Y " : " N ".yellow} | #{"Error:".bold.red} #{repo.status}")
151
177
  end
152
178
 
153
- def self.separator(max_col)
154
- puts "-" * (max_col + 20)
179
+ def self.separator(max_col, char = "-", color = :none)
180
+ puts (char * (max_col + 20)).send(color)
155
181
  end
156
182
 
157
183
  def self.header(max_col, upgrade: false)
@@ -177,6 +203,34 @@ module Zypper
177
203
 
178
204
  Messages.warning "The #{"last".bold.red} version should be considered #{"Unstable".bold.red}"
179
205
  end
206
+
207
+ def self.duplicates_header(max_col)
208
+ puts " St. | # | #{"Name".ljust(max_col, " ")} | En. | Details"
209
+ end
210
+
211
+ def self.duplicates_item(num, dnum, dcount, repo, max_col)
212
+ Messages.warning("| #{num.to_s.rjust(2)} | #{repo.name.ljust(max_col, " ")} " \
213
+ "| #{repo.enabled? ? " Y " : " N ".yellow} " \
214
+ "| Duplicate n.#{dnum.to_s.bold}/#{dcount.to_s.bold} ")
215
+ end
216
+
217
+ def self.duplicates_footer(dcount, total)
218
+ puts "Total duplicated repositories: #{dcount.to_s.bold.yellow}/#{total}"
219
+ end
220
+
221
+ def self.unused_header(max_col)
222
+ puts " St. | # | #{"Name".ljust(max_col, " ")} | En. | Details"
223
+ end
224
+
225
+ def self.unused_item(num, unum, repo, max_col)
226
+ Messages.warning("| #{num.to_s.rjust(2)} | #{repo.name.ljust(max_col, " ")} " \
227
+ "| #{repo.enabled? ? " Y " : " N ".yellow} " \
228
+ "| Unused n.#{unum.to_s.bold}")
229
+ end
230
+
231
+ def self.unused_footer(ucount, total)
232
+ puts "Total unused repositories: #{ucount.to_s.bold.yellow}/#{total}"
233
+ end
180
234
  end
181
235
 
182
236
  #
@@ -201,7 +255,7 @@ module Zypper
201
255
 
202
256
  def self.server_error(num, repo, max_col); end
203
257
 
204
- def self.separator(_max_col); end
258
+ def self.separator(_max_col, _char = "-", _color = :none); end
205
259
 
206
260
  def self.header(max_col, upgrade: false); end
207
261
 
@@ -210,6 +264,22 @@ module Zypper
210
264
  def self.status(os_release)
211
265
  puts "#{os_release.seniority} #{os_release.newer.join(" ")}"
212
266
  end
267
+
268
+ def self.duplicates_header(_max_col); end
269
+
270
+ def self.duplicates_item(num, dnum, _dcount, _repo, _max_col)
271
+ puts "#{dnum}:#{num} "
272
+ end
273
+
274
+ def self.duplicates_footer(dcount, total); end
275
+
276
+ def self.unused_header(_max_col); end
277
+
278
+ def self.unused_item(num, _unum, _repo, _max_col)
279
+ puts num
280
+ end
281
+
282
+ def self.unused_footer(ucount, total); end
213
283
  end
214
284
 
215
285
  #
@@ -256,7 +326,7 @@ module Zypper
256
326
  puts "error=#{repo.status}"
257
327
  end
258
328
 
259
- def self.separator(_max_col)
329
+ def self.separator(_max_col, _char = "-", _color = :none)
260
330
  puts ""
261
331
  end
262
332
 
@@ -313,6 +383,34 @@ module Zypper
313
383
  puts "enabled=#{repo.enabled? ? "Yes" : "No"}"
314
384
  puts "status=#{status}"
315
385
  end
386
+
387
+ def self.duplicates_header(_max_col); end
388
+
389
+ def self.duplicates_item(num, dnum, dcount, repo, _max_col)
390
+ puts "[repository_#{num}]" if dnum == 1
391
+ puts "number_#{dnum}_#{dcount}=#{num}"
392
+ puts "name_#{dnum}_#{dcount}=#{repo.name}"
393
+ puts "alias_#{dnum}_#{dcount}=#{repo.alias}"
394
+ puts "url_#{dnum}_#{dcount}=#{repo.url}"
395
+ puts "priority_#{dnum}_#{dcount}=#{repo.priority}"
396
+ puts "enabled_#{dnum}_#{dcount}=#{repo.enabled? ? "Yes" : "No"}"
397
+ end
398
+
399
+ def self.duplicates_footer(dcount, total); end
400
+
401
+ def self.unused_header(_max_col); end
402
+
403
+ def self.unused_item(num, _unum, repo, _max_col)
404
+ puts "[repository_#{num}]"
405
+ puts "number=#{num}"
406
+ puts "name=#{repo.name}"
407
+ puts "alias=#{repo.alias}"
408
+ puts "url=#{repo.url}"
409
+ puts "priority=#{repo.priority}"
410
+ puts "enabled=#{repo.enabled? ? "Yes" : "No"}"
411
+ end
412
+
413
+ def self.unused_footer(ucount, total); end
316
414
  end
317
415
 
318
416
  #
@@ -16,7 +16,7 @@ module Zypper
16
16
  class Builder
17
17
  def initialize(options)
18
18
  @os_release = OsRelease.new(options)
19
- @repos = RepositoryList.new(options).resolve_variables!(@os_release.current)
19
+ @repos = RepositoryList.new(options, RepositoryVariables.new(@os_release.current))
20
20
  @print_hint = options.hint
21
21
  @view_class = Zypper::Upgraderepo::View.const_get options.view.to_s.capitalize
22
22
 
@@ -59,6 +59,46 @@ module Zypper
59
59
  check_repos(@os_release.last)
60
60
  end
61
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
+
62
102
  def upgrade_to_next
63
103
  raise AlreadyUpgraded, "latest" if @os_release.last?
64
104
 
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.9.0
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: 2024-06-13 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