zypper-upgraderepo 1.2.0 → 1.3.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: a427fb24de5056e9425117be69b150cd225a9cf649d93f0ee8c5425951021824
4
- data.tar.gz: a317a3f790c16151bb08a9cdffddd8e813f325adf0f49f5a5aac9760a4b28aee
3
+ metadata.gz: b13911becd258b1faf2a3a94c84a9899cd9d5bb8e0ac916e7aac7b7e687dfdc4
4
+ data.tar.gz: 563d2da75b66e61a72d3f5471d4bbe7d4a2910ec0fb5141811d68212bc69dd3a
5
5
  SHA512:
6
- metadata.gz: 256f4cf0b63242db412d27328bdc0599b583e20dfbc194941963d4676f025033defadaeab0bb1f6cf3cbeaf2c0ebe64cdc78e3460c9693ac53454768d810cf91
7
- data.tar.gz: '0408b1a8169c94fa1115b1f9fda5ce411718cac4d8afeb149dbdb3b5f2a76a89a57c97ebca951a7c440ffc2c96929985e94f60d353fd5302517d9a8f9f2aa141'
6
+ metadata.gz: b23a6b5f089b9c2d23d7c887489f72f1c421b6259f1a291efa9211506dc489ef85820ac52d9f4786ac908a74f55cd163aa0a7b40713e0d10873e3e3823ef66ff
7
+ data.tar.gz: 9adf8f0be93b9a7f2c349168535238ed6355f1f9c14968717e96168d1929216ac0a1917ab63c1d35136e4e131cbfe88fae8a3ea2d2784431a37f2a393af73b3f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zypper-upgraderepo (1.2.0)
4
+ zypper-upgraderepo (1.3.0)
5
5
  iniparse
6
6
  minitar
7
7
 
@@ -9,31 +9,31 @@ GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  diff-lcs (1.3)
12
- iniparse (1.4.4)
13
- minitar (0.6.1)
14
- rake (10.5.0)
15
- rspec (3.7.0)
16
- rspec-core (~> 3.7.0)
17
- rspec-expectations (~> 3.7.0)
18
- rspec-mocks (~> 3.7.0)
19
- rspec-core (3.7.1)
20
- rspec-support (~> 3.7.0)
21
- rspec-expectations (3.7.0)
12
+ iniparse (1.5.0)
13
+ minitar (0.9)
14
+ rake (13.0.1)
15
+ rspec (3.9.0)
16
+ rspec-core (~> 3.9.0)
17
+ rspec-expectations (~> 3.9.0)
18
+ rspec-mocks (~> 3.9.0)
19
+ rspec-core (3.9.1)
20
+ rspec-support (~> 3.9.1)
21
+ rspec-expectations (3.9.0)
22
22
  diff-lcs (>= 1.2.0, < 2.0)
23
- rspec-support (~> 3.7.0)
24
- rspec-mocks (3.7.0)
23
+ rspec-support (~> 3.9.0)
24
+ rspec-mocks (3.9.1)
25
25
  diff-lcs (>= 1.2.0, < 2.0)
26
- rspec-support (~> 3.7.0)
27
- rspec-support (3.7.1)
26
+ rspec-support (~> 3.9.0)
27
+ rspec-support (3.9.2)
28
28
 
29
29
  PLATFORMS
30
30
  ruby
31
31
 
32
32
  DEPENDENCIES
33
- bundler (~> 1.16)
34
- rake (~> 10.0)
33
+ bundler (~> 2.0)
34
+ rake (~> 13.0)
35
35
  rspec (~> 3.0)
36
36
  zypper-upgraderepo!
37
37
 
38
38
  BUNDLED WITH
39
- 1.17.1
39
+ 2.1.4
@@ -21,12 +21,16 @@ module Zypper
21
21
  @upgrade_options = { alias: options.alias, name: options.name }
22
22
 
23
23
  @backup_path = options.backup_path
24
+
25
+ @exit_on_fail = options.exit_on_fail
26
+
27
+ @filename = options.filename
24
28
  end
25
29
 
26
30
  def backup
27
31
  filename = File.join(@backup_path, "repos-backup-#{Time.now.to_s.delete(': +-')[0..-5]}.tgz")
28
32
 
29
- raise InvalidPermissions, filename unless File.writable? @backup_path
33
+ raise InvalidWritePermissions, filename unless File.writable? @backup_path
30
34
 
31
35
  Minitar.pack(RepositoryList::REPOSITORY_PATH, Zlib::GzipWriter.new(File.open(filename, 'wb')))
32
36
 
@@ -48,6 +52,11 @@ module Zypper
48
52
  check_repos(@os_release.custom)
49
53
  end
50
54
 
55
+ def check_from_file
56
+ load_overrides
57
+ check_repos(@os_release.next)
58
+ end
59
+
51
60
  def upgrade
52
61
  raise AlreadyUpgraded, 'latest' if @os_release.last?
53
62
  upgrade_repos(@os_release.next)
@@ -58,9 +67,28 @@ module Zypper
58
67
  upgrade_repos(@os_release.custom)
59
68
  end
60
69
 
70
+ def reset
71
+ upgrade_repos(@os_release.current)
72
+ end
73
+
74
+ def upgrade_from_file
75
+ load_overrides
76
+ upgrade_repos(@os_release.next)
77
+ end
78
+
61
79
 
62
80
  private
63
81
 
82
+ def load_overrides
83
+ ini = IniParse.parse(File.read(@filename))
84
+ @repos.each_with_index do |r, i|
85
+ x = ini["Repository_#{i.next}"]
86
+ raise UnmatchingOverrides, { num: i.next, ini: x, repo: r } if r.url != x['OldURL']
87
+ raise MissingOverride, { num: i.next, ini: x } unless x['URL']
88
+ @overrides[i.next] = x['URL']
89
+ end
90
+ end
91
+
64
92
  def check_repos(version)
65
93
  @view_class.header(@repos.max_col)
66
94
 
@@ -70,16 +98,19 @@ module Zypper
70
98
 
71
99
  if r.available?
72
100
  @view_class.available i.next, r, @repos.max_col
73
- elsif r.redirected?
74
- @view_class.redirected i.next, r, @repos.max_col, r.redirected_to
75
- elsif r.not_found?
76
- if @print_hint
77
- @view_class.alternative i.next, r, @repos.max_col, r.evaluate_alternative(version)
78
- else
79
- @view_class.not_found i.next, r, @repos.max_col
101
+ else
102
+ raise UnableToUpgrade, {num: i.next, repo: r} if @exit_on_fail
103
+ if r.redirected?
104
+ @view_class.redirected i.next, r, @repos.max_col, r.redirected_to
105
+ elsif r.not_found?
106
+ if @print_hint
107
+ @view_class.alternative i.next, r, @repos.max_col, r.evaluate_alternative(version)
108
+ else
109
+ @view_class.not_found i.next, r, @repos.max_col
110
+ end
111
+ elsif r.timeout?
112
+ @view_class.timeout i.next, r, @repos.max_col
80
113
  end
81
- elsif r.timeout?
82
- @view_class.timeout i.next, r, @repos.max_col
83
114
  end
84
115
  end
85
116
 
@@ -23,6 +23,8 @@ module Zypper
23
23
  options.view = :table
24
24
  options.only_repo = nil
25
25
  options.timeout = 10.0
26
+ options.exit_on_fail = false
27
+ options.filename = ''
26
28
 
27
29
  opt_parser = OptionParser.new do |opt|
28
30
 
@@ -54,6 +56,15 @@ module Zypper
54
56
  options.operation = :check_to
55
57
  end
56
58
 
59
+ opt.on('-f', '--check-from-file <FILENAME>', 'Check the URLs in the exported FILENAME') do |f|
60
+ options.filename = f
61
+ options.operation = :check_from_file
62
+ end
63
+
64
+ opt.on('-R', '--reset', 'Reset the repositories to the current OS version.') do |v|
65
+ options.operation = :reset
66
+ end
67
+
57
68
  opt.on('-u', '--upgrade', 'Upgrade to the last version available') do |o|
58
69
  options.operation = :upgrade
59
70
  end
@@ -63,9 +74,18 @@ module Zypper
63
74
  options.operation = :upgrade_to
64
75
  end
65
76
 
77
+ opt.on('-F', '--upgrade-from-file <FILENAME>', 'Upgrade from FILENAME') do |f|
78
+ options.filename = f
79
+ options.operation = :upgrade_from_file
80
+ end
81
+
66
82
  opt.separator ''
67
83
  opt.separator 'Options:'
68
84
 
85
+ opt.on('--exit-on-fail', 'Exit with error when a repository upgrade check fails') do |o|
86
+ options.exit_on_fail = true
87
+ end
88
+
69
89
  opt.on('--only-enabled', 'Include only the enabled repositories') do |o|
70
90
  options.only_enabled = true
71
91
  end
@@ -109,6 +129,14 @@ module Zypper
109
129
  options.sort_by = :priority
110
130
  end
111
131
 
132
+ opt.on('--ini', 'Output the result in Ini format') do |o|
133
+ options.view = :ini
134
+ end
135
+
136
+ opt.on('--quiet', 'Quiet mode, show only error messages') do |o|
137
+ options.view = :quiet
138
+ end
139
+
112
140
  opt.on('--report', 'View the data as report') do |o|
113
141
  options.view = :report
114
142
  end
@@ -8,7 +8,7 @@ module Zypper
8
8
 
9
9
  attr_reader :custom
10
10
 
11
- OS_VERSIONS = ['13.1', '13.2', '42.1', '42.2', '42.3', '15.0', '15.1']
11
+ OS_VERSIONS = ['13.1', '13.2', '42.1', '42.2', '42.3', '15.0', '15.1', '15.2']
12
12
 
13
13
 
14
14
  def initialize(options)
@@ -112,13 +112,22 @@ module Zypper
112
112
  end
113
113
 
114
114
  def save
115
- raise InvalidPermissions, @filename unless File.writable? @filename
115
+ raise InvalidWritePermissions, @filename unless File.writable? @filename
116
+ process, pid = libzypp_process
117
+ raise SystemUpdateRunning, { pid: pid, process: process } if pid
116
118
  @repo.save(@filename)
117
119
  end
118
120
 
119
121
 
120
122
  private
121
123
 
124
+ def libzypp_process
125
+ libpath = `ldd /usr/bin/zypper | grep "libzypp.so"`.split(' => ')[1].split(' ').shift
126
+ process = `sudo lsof #{libpath} | tail -n 1`
127
+ process, pid = process.split(' ')
128
+ [process, pid]
129
+ end
130
+
122
131
  def get_key
123
132
  @repo.to_hash.keys.delete_if {|k| k == '0'}.pop
124
133
  end
@@ -164,7 +164,7 @@ module Zypper
164
164
  uri = URI(url)
165
165
  end
166
166
 
167
- uri.path = uri.path.gsub(/\/$/, '') + '/repodata/repomd.xml'
167
+ uri.path = uri.path.gsub(/\/$/, '') + '/repodata/repomd.xml'
168
168
 
169
169
  uri
170
170
  end
@@ -61,12 +61,36 @@ module Zypper
61
61
  end
62
62
  end
63
63
 
64
- class InvalidPermissions < StandardError
64
+ class InvalidWritePermissions < StandardError
65
65
  def initialize(filename)
66
66
  super "Don't have the right permission to write #{filename}"
67
67
  end
68
68
  end
69
69
 
70
+ class SystemUpdateRunning < StandardError
71
+ def initialize(args)
72
+ super "The application #{args[:process].bold} with pid #{args[:pid].bold} is running a system update!"
73
+ end
74
+ end
75
+
76
+ class UnableToUpgrade < StandardError
77
+ def initialize(args)
78
+ super "The repository n.#{args[:num].to_s.bold.red} named #{args[:repo].name.bold.red} can't be upgraded, a manual check is required!"
79
+ end
80
+ end
81
+
82
+ class MissingOverride < StandardError
83
+ def initialize(args)
84
+ super "The repository n.#{args[:num].to_s.bold.red} named #{args[:ini]['Name'].bold.red} doesn't contain the URL key!"
85
+ end
86
+ end
87
+
88
+ class UnmatchingOverrides < StandardError
89
+ def initialize(args)
90
+ super "The repository n.#{args[:num]} named #{args[:repo].name.bold.red} doesn't match with the repository named #{args[:ini]['Name'].bold.red} in the ini file"
91
+ end
92
+ end
93
+
70
94
  class AlreadyUpgraded < StandardError
71
95
  def initialize(version)
72
96
  super "The system is already upgraded to the #{version} version"
@@ -1,5 +1,5 @@
1
1
  module Zypper
2
2
  module Upgraderepo
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
@@ -34,11 +34,7 @@ module Zypper
34
34
  end
35
35
 
36
36
  def self.upgraded(num, repo, max_col)
37
- puts " #{num.to_s.rjust(2).bold.green} | #{'Upgraded'.bold.green}" #{'Upgraded from:'.bold.green} #{repo.old_url}"
38
- #puts " #{' ' * 2} | Old Name: #{old_data[:name].yellow}" if old_data[:name] != repo.name
39
- #puts " #{' ' * 2} | Old Alias: #{old_data[:alias].yellow}" if old_data[:alias] != repo.alias
40
-
41
- #puts " #{' ' * 2} | Old URL: #{repo.old_url}"
37
+ puts " #{num.to_s.rjust(2).bold.green} | #{'Upgraded'.bold.green}"
42
38
  self.info(repo)
43
39
  end
44
40
 
@@ -51,7 +47,7 @@ module Zypper
51
47
  puts '-' * 90
52
48
  end
53
49
 
54
- def self.header(max_col)
50
+ def self.header(max_col, upgrade = false)
55
51
  puts " # | Report"
56
52
  end
57
53
 
@@ -120,7 +116,101 @@ module Zypper
120
116
  end
121
117
  end
122
118
 
123
- end
124
119
 
120
+ class Quiet
121
+
122
+ def self.available(num, repo, max_col)
123
+ end
124
+
125
+ def self.redirected(num, repo, max_col, redirected)
126
+ end
127
+
128
+ def self.not_found(num, repo, max_col)
129
+ end
130
+
131
+ def self.alternative(num, repo, max_col, alt)
132
+ end
133
+
134
+ def self.timeout(num, repo, max_col)
135
+ end
136
+
137
+ def self.upgraded(num, repo, max_col) #, old_data)
138
+ end
139
+
140
+ def self.untouched(num, repo, max_col)
141
+ end
142
+
143
+ def self.separator
144
+ end
145
+
146
+ def self.header(max_col, upgrade = false)
147
+ end
148
+
149
+ def self.footer
150
+ end
151
+
152
+ end
153
+
154
+
155
+ class Ini
156
+
157
+ def self.available(num, repo, max_col)
158
+ self.info num, 'Ok', repo
159
+ end
160
+
161
+ def self.redirected(num, repo, max_col, redirected)
162
+ self.info num, 'Redirected', repo, false
163
+ puts "RedirectedTo=#{redirected}"
164
+ end
165
+
166
+ def self.not_found(num, repo, max_col)
167
+ self.info num, 'Not Found', repo, false
168
+ end
169
+
170
+ def self.alternative(num, repo, max_col, alt)
171
+ self.info num, 'Not Found', repo, false
172
+ puts "Hint=#{alt[:message]}"
173
+ puts "Suggested=#{alt[:url]}" unless alt[:url].to_s.empty?
174
+ end
175
+
176
+ def self.timeout(num, repo, max_col)
177
+ self.info num, 'Server Timeout', repo, false
178
+ end
179
+
180
+ def self.upgraded(num, repo, max_col)
181
+ self.info num, 'Upgraded', repo
182
+ end
183
+
184
+ def self.untouched(num, repo, max_col)
185
+ self.info num, 'Untouched', repo
186
+ end
187
+
188
+ def self.separator
189
+ puts ''
190
+ end
191
+
192
+ def self.header(max_col, upgrade = false)
193
+ end
194
+
195
+ def self.footer
196
+ end
197
+
198
+
199
+ private
200
+
201
+ def self.info(num, status, repo, valid = true)
202
+ @@number = num
203
+ puts "[Repository_#{num}]"
204
+ puts "Name=#{repo.name}"
205
+ puts "Alias=#{repo.alias}"
206
+ puts "OldURL=#{repo.old_url}"
207
+ puts "URL=#{repo.url}" if valid
208
+ puts "Priority=#{repo.priority}"
209
+ puts "Enabled=#{repo.enabled? ? 'Yes' : 'No'}"
210
+ puts "Status=#{status}"
211
+ end
212
+ end
213
+
214
+ end
125
215
  end
126
216
  end
@@ -31,8 +31,8 @@ Gem::Specification.new do |spec|
31
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
32
  spec.require_paths = ["lib"]
33
33
 
34
- spec.add_development_dependency "bundler", "~> 1.16"
35
- spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "bundler", "~> 2.0"
35
+ spec.add_development_dependency "rake", "~> 13.0"
36
36
  spec.add_development_dependency "rspec", "~> 3.0"
37
37
 
38
38
  spec.add_runtime_dependency "iniparse"
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.2.0
4
+ version: 1.3.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: 2018-12-20 00:00:00.000000000 Z
11
+ date: 2020-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -115,7 +115,7 @@ licenses:
115
115
  - GPL-3.0
116
116
  metadata:
117
117
  bug_tracker_uri: https://github.com/fabiomux/zypper-upgraderepo/issues
118
- documentation_uri: https://www.rubydoc.info/gems/zypper-upgraderepo/1.2.0
118
+ documentation_uri: https://www.rubydoc.info/gems/zypper-upgraderepo/1.3.0
119
119
  homepage_uri: https://github.com/fabiomux/zypper-upgraderepo
120
120
  source_code_uri: https://github.com/fabiomux/zypper-upgraderepo
121
121
  wiki_uri: https://github.com/fabiomux/zypper-upgraderepo/wiki
@@ -134,8 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  - !ruby/object:Gem::Version
135
135
  version: '0'
136
136
  requirements: []
137
- rubyforge_project:
138
- rubygems_version: 2.7.7
137
+ rubygems_version: 3.0.8
139
138
  signing_key:
140
139
  specification_version: 4
141
140
  summary: Zypper addon to check and upgrade local repositories.