zypper-upgraderepo 1.8.1 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +80 -0
- data/Gemfile +13 -1
- data/Gemfile.lock +50 -14
- data/README.md +5 -0
- data/Rakefile +7 -1
- data/lib/zypper/upgraderepo/cli.rb +93 -75
- data/lib/zypper/upgraderepo/os_release.rb +27 -29
- data/lib/zypper/upgraderepo/repository.rb +106 -84
- data/lib/zypper/upgraderepo/request.rb +16 -17
- data/lib/zypper/upgraderepo/requests/http.rb +52 -42
- data/lib/zypper/upgraderepo/requests/local.rb +28 -22
- data/lib/zypper/upgraderepo/traversable.rb +34 -32
- data/lib/zypper/upgraderepo/utils.rb +161 -44
- data/lib/zypper/upgraderepo/version.rb +3 -1
- data/lib/zypper/upgraderepo/view.rb +269 -154
- data/lib/zypper/upgraderepo.rb +73 -26
- data/zypper-upgraderepo.gemspec +25 -27
- metadata +10 -10
@@ -1,45 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Zypper
|
2
4
|
module Upgraderepo
|
3
|
-
|
5
|
+
#
|
6
|
+
# Mixin module that introduces the generic procedures
|
7
|
+
# used to traverse the repository path and query the
|
8
|
+
# system to discover wheter or not the upgraded folder
|
9
|
+
# exists.
|
10
|
+
#
|
4
11
|
module Traversable
|
5
|
-
|
6
12
|
def traverse_url(uri, version)
|
7
13
|
ping(uri)
|
8
14
|
|
9
|
-
if available? && !
|
10
|
-
return { url:
|
15
|
+
if available? && !repodata?(uri)
|
16
|
+
return { url: "", message: "This repository doesn't seem working and should be disabled." }
|
11
17
|
elsif forbidden?
|
12
|
-
res = { url: url, message:
|
18
|
+
res = { url: url, message: "Can't navigate through the repository!" }
|
13
19
|
elsif available? && uri.to_s =~ /#{version}/
|
14
20
|
res = traverse_url_forward(uri, version)
|
15
21
|
else
|
16
22
|
res = traverse_url_backward(uri, version)
|
17
23
|
end
|
18
24
|
|
19
|
-
res || { url:
|
25
|
+
res || { url: "", message: "Can't find a valid alternative, try manually!" }
|
20
26
|
end
|
21
27
|
|
22
|
-
|
23
28
|
private
|
24
29
|
|
25
30
|
def traverse_url_backward(uri, version)
|
26
31
|
uri.path = File.dirname(uri.path)
|
27
32
|
|
28
|
-
return nil if uri.path ==
|
33
|
+
return nil if uri.path == "/" || uri.path == "." || (versioned? && (drop_back_level(uri) > max_drop_back))
|
29
34
|
|
30
|
-
uri.path +=
|
31
|
-
ping(uri, false)
|
35
|
+
uri.path += "/" if uri.path[-1] != "/"
|
36
|
+
ping(uri, head: false)
|
32
37
|
|
33
38
|
if not_found?
|
34
39
|
return traverse_url_backward(uri, version)
|
35
40
|
elsif available?
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
+
res = traverse_url_forward(uri, version)
|
42
|
+
return res if res
|
43
|
+
|
44
|
+
return traverse_url_backward(uri, version)
|
45
|
+
|
41
46
|
elsif forbidden?
|
42
|
-
return { url: uri.to_s, message:
|
47
|
+
return { url: uri.to_s, message: "Try to replace with this one" } if repodata?(uri)
|
43
48
|
|
44
49
|
return traverse_url_backward(uri, version)
|
45
50
|
end
|
@@ -48,20 +53,18 @@ module Zypper
|
|
48
53
|
end
|
49
54
|
|
50
55
|
def traverse_url_forward(uri, version)
|
51
|
-
uri.path +=
|
52
|
-
ping(uri, false)
|
56
|
+
uri.path += "/" if uri.path[-1] != "/"
|
57
|
+
ping(uri, head: false)
|
53
58
|
|
54
59
|
subfolders(uri).each do |dir|
|
55
60
|
u = URI(uri.to_s)
|
56
61
|
u.path += dir
|
57
62
|
|
58
|
-
if
|
59
|
-
if
|
60
|
-
return { url: u.to_s, message: 'Override with this one' }
|
61
|
-
end
|
63
|
+
if repodata?(u)
|
64
|
+
return { url: u.to_s, message: "Override with this one" } if versioned? && (u.to_s =~ /#{version}/)
|
62
65
|
else
|
63
66
|
res = traverse_url_forward(u, version)
|
64
|
-
return res if res.
|
67
|
+
return res if res.instance_of?(Hash)
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
@@ -69,27 +72,26 @@ module Zypper
|
|
69
72
|
end
|
70
73
|
|
71
74
|
def repodata_uri(uri = nil)
|
72
|
-
if uri
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
75
|
+
uri = if uri
|
76
|
+
URI(uri.to_s)
|
77
|
+
else
|
78
|
+
URI(url)
|
79
|
+
end
|
77
80
|
|
78
|
-
uri.path = uri.path.gsub(
|
81
|
+
uri.path = "#{uri.path.gsub(%r{/$}, "")}/repodata/repomd.xml"
|
79
82
|
|
80
83
|
uri
|
81
84
|
end
|
82
85
|
|
83
86
|
def drop_back_level(uri)
|
84
|
-
URI(url).path.split(
|
87
|
+
URI(url).path.split("/").index { |x| x =~ /\d\d.\d/ } - uri.path.split("/").count
|
85
88
|
end
|
86
89
|
|
87
90
|
# to implement on each repository type class
|
88
91
|
#
|
89
|
-
# def
|
92
|
+
# def repodata?(uri)
|
90
93
|
#
|
91
94
|
# def subfolders
|
92
|
-
|
93
95
|
end
|
94
96
|
end
|
95
97
|
end
|
@@ -1,82 +1,174 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Zypper
|
4
|
+
#
|
5
|
+
# Collection of util classes.
|
6
|
+
#
|
2
7
|
module Upgraderepo
|
3
|
-
|
8
|
+
#
|
9
|
+
# String class patch.
|
10
|
+
#
|
4
11
|
class ::String
|
5
|
-
def black
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
def
|
12
|
+
def black
|
13
|
+
"\033[30m#{self}\033[0m"
|
14
|
+
end
|
15
|
+
|
16
|
+
def red
|
17
|
+
"\033[31m#{self}\033[0m"
|
18
|
+
end
|
19
|
+
|
20
|
+
def green
|
21
|
+
"\033[32m#{self}\033[0m"
|
22
|
+
end
|
23
|
+
|
24
|
+
def yellow
|
25
|
+
"\033[33m#{self}\033[0m"
|
26
|
+
end
|
27
|
+
|
28
|
+
def blue
|
29
|
+
"\033[34m#{self}\033[0m"
|
30
|
+
end
|
31
|
+
|
32
|
+
def magenta
|
33
|
+
"\033[35m#{self}\033[0m"
|
34
|
+
end
|
35
|
+
|
36
|
+
def cyan
|
37
|
+
"\033[36m#{self}\033[0m"
|
38
|
+
end
|
39
|
+
|
40
|
+
def gray
|
41
|
+
"\033[37m#{self}\033[0m"
|
42
|
+
end
|
43
|
+
|
44
|
+
def bg_black
|
45
|
+
"\033[40m#{self}\0330m"
|
46
|
+
end
|
47
|
+
|
48
|
+
def bg_red
|
49
|
+
"\033[41m#{self}\033[0m"
|
50
|
+
end
|
51
|
+
|
52
|
+
def bg_green
|
53
|
+
"\033[42m#{self}\033[0m"
|
54
|
+
end
|
55
|
+
|
56
|
+
def bg_brown
|
57
|
+
"\033[43m#{self}\033[0m"
|
58
|
+
end
|
59
|
+
|
60
|
+
def bg_blue
|
61
|
+
"\033[44m#{self}\033[0m"
|
62
|
+
end
|
63
|
+
|
64
|
+
def bg_magenta
|
65
|
+
"\033[45m#{self}\033[0m"
|
66
|
+
end
|
67
|
+
|
68
|
+
def bg_cyan
|
69
|
+
"\033[46m#{self}\033[0m"
|
70
|
+
end
|
71
|
+
|
72
|
+
def bg_gray
|
73
|
+
"\033[47m#{self}\033[0m"
|
74
|
+
end
|
75
|
+
|
76
|
+
def bold
|
77
|
+
"\033[1m#{self}\033[22m"
|
78
|
+
end
|
79
|
+
|
80
|
+
def reverse_color
|
81
|
+
"\033[7m#{self}\033[27m"
|
82
|
+
end
|
83
|
+
|
84
|
+
def cr
|
85
|
+
"\r#{self}"
|
86
|
+
end
|
87
|
+
|
88
|
+
def clean
|
89
|
+
"\e[K#{self}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def new_line
|
93
|
+
"\n#{self}"
|
94
|
+
end
|
95
|
+
|
96
|
+
def none
|
97
|
+
self
|
98
|
+
end
|
26
99
|
end
|
27
100
|
|
101
|
+
#
|
102
|
+
# Default error code.
|
103
|
+
#
|
28
104
|
class ::StandardError
|
29
105
|
def error_code
|
30
106
|
1
|
31
107
|
end
|
32
108
|
end
|
33
109
|
|
110
|
+
#
|
111
|
+
# Color the error message.
|
112
|
+
#
|
34
113
|
class Messages
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
STDERR.puts e.message =~ /\(/ ? e.message.gsub(/.*\((.*)\).*/, '\1').green : e.message.green
|
114
|
+
def self.error(err)
|
115
|
+
if err.instance_of?(String)
|
116
|
+
puts " [E] ".bold.red + err
|
117
|
+
elsif err.instance_of?(Interruption)
|
118
|
+
warn err.message =~ /\(/ ? err.message.gsub(/.*\((.*)\).*/, '\1').green : err.message.green
|
41
119
|
else
|
42
|
-
|
120
|
+
warn "Error! ".bold.red + err.message
|
43
121
|
end
|
44
122
|
end
|
45
123
|
|
46
|
-
def self.ok(
|
47
|
-
puts
|
124
|
+
def self.ok(msg)
|
125
|
+
puts " [V] ".bold.green + msg
|
48
126
|
end
|
49
127
|
|
50
|
-
def self.warning(
|
51
|
-
puts
|
128
|
+
def self.warning(msg)
|
129
|
+
puts " [W] ".bold.yellow + msg
|
52
130
|
end
|
53
|
-
|
54
131
|
end
|
55
132
|
|
133
|
+
#
|
134
|
+
# File not found error.
|
135
|
+
#
|
56
136
|
class FileNotFound < StandardError
|
57
137
|
def initialize(filename)
|
58
138
|
super "The File #{filename} doesn't exist."
|
59
139
|
end
|
60
140
|
end
|
61
141
|
|
142
|
+
#
|
143
|
+
# Osrelease file not found.
|
144
|
+
#
|
62
145
|
class ReleaseFileNotFound < StandardError
|
63
146
|
def initialize
|
64
|
-
super
|
147
|
+
super "The release file is not found."
|
65
148
|
end
|
66
149
|
end
|
67
150
|
|
151
|
+
#
|
152
|
+
# Invalid repository protocol.
|
153
|
+
#
|
68
154
|
class InvalidProtocol < StandardError
|
69
155
|
def initialize(repo)
|
70
156
|
super "The repository #{repo.name} has an unknown protocol: #{repo.protocol}; disable it to continue."
|
71
157
|
end
|
72
158
|
end
|
73
159
|
|
160
|
+
#
|
161
|
+
# Invalid release version.
|
162
|
+
#
|
74
163
|
class InvalidVersion < StandardError
|
75
164
|
def initialize(version)
|
76
165
|
super "The version #{version} is not valid"
|
77
166
|
end
|
78
167
|
end
|
79
168
|
|
169
|
+
#
|
170
|
+
# Repository file writing not allowed.
|
171
|
+
#
|
80
172
|
class InvalidWritePermissions < StandardError
|
81
173
|
def initialize(filename)
|
82
174
|
super "Don't have the right permission to write #{filename}"
|
@@ -87,6 +179,9 @@ module Zypper
|
|
87
179
|
end
|
88
180
|
end
|
89
181
|
|
182
|
+
#
|
183
|
+
# An application is running an update.
|
184
|
+
#
|
90
185
|
class SystemUpdateRunning < StandardError
|
91
186
|
def initialize(args)
|
92
187
|
super "The application #{args[:process].bold} with pid #{args[:pid].bold} is running a system update!"
|
@@ -97,9 +192,13 @@ module Zypper
|
|
97
192
|
end
|
98
193
|
end
|
99
194
|
|
195
|
+
#
|
196
|
+
# The repository URL can't be interpolated.
|
197
|
+
#
|
100
198
|
class UnableToUpgrade < StandardError
|
101
199
|
def initialize(args)
|
102
|
-
super "The repository n.#{args[:num].to_s.bold.red} named #{args[:repo].name.bold.red}
|
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!"
|
103
202
|
end
|
104
203
|
|
105
204
|
def error_code
|
@@ -107,9 +206,13 @@ module Zypper
|
|
107
206
|
end
|
108
207
|
end
|
109
208
|
|
209
|
+
#
|
210
|
+
# Repository with missing URL.
|
211
|
+
#
|
110
212
|
class MissingOverride < StandardError
|
111
213
|
def initialize(args)
|
112
|
-
super "The repository n.#{args[:num].to_s.bold.red} named #{args[:ini][
|
214
|
+
super "The repository n.#{args[:num].to_s.bold.red} named #{args[:ini]["name"].bold.red} " \
|
215
|
+
"doesn't contain the URL key!"
|
113
216
|
end
|
114
217
|
|
115
218
|
def error_code
|
@@ -117,9 +220,13 @@ module Zypper
|
|
117
220
|
end
|
118
221
|
end
|
119
222
|
|
223
|
+
#
|
224
|
+
# Repository overrides failure.
|
225
|
+
#
|
120
226
|
class UnmatchingOverrides < StandardError
|
121
227
|
def initialize(args)
|
122
|
-
super "The repository n.#{args[:num]} named #{args[:repo].name.bold.red} doesn't match with
|
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"
|
123
230
|
end
|
124
231
|
|
125
232
|
def error_code
|
@@ -127,6 +234,9 @@ module Zypper
|
|
127
234
|
end
|
128
235
|
end
|
129
236
|
|
237
|
+
#
|
238
|
+
# The system doesn't require any upgrade.
|
239
|
+
#
|
130
240
|
class AlreadyUpgraded < StandardError
|
131
241
|
def initialize(version)
|
132
242
|
super "The system is already upgraded to the #{version} version"
|
@@ -137,9 +247,12 @@ module Zypper
|
|
137
247
|
end
|
138
248
|
end
|
139
249
|
|
250
|
+
#
|
251
|
+
# There are not unstable versions,
|
252
|
+
#
|
140
253
|
class NoUnstableVersionAvailable < StandardError
|
141
254
|
def initialize
|
142
|
-
super
|
255
|
+
super "No unstable version is available, remove the --allow-unstable switch to continue"
|
143
256
|
end
|
144
257
|
|
145
258
|
def error_code
|
@@ -147,9 +260,11 @@ module Zypper
|
|
147
260
|
end
|
148
261
|
end
|
149
262
|
|
263
|
+
#
|
264
|
+
# No internet connection.
|
150
265
|
class NoConnection < StandardError
|
151
266
|
def initialize
|
152
|
-
super
|
267
|
+
super "Internet connection has some trouble"
|
153
268
|
end
|
154
269
|
|
155
270
|
def error_code
|
@@ -157,14 +272,16 @@ module Zypper
|
|
157
272
|
end
|
158
273
|
end
|
159
274
|
|
275
|
+
#
|
276
|
+
# Ctrl + C message error.
|
277
|
+
#
|
160
278
|
class Interruption < StandardError
|
161
279
|
def initialize
|
162
|
-
super
|
280
|
+
super "Ok ok... Exiting!"
|
163
281
|
end
|
164
282
|
end
|
165
283
|
|
166
|
-
Signal.trap(
|
167
|
-
|
168
|
-
Signal.trap('TERM') { raise Interruption }
|
284
|
+
Signal.trap("INT") { raise Interruption }
|
285
|
+
Signal.trap("TERM") { raise Interruption }
|
169
286
|
end
|
170
287
|
end
|