zypper-upgraderepo 1.9.0 → 1.11.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: 7ceec1a1b9750d49b3c32863595d7b83c615dc140458a65a55dc93b115d5e3f3
4
- data.tar.gz: 857477ddec8c0457e0082583a98a68de4ee62ebca1e4972a578fceb6ba74ca57
3
+ metadata.gz: e642faca5400e4b8ed243726b9349740a1211207245d9cc9e72ee391bc12a71d
4
+ data.tar.gz: f4d8995a91cc4149db25129004e682afba03ffded92f4d812f980e2460bc839c
5
5
  SHA512:
6
- metadata.gz: 490758a8241038010a130c18b97d926744e289d6fe82462647b2d7fe149143e2efbb78dafd1b50cf769cdcde3a3d31099da87743ac77990d4be8aa8017113e4f
7
- data.tar.gz: 51731e28707401f36a825e34d06ecce3753bfd96fa03a14c35997a6113b1c62ddfd142b54df6d27d8f81863afb560964209a42f020e6ff2b693c1f201adc3d90
6
+ metadata.gz: 2d1e4c172bb8ce5cced6fd2fbfc932274b669aec69881d9b6069c9eefe308fd75b4ea78ecf385a8bb22550fbc7a4f1806b586e7ff8272d599f5f3a5cfebd0d86
7
+ data.tar.gz: c8d2563ba33b03e6417ad91f15a7f911c4f8438aad414b9558b859a821a4d88cfb9af4c2903c94e3bf2385c972ae872495449c763e2f0bbb745a485d5fba45ba
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
@@ -59,21 +60,7 @@ Metrics/CyclomaticComplexity:
59
60
  - './lib/**/view.rb'
60
61
  - './lib/**/traversable.rb'
61
62
 
62
- Lint/UriEscapeUnescape:
63
- Enabled: false
64
-
65
- Lint/UnusedMethodArgument:
66
- Enabled: true
67
- Exclude:
68
- - './lib/**/local.rb'
69
-
70
63
  Style/MixinUsage:
71
64
  Enabled: true
72
65
  Exclude:
73
66
  - './spec/**/*'
74
-
75
- Style/FrozenStringLiteralComment:
76
- Enabled: true
77
- Exclude:
78
- - './bin/*'
79
- - './exe/*'
data/Gemfile CHANGED
@@ -7,6 +7,8 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
7
7
  # Specify your gem's dependencies in zypper-upgraderepo.gemspec
8
8
  gemspec
9
9
 
10
+ gem "bundler", "~> 2.0"
11
+
10
12
  gem "rake", "~> 13.0"
11
13
 
12
14
  gem "rspec", "~> 3.0"
data/Gemfile.lock CHANGED
@@ -1,63 +1,75 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zypper-upgraderepo (1.9.0)
4
+ zypper-upgraderepo (1.11.0)
5
5
  iniparse
6
6
  minitar
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- ast (2.4.2)
12
- diff-lcs (1.5.1)
11
+ ast (2.4.3)
12
+ diff-lcs (1.6.2)
13
13
  iniparse (1.5.0)
14
- json (2.7.2)
15
- minitar (0.9)
16
- parallel (1.24.0)
17
- parser (3.3.2.0)
14
+ json (2.12.2)
15
+ language_server-protocol (3.17.0.5)
16
+ lint_roller (1.1.0)
17
+ minitar (0.12.1)
18
+ parallel (1.27.0)
19
+ parser (3.3.8.0)
18
20
  ast (~> 2.4.1)
19
21
  racc
20
- racc (1.8.0)
22
+ prism (1.4.0)
23
+ racc (1.8.1)
21
24
  rainbow (3.1.1)
22
- rake (13.2.1)
23
- regexp_parser (2.9.2)
24
- rexml (3.3.0)
25
- strscan
26
- rspec (3.13.0)
25
+ rake (13.3.0)
26
+ regexp_parser (2.10.0)
27
+ rspec (3.13.1)
27
28
  rspec-core (~> 3.13.0)
28
29
  rspec-expectations (~> 3.13.0)
29
30
  rspec-mocks (~> 3.13.0)
30
- rspec-core (3.13.0)
31
+ rspec-core (3.13.4)
31
32
  rspec-support (~> 3.13.0)
32
- rspec-expectations (3.13.0)
33
+ rspec-expectations (3.13.5)
33
34
  diff-lcs (>= 1.2.0, < 2.0)
34
35
  rspec-support (~> 3.13.0)
35
- rspec-mocks (3.13.1)
36
+ rspec-mocks (3.13.5)
36
37
  diff-lcs (>= 1.2.0, < 2.0)
37
38
  rspec-support (~> 3.13.0)
38
- rspec-support (3.13.1)
39
- rubocop (1.50.2)
39
+ rspec-support (3.13.4)
40
+ rubocop (1.76.0)
40
41
  json (~> 2.3)
42
+ language_server-protocol (~> 3.17.0.2)
43
+ lint_roller (~> 1.1.0)
41
44
  parallel (~> 1.10)
42
- parser (>= 3.2.0.0)
45
+ parser (>= 3.3.0.2)
43
46
  rainbow (>= 2.2.2, < 4.0)
44
- regexp_parser (>= 1.8, < 3.0)
45
- rexml (>= 3.2.5, < 4.0)
46
- rubocop-ast (>= 1.28.0, < 2.0)
47
+ regexp_parser (>= 2.9.3, < 3.0)
48
+ rubocop-ast (>= 1.45.0, < 2.0)
47
49
  ruby-progressbar (~> 1.7)
48
- unicode-display_width (>= 2.4.0, < 3.0)
49
- rubocop-ast (1.30.0)
50
- parser (>= 3.2.1.0)
51
- rubocop-capybara (2.18.0)
52
- rubocop (~> 1.41)
50
+ unicode-display_width (>= 2.4.0, < 4.0)
51
+ rubocop-ast (1.45.0)
52
+ parser (>= 3.3.7.2)
53
+ prism (~> 1.4)
54
+ rubocop-capybara (2.22.1)
55
+ lint_roller (~> 1.1)
56
+ rubocop (~> 1.72, >= 1.72.1)
57
+ rubocop-factory_bot (2.27.1)
58
+ lint_roller (~> 1.1)
59
+ rubocop (~> 1.72, >= 1.72.1)
53
60
  rubocop-rake (0.6.0)
54
61
  rubocop (~> 1.0)
55
- rubocop-rspec (2.20.0)
56
- rubocop (~> 1.33)
62
+ rubocop-rspec (2.31.0)
63
+ rubocop (~> 1.40)
57
64
  rubocop-capybara (~> 2.17)
65
+ rubocop-factory_bot (~> 2.22)
66
+ rubocop-rspec_rails (~> 2.28)
67
+ rubocop-rspec_rails (2.29.1)
68
+ rubocop (~> 1.61)
58
69
  ruby-progressbar (1.13.0)
59
- strscan (3.1.0)
60
- unicode-display_width (2.5.0)
70
+ unicode-display_width (3.1.4)
71
+ unicode-emoji (~> 4.0, >= 4.0.4)
72
+ unicode-emoji (4.0.4)
61
73
 
62
74
  PLATFORMS
63
75
  ruby
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Zypper-Upgraderepo
2
2
 
3
- Zypper-Upgraderepo helps to check and upgrade the repositories used in your system for the
4
- current, next or a custom valid version, reporting the errors and trying to find a replacement
3
+ Zypper-Upgraderepo helps to check and upgrade the configured repositories validating or looking for the
4
+ current, next or a custom valid version, reporting the errors and trying to find an alternative URL
5
5
  when possible.
6
6
 
7
7
  It can be also be installed as Zypper plugin using the [Zypper Upgraderepo Plugin][zypper_upgraderepo_plugin].
@@ -32,24 +32,24 @@ in the related [project page][project_page] at my blog.
32
32
 
33
33
  ## Usage
34
34
 
35
- ***Warning!!! The executables name prior the 1.8.0 version is zypper-upgraderepo, unfortunately the
36
- RPM package installation introduces annoying copies of the same executable having a version appended
37
- (zypper-upgraderepo.version, zypper-upgraderepo.rubyversion, zypper-upgraderepo.rubyversion.version)
35
+ **Warning!!! The executables name prior the 1.8.0 version was zypper-upgraderepo, unfortunately the
36
+ RPM package installation introduces annoying copies of the same executable with a Ruby version appended
37
+ (zypper-upgraderepo.*version*, zypper-upgraderepo.*rubyversion*, zypper-upgraderepo.*rubyversion*.*version*)
38
38
  interpreted by zypper itself as different subcommands. So I considered more convenient to remove the
39
39
  zypper prefix from the original executable and let the sole zypper-upgraderepo-plugin package install
40
- it as a zypper plugin.***
40
+ it as a zypper plugin.**
41
41
 
42
- To check the availability of the current repositories:
42
+ To check the availability of the **current** repositories:
43
43
  ```shell
44
44
  $ upgraderepo
45
45
  ```
46
46
 
47
- To check the availability of the next version repositories:
47
+ To check the availability of the **next** version repositories:
48
48
  ```shell
49
49
  $ upgraderepo --check-next
50
50
  ```
51
51
 
52
- To upgrade the repositories to the next version:
52
+ To **upgrade** the repositories to the next version:
53
53
  ```shell
54
54
  $ sudo upgraderepo --upgrade
55
55
  ```
@@ -64,8 +64,8 @@ $ upgraderepo --help
64
64
  ## More Help:
65
65
 
66
66
  More info is available at:
67
- - the [Zypper-Upgraderepo GitHub wiki][zypper_upgraderepo_wiki];
68
- - the article [Upgrading with Zypper][upgrading_with_zypper] on Freeaptitude blog.
67
+ - The [Zypper-Upgraderepo GitHub wiki][zypper_upgraderepo_wiki];
68
+ - The [Upgrading with Zypper][upgrading_with_zypper] article on Freeaptitude blog.
69
69
 
70
70
 
71
71
  [zypper_upgraderepo_plugin]: https://github.com/fabiomux/zypper-upgraderepo-plugin "Zypper-Upgraderepo Plugin GitHub page"
data/bin/console CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # frozen_string_literal: true
4
+
3
5
  require "bundler/setup"
4
6
  require "zypper/upgraderepo"
5
7
 
data/exe/upgraderepo CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # frozen_string_literal: true
4
+
3
5
  require "zypper/upgraderepo/cli"
4
6
 
5
7
  Zypper::Upgraderepo::CLI.start
@@ -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
@@ -10,10 +10,6 @@ module Zypper
10
10
  class OsRelease
11
11
  attr_reader :custom, :unstable
12
12
 
13
- OS_VERSIONS = ["13.1", "13.2",
14
- "42.1", "42.2", "42.3",
15
- "15.0", "15.1", "15.2", "15.3", "15.4", "15.5", "15.6"].freeze
16
-
17
13
  UNSTABLE_VERSION = "16.0"
18
14
 
19
15
  OS_RELEASE_FILE = "/etc/os-release"
@@ -21,10 +17,15 @@ module Zypper
21
17
  SUSE_RELEASE_FILE = "/etc/SuSE-release"
22
18
 
23
19
  def initialize(options)
20
+ @os_versions = ["13.1", "13.2",
21
+ "42.1", "42.2", "42.3",
22
+ "15.0", "15.1", "15.2", "15.3", "15.4", "15.5", "15.6",
23
+ "16.0"]
24
+
24
25
  if options.allow_unstable
25
26
  raise NoUnstableVersionAvailable if UNSTABLE_VERSION.empty?
26
27
 
27
- OS_VERSIONS << UNSTABLE_VERSION
28
+ @os_versions << UNSTABLE_VERSION
28
29
  @unstable = true
29
30
  end
30
31
 
@@ -36,52 +37,52 @@ module Zypper
36
37
  raise ReleaseFileNotFound
37
38
  end
38
39
  @release = IniParse.parse(File.read(fname))
39
- @current_idx = OS_VERSIONS.index(@release["__anonymous__"]["VERSION"].delete('"'))
40
+ @current_idx = @os_versions.index(@release["__anonymous__"]["VERSION"].delete('"'))
40
41
 
41
42
  return unless options.version
42
- raise InvalidVersion, options.version unless OS_VERSIONS.include?(options.version)
43
+ raise InvalidVersion, options.version unless @os_versions.include?(options.version)
43
44
 
44
45
  @custom = options.version
45
46
  end
46
47
 
47
48
  def current
48
- OS_VERSIONS[@current_idx]
49
+ @os_versions[@current_idx]
49
50
  end
50
51
 
51
52
  def last
52
- OS_VERSIONS[-1]
53
+ @os_versions[-1]
53
54
  end
54
55
 
55
56
  def next
56
57
  return if last?
57
58
 
58
- OS_VERSIONS[@current_idx.next]
59
+ @os_versions[@current_idx.next]
59
60
  end
60
61
 
61
62
  def previous
62
63
  return if first?
63
64
 
64
- OS_VERSIONS[@current_idx.pred]
65
+ @os_versions[@current_idx.pred]
65
66
  end
66
67
 
67
68
  def fullname
68
- @release["__anonymous__"]["PRETTY_NAME"].gsub(/"/, "")
69
+ @release["__anonymous__"]["PRETTY_NAME"].gsub('"', "")
69
70
  end
70
71
 
71
72
  def seniority
72
- OS_VERSIONS.count - @current_idx.next
73
+ @os_versions.count - @current_idx.next
73
74
  end
74
75
 
75
76
  def newer
76
77
  if seniority.positive?
77
- OS_VERSIONS[@current_idx.next..-1]
78
+ @os_versions[@current_idx.next..-1]
78
79
  else
79
80
  []
80
81
  end
81
82
  end
82
83
 
83
84
  def last?
84
- @current_idx == (OS_VERSIONS.count - 1)
85
+ @current_idx == (@os_versions.count - 1)
85
86
  end
86
87
 
87
88
  def first?
@@ -89,11 +90,11 @@ module Zypper
89
90
  end
90
91
 
91
92
  def valid?(version)
92
- OS_VERSIONS.include? version
93
+ @os_versions.include? version
93
94
  end
94
95
 
95
96
  def current?(version)
96
- OS_VERSIONS.index(version) == @current_idx
97
+ @os_versions.index(version) == @current_idx
97
98
  end
98
99
  end
99
100
  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,19 +99,9 @@ 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
- @list.each do |i|
81
- i[:repo].save
103
+ each_with_number do |repo, _num|
104
+ repo.save
82
105
  end
83
106
  end
84
107
 
@@ -95,12 +118,12 @@ module Zypper
95
118
  res.push l[:num]
96
119
  end
97
120
  elsif r =~ /^\ *\#.*/
98
- u = r.gsub(/\#/, "").strip
121
+ u = r.gsub("#", "").strip
99
122
  @list.select { |x| x[:repo].url.match?(Regexp.new(u, "i")) }.each do |l|
100
123
  res.push l[:num]
101
124
  end
102
125
  elsif r =~ /^\ *&.*/
103
- s = r.gsub(/&/, "").strip
126
+ s = r.gsub("&", "").strip
104
127
  sel = @list.select do |x|
105
128
  x[:repo].alias.match?(Regexp.new(s, "i")) ||
106
129
  x[:repo].name.match?(Regexp.new(s, "i")) ||
@@ -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`
@@ -14,7 +14,7 @@ module Zypper
14
14
  USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
15
15
 
16
16
  def initialize(obj, timeout = 60)
17
- super obj
17
+ super(obj)
18
18
  @timeout = timeout
19
19
  end
20
20
 
@@ -118,7 +118,7 @@ module Zypper
118
118
 
119
119
  def get_request(uri, head)
120
120
  # super uri || URI(url), head
121
- super uri || repodata_uri, head
121
+ super(uri || repodata_uri, head)
122
122
  end
123
123
 
124
124
  def repodata?(uri)
@@ -11,7 +11,7 @@ module Zypper
11
11
  attr_reader :dir_path
12
12
 
13
13
  def initialize(obj, _timeout)
14
- super obj
14
+ super(obj)
15
15
  end
16
16
 
17
17
  def available?
@@ -48,13 +48,15 @@ module Zypper
48
48
 
49
49
  private
50
50
 
51
+ # rubocop: disable Lint/UnusedMethodArgument
51
52
  def ping(uri = nil, head: true)
52
53
  @dir_path ||= URI(url).path
53
54
 
54
55
  @dir_path = uri.to_s =~ %r{^/} ? uri.to_s : URI(uri.to_s).path if uri
55
56
 
56
- URI.unescape(@dir_path)
57
+ URI::DEFAULT_PARSER.unescape(@dir_path)
57
58
  end
59
+ # rubocop: enable Lint/UnusedMethodArgument
58
60
  end
59
61
 
60
62
  module Requests
@@ -88,12 +90,12 @@ module Zypper
88
90
  private
89
91
 
90
92
  def repodata?(uri)
91
- File.exist? URI.unescape(repodata_uri(uri).path)
93
+ File.exist? URI::DEFAULT_PARSER.unescape(repodata_uri(uri).path)
92
94
  end
93
95
 
94
96
  def subfolders
95
97
  Dir.glob("#{ping.gsub(%r{/$}, "")}/*/").map do |x|
96
- URI.escape(x.gsub(%r{/$}, "").gsub(ping, "").gsub(%r{^/}, ""))
98
+ URI::DEFAULT_PARSER.escape(x.gsub(%r{/$}, "").gsub(ping, "").gsub(%r{^/}, ""))
97
99
  end
98
100
  end
99
101
  end
@@ -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
  #
@@ -131,7 +135,7 @@ module Zypper
131
135
  #
132
136
  class FileNotFound < StandardError
133
137
  def initialize(filename)
134
- super "The File #{filename} doesn't exist."
138
+ super("The File #{filename} doesn't exist.")
135
139
  end
136
140
  end
137
141
 
@@ -140,7 +144,7 @@ module Zypper
140
144
  #
141
145
  class ReleaseFileNotFound < StandardError
142
146
  def initialize
143
- super "The release file is not found."
147
+ super("The release file is not found.")
144
148
  end
145
149
  end
146
150
 
@@ -149,7 +153,7 @@ module Zypper
149
153
  #
150
154
  class InvalidProtocol < StandardError
151
155
  def initialize(repo)
152
- super "The repository #{repo.name} has an unknown protocol: #{repo.protocol}; disable it to continue."
156
+ super("The repository #{repo.name} has an unknown protocol: #{repo.protocol}; disable it to continue.")
153
157
  end
154
158
  end
155
159
 
@@ -158,7 +162,7 @@ module Zypper
158
162
  #
159
163
  class InvalidVersion < StandardError
160
164
  def initialize(version)
161
- super "The version #{version} is not valid"
165
+ super("The version #{version} is not valid")
162
166
  end
163
167
  end
164
168
 
@@ -167,7 +171,7 @@ module Zypper
167
171
  #
168
172
  class InvalidWritePermissions < StandardError
169
173
  def initialize(filename)
170
- super "Don't have the right permission to write #{filename}"
174
+ super("Don't have the permissions to write #{filename}")
171
175
  end
172
176
 
173
177
  def error_code
@@ -180,7 +184,7 @@ module Zypper
180
184
  #
181
185
  class SystemUpdateRunning < StandardError
182
186
  def initialize(args)
183
- super "The application #{args[:process].bold} with pid #{args[:pid].bold} is running a system update!"
187
+ super("The application #{args[:process].bold} with pid #{args[:pid].bold} is running a system update!")
184
188
  end
185
189
 
186
190
  def error_code
@@ -193,8 +197,8 @@ module Zypper
193
197
  #
194
198
  class UnableToUpgrade < StandardError
195
199
  def initialize(args)
196
- super "The repository n.#{args[:num].to_s.bold.red} named #{args[:repo].name.bold.red} " \
197
- "can't be upgraded, a manual check is required!"
200
+ super("The repository n.#{args[:num].to_s.bold.red} named #{args[:repo].name.bold.red} " \
201
+ "can't be upgraded, a manual check is required!")
198
202
  end
199
203
 
200
204
  def error_code
@@ -207,8 +211,8 @@ module Zypper
207
211
  #
208
212
  class MissingOverride < StandardError
209
213
  def initialize(args)
210
- super "The repository n.#{args[:num].to_s.bold.red} named #{args[:ini]["name"].bold.red} " \
211
- "doesn't contain the URL key!"
214
+ super("The repository n.#{args[:num].to_s.bold.red} named #{args[:ini]["name"].bold.red} " \
215
+ "doesn't contain the URL key!")
212
216
  end
213
217
 
214
218
  def error_code
@@ -221,8 +225,8 @@ module Zypper
221
225
  #
222
226
  class UnmatchingOverrides < StandardError
223
227
  def initialize(args)
224
- super "The repository n.#{args[:num]} named #{args[:repo].name.bold.red} doesn't match with " \
225
- "the repository named #{args[:ini]["name"].bold.red} in the ini file"
228
+ super("The repository n.#{args[:num]} named #{args[:repo].name.bold.red} doesn't match with " \
229
+ "the repository named #{args[:ini]["name"].bold.red} in the ini file")
226
230
  end
227
231
 
228
232
  def error_code
@@ -235,7 +239,7 @@ module Zypper
235
239
  #
236
240
  class AlreadyUpgraded < StandardError
237
241
  def initialize(version)
238
- super "The system is already upgraded to the #{version} version"
242
+ super("The system is already upgraded to the #{version} version")
239
243
  end
240
244
 
241
245
  def error_code
@@ -248,7 +252,7 @@ module Zypper
248
252
  #
249
253
  class NoUnstableVersionAvailable < StandardError
250
254
  def initialize
251
- super "No unstable version is available, remove the --allow-unstable switch to continue"
255
+ super("No unstable version is available, remove the --allow-unstable switch to continue")
252
256
  end
253
257
 
254
258
  def error_code
@@ -260,7 +264,7 @@ module Zypper
260
264
  # No internet connection.
261
265
  class NoConnection < StandardError
262
266
  def initialize
263
- super "Internet connection has some trouble"
267
+ super("Internet connection has some trouble")
264
268
  end
265
269
 
266
270
  def error_code
@@ -273,7 +277,7 @@ module Zypper
273
277
  #
274
278
  class Interruption < StandardError
275
279
  def initialize
276
- super "Ok ok... Exiting!"
280
+ super("Ok ok... Exiting!")
277
281
  end
278
282
  end
279
283
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Zypper
4
4
  module Upgraderepo
5
- VERSION = "1.9.0"
5
+ VERSION = "1.11.0"
6
6
  end
7
7
  end
@@ -57,11 +57,11 @@ 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
- def self.header(_max_col, _upgrade: false)
64
+ def self.header(*)
65
65
  puts " # | Report"
66
66
  end
67
67
 
@@ -83,14 +83,43 @@ module Zypper
83
83
  end
84
84
 
85
85
  def self.info(repo)
86
- puts " #{" " * 2} | Name: #{repo.name} #{repo.upgraded?(:name) ? "(#{repo.old_name.yellow})" : ""}"
87
- puts " #{" " * 2} | Alias: #{repo.alias} #{repo.upgraded?(:alias) ? "(#{repo.old_alias.yellow})" : ""}"
86
+ old_name = repo.upgraded?(:name) ? "(#{repo.old_name.yellow})" : ""
87
+ old_alias = repo.upgraded?(:alias) ? "(#{repo.old_alias.yellow})" : ""
88
+
89
+ puts " #{" " * 2} | Name: #{repo.name} #{old_name}"
90
+ puts " #{" " * 2} | Alias: #{repo.alias} #{old_alias}"
88
91
  puts " #{" " * 2} | Url: #{repo.url}"
89
92
  puts " #{" " * 2} | (#{repo.old_url.yellow})" if repo.upgraded?
90
93
  puts " #{" " * 2} | Priority: #{repo.priority}"
91
94
  puts " #{" " * 2} | #{repo.enabled? ? "Enabled: Yes" : "Enabled: No".yellow}"
92
95
  puts " #{" " * 2} | Filename: #{repo.filename}"
93
96
  end
97
+
98
+ def self.duplicates_header(_max_col)
99
+ puts " # | Duplicated repositories"
100
+ end
101
+
102
+ def self.duplicates_item(num, dnum, dcount, repo, _max_col)
103
+ puts " #{num.to_s.rjust(2).bold.yellow} | Duplicated repository n.#{dnum.to_s.bold}/#{dcount.to_s.bold}"
104
+ info(repo)
105
+ end
106
+
107
+ def self.duplicates_footer(dcount, total)
108
+ puts "Total duplicated repositories: #{dcount.to_s.bold.yellow}/#{total}"
109
+ end
110
+
111
+ def self.unused_header(_max_col)
112
+ puts " # | Unused repositories"
113
+ end
114
+
115
+ def self.unused_item(num, unum, repo, _max_col)
116
+ puts " #{num.to_s.rjust(2).bold.yellow} | Unused repository n.#{unum.to_s.bold}"
117
+ info(repo)
118
+ end
119
+
120
+ def self.unused_footer(ucount, total)
121
+ puts "Total unused repositories: #{ucount.to_s.bold.yellow}/#{total}"
122
+ end
94
123
  end
95
124
 
96
125
  #
@@ -150,8 +179,8 @@ module Zypper
150
179
  "| #{repo.enabled? ? " Y " : " N ".yellow} | #{"Error:".bold.red} #{repo.status}")
151
180
  end
152
181
 
153
- def self.separator(max_col)
154
- puts "-" * (max_col + 20)
182
+ def self.separator(max_col, char = "-", color = :none)
183
+ puts (char * (max_col + 20)).send(color)
155
184
  end
156
185
 
157
186
  def self.header(max_col, upgrade: false)
@@ -177,6 +206,34 @@ module Zypper
177
206
 
178
207
  Messages.warning "The #{"last".bold.red} version should be considered #{"Unstable".bold.red}"
179
208
  end
209
+
210
+ def self.duplicates_header(max_col)
211
+ puts " St. | # | #{"Name".ljust(max_col, " ")} | En. | Details"
212
+ end
213
+
214
+ def self.duplicates_item(num, dnum, dcount, repo, max_col)
215
+ Messages.warning("| #{num.to_s.rjust(2)} | #{repo.name.ljust(max_col, " ")} " \
216
+ "| #{repo.enabled? ? " Y " : " N ".yellow} " \
217
+ "| Duplicate n.#{dnum.to_s.bold}/#{dcount.to_s.bold} ")
218
+ end
219
+
220
+ def self.duplicates_footer(dcount, total)
221
+ puts "Total duplicated repositories: #{dcount.to_s.bold.yellow}/#{total}"
222
+ end
223
+
224
+ def self.unused_header(max_col)
225
+ puts " St. | # | #{"Name".ljust(max_col, " ")} | En. | Details"
226
+ end
227
+
228
+ def self.unused_item(num, unum, repo, max_col)
229
+ Messages.warning("| #{num.to_s.rjust(2)} | #{repo.name.ljust(max_col, " ")} " \
230
+ "| #{repo.enabled? ? " Y " : " N ".yellow} " \
231
+ "| Unused n.#{unum.to_s.bold}")
232
+ end
233
+
234
+ def self.unused_footer(ucount, total)
235
+ puts "Total unused repositories: #{ucount.to_s.bold.yellow}/#{total}"
236
+ end
180
237
  end
181
238
 
182
239
  #
@@ -201,7 +258,7 @@ module Zypper
201
258
 
202
259
  def self.server_error(num, repo, max_col); end
203
260
 
204
- def self.separator(_max_col); end
261
+ def self.separator(_max_col, _char = "-", _color = :none); end
205
262
 
206
263
  def self.header(max_col, upgrade: false); end
207
264
 
@@ -210,6 +267,22 @@ module Zypper
210
267
  def self.status(os_release)
211
268
  puts "#{os_release.seniority} #{os_release.newer.join(" ")}"
212
269
  end
270
+
271
+ def self.duplicates_header(_max_col); end
272
+
273
+ def self.duplicates_item(num, dnum, _dcount, _repo, _max_col)
274
+ puts "#{dnum}:#{num} "
275
+ end
276
+
277
+ def self.duplicates_footer(dcount, total); end
278
+
279
+ def self.unused_header(_max_col); end
280
+
281
+ def self.unused_item(num, _unum, _repo, _max_col)
282
+ puts num
283
+ end
284
+
285
+ def self.unused_footer(ucount, total); end
213
286
  end
214
287
 
215
288
  #
@@ -256,7 +329,7 @@ module Zypper
256
329
  puts "error=#{repo.status}"
257
330
  end
258
331
 
259
- def self.separator(_max_col)
332
+ def self.separator(_max_col, _char = "-", _color = :none)
260
333
  puts ""
261
334
  end
262
335
 
@@ -313,6 +386,34 @@ module Zypper
313
386
  puts "enabled=#{repo.enabled? ? "Yes" : "No"}"
314
387
  puts "status=#{status}"
315
388
  end
389
+
390
+ def self.duplicates_header(_max_col); end
391
+
392
+ def self.duplicates_item(num, dnum, dcount, repo, _max_col)
393
+ puts "[repository_#{num}]" if dnum == 1
394
+ puts "number_#{dnum}_#{dcount}=#{num}"
395
+ puts "name_#{dnum}_#{dcount}=#{repo.name}"
396
+ puts "alias_#{dnum}_#{dcount}=#{repo.alias}"
397
+ puts "url_#{dnum}_#{dcount}=#{repo.url}"
398
+ puts "priority_#{dnum}_#{dcount}=#{repo.priority}"
399
+ puts "enabled_#{dnum}_#{dcount}=#{repo.enabled? ? "Yes" : "No"}"
400
+ end
401
+
402
+ def self.duplicates_footer(dcount, total); end
403
+
404
+ def self.unused_header(_max_col); end
405
+
406
+ def self.unused_item(num, _unum, repo, _max_col)
407
+ puts "[repository_#{num}]"
408
+ puts "number=#{num}"
409
+ puts "name=#{repo.name}"
410
+ puts "alias=#{repo.alias}"
411
+ puts "url=#{repo.url}"
412
+ puts "priority=#{repo.priority}"
413
+ puts "enabled=#{repo.enabled? ? "Yes" : "No"}"
414
+ end
415
+
416
+ def self.unused_footer(ucount, total); end
316
417
  end
317
418
 
318
419
  #
@@ -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_value do |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
 
@@ -29,10 +29,6 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ["lib"]
31
31
 
32
- spec.add_development_dependency "bundler", "~> 2.0"
33
- spec.add_development_dependency "rake", "~> 13.0"
34
- spec.add_development_dependency "rspec", "~> 3.0"
35
-
36
- spec.add_runtime_dependency "iniparse"
37
- spec.add_runtime_dependency "minitar"
32
+ spec.add_dependency "iniparse"
33
+ spec.add_dependency "minitar"
38
34
  end
metadata CHANGED
@@ -1,57 +1,15 @@
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.11.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: 2025-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '2.0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '13.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '13.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.0'
55
13
  - !ruby/object:Gem::Dependency
56
14
  name: iniparse
57
15
  requirement: !ruby/object:Gem::Requirement
@@ -135,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
93
  - !ruby/object:Gem::Version
136
94
  version: '0'
137
95
  requirements: []
138
- rubygems_version: 3.4.3
96
+ rubygems_version: 3.1.6
139
97
  signing_key:
140
98
  specification_version: 4
141
99
  summary: Zypper addon to check and upgrade local repositories.