zypper-upgraderepo 1.8.0 → 1.9.0

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