zypper-upgraderepo 1.0.2 → 1.1.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: 25eb50066963aad6a37ce7c2d79410d0ef30a68e8dbc302e4a09f6c9589c15de
4
- data.tar.gz: ca2e0b7855cbd47ff45d41daef4ec3907e9813df77ead0ddd8e32fd37e4ff486
3
+ metadata.gz: d9e0bb83e66c339eaffe198c509e835a565db6075ab6afedd75eb5816c5176ce
4
+ data.tar.gz: 79f79f8f2fc1cdbea708cb5bf02d25b82d4be4ca83630962c02cdc01870b72d9
5
5
  SHA512:
6
- metadata.gz: e5c58c0ea4564541da066b599c9e882015e019328c84330f0bad4ccb3dcf99089628a40a9a1b5d3b0661996db86ce99c85d71d77138a765cfcabb313a888c098
7
- data.tar.gz: 6e4e59b92565921be94f45bc59efb7713cad2a5c40ce60096dd95195cc58401100411837470de7d76d0480d2284958f78a388bbd1f6135ade279a59d66e30cb0
6
+ metadata.gz: f4babf4d20fecf1d1306e1411ee28e2026ec1214523f879a99107982b0b62bbce621e61da4fa77f7b9c73799238001bee26978bc47a47a9bdadc92c49b0aa87d
7
+ data.tar.gz: 6bf20f0c92d33e58cf1fc088b4130c9ea3704b13b1ec2667cf6a859329573cf9a451b1f78a15cfac245c173ca23aaea1d509398a1006cb6a0df9d2e767f09cfe
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zypper-upgraderepo (1.0.2)
4
+ zypper-upgraderepo (1.1.0)
5
5
  iniparse
6
6
  minitar
7
7
 
data/README.md CHANGED
@@ -17,15 +17,15 @@ If you want to install it as zypper plugin watch the _zypper-upgraderepo-plugin_
17
17
 
18
18
  To check the availability of the current repositories:
19
19
 
20
- $ zypper-upgraderepo -c
20
+ $ zypper-upgraderepo --check-current
21
21
 
22
22
  To check the availability of the next version repositories:
23
23
 
24
- $ zypper-upgraderepo -n
24
+ $ zypper-upgraderepo --check-next
25
25
 
26
26
  To upgrade the repositories to the next version:
27
27
 
28
- $ sudo zypper-upgraderepo -u
28
+ $ sudo zypper-upgraderepo --upgrade
29
29
 
30
30
  ## Get help
31
31
 
@@ -36,6 +36,10 @@ Where to start:
36
36
  More Help:
37
37
 
38
38
  - The wiki page: https://github.com/fabiomux/zypper-upgraderepo
39
+ - openSUSE Lizards: https://lizards.opensuse.org/2018/08/07/zypper-upgraderepo-plugin-is-here/
40
+
41
+ ## Related projects
42
+
39
43
  - zypper-upgraderepo-plugin project: https://github.com/fabiomux/zypper-upgraderepo-plugin
40
44
 
41
45
  ## Contributing
@@ -11,6 +11,7 @@ module Zypper
11
11
  @os_release = OsRelease.new(options)
12
12
  @repos = RepositoryList.new(options)
13
13
  @print_hint = options.hint
14
+ @view_class = Object.const_get options.view.to_s.split(' ').map(&:capitalize).insert(0,'Zypper::Upgraderepo::').push('View').join
14
15
  end
15
16
 
16
17
  def backup
@@ -23,7 +24,8 @@ module Zypper
23
24
  end
24
25
 
25
26
  def check_next
26
- @repos.upgrade(@os_release.next) unless @os_release.last?
27
+ raise AlreadyUpgraded, 'latest' if @os_release.last?
28
+ @repos.upgrade(@os_release.next)
27
29
  check_repos(@os_release.next)
28
30
  end
29
31
 
@@ -33,7 +35,8 @@ module Zypper
33
35
  end
34
36
 
35
37
  def upgrade
36
- @repos.upgrade(@os_release.next) unless @os_release.last?
38
+ raise AlreadyUpgraded, 'latest' if @os_release.last?
39
+ @repos.upgrade(@os_release.next)
37
40
  @repos.save
38
41
  Messages.ok 'Repositories upgraded!'
39
42
  end
@@ -48,22 +51,25 @@ module Zypper
48
51
  private
49
52
 
50
53
  def check_repos(version)
51
- Messages.header(@repos.max_col)
54
+ @view_class.header(@repos.max_col)
55
+
52
56
  @repos.list.each_with_index do |r, i|
53
- Messages.separator
57
+ @view_class.separator
58
+
54
59
  if r.available?
55
- Messages.available i.next, r.name, r.url, @repos.max_col
60
+ @view_class.available i.next, r, @repos.max_col
56
61
  elsif r.redirected?
57
- Messages.redirected i.next, r.name, r.url, @repos.max_col, r.redirected_to
62
+ @view_class.redirected i.next, r, @repos.max_col, r.redirected_to
58
63
  elsif r.not_found?
59
64
  if @print_hint
60
- Messages.alternative i.next, r.name, r.url, @repos.max_col, r.evaluate_alternative(version)
65
+ @view_class.alternative i.next, r, @repos.max_col, r.evaluate_alternative(version)
61
66
  else
62
- Messages.not_found i.next, r.name, r.url, @repos.max_col
67
+ @view_class.not_found i.next, r, @repos.max_col
63
68
  end
64
69
  end
65
70
  end
66
- Messages.footer
71
+
72
+ @view_class.footer
67
73
  end
68
74
 
69
75
  end
@@ -13,12 +13,14 @@ module Zypper
13
13
  options = OpenStruct.new
14
14
  options.operation = :check_current
15
15
  options.backup_path = ENV['HOME']
16
- options.only_enabled = true
16
+ options.only_enabled = false
17
17
  options.alias = true
18
18
  options.name = true
19
19
  options.hint = true
20
20
  options.overrides = {}
21
21
  options.version = nil
22
+ options.sort_by = :alias
23
+ options.view = :table
22
24
 
23
25
  opt_parser = OptionParser.new do |opt|
24
26
 
@@ -82,6 +84,22 @@ module Zypper
82
84
  options.overrides[r[0]] = r[1]
83
85
  end
84
86
 
87
+ opt.on('--sort-by-alias', 'Sort repositories by alias (Default)') do |o|
88
+ options.sort_by = :alias
89
+ end
90
+
91
+ opt.on('--sort-by-name', 'Sort repositories by name') do |o|
92
+ options.sort_by = :name
93
+ end
94
+
95
+ opt.on('--sort-by-priority', 'Sort repositories by priority') do |o|
96
+ options.sort_by = :priority
97
+ end
98
+
99
+ opt.on('--report-view', 'View the data as report') do |o|
100
+ options.view = :report
101
+ end
102
+
85
103
  unless ENV['ZYPPER_UPGRADEREPO']
86
104
  opt.separator ''
87
105
  opt.separator 'Other:'
@@ -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']
11
+ OS_VERSIONS = ['13.1', '13.2', '42.1', '42.2', '42.3', '15.0', '15.1']
12
12
 
13
13
 
14
14
  def initialize(options)
@@ -17,12 +17,15 @@ module Zypper
17
17
  @list = []
18
18
  @backup_path = options.backup_path
19
19
 
20
- Dir.glob('/etc/zypp/repos.d/*.repo').sort.each do |i|
20
+ Dir.glob('/etc/zypp/repos.d/*.repo').each do |i|
21
21
  r = Repository.new(i)
22
22
  next if options.only_enabled && (!r.enabled?)
23
23
  @list << r
24
24
  end
25
25
  @max_col = @list.max_by { |x| x.name.length }.name.length
26
+
27
+ @list.sort_by! { |x| x.alias }
28
+ @list.sort_by! { |x| x.send(options.sort_by) } if options.sort_by != :alias
26
29
  end
27
30
 
28
31
  def backup
@@ -78,6 +81,10 @@ module Zypper
78
81
  @repo[@key]['name'] = value
79
82
  end
80
83
 
84
+ def priority
85
+ @repo[@key]['priority'] || 99
86
+ end
87
+
81
88
  def url
82
89
  @repo[@key]['baseurl']
83
90
  end
@@ -152,20 +159,52 @@ module Zypper
152
159
  if not_found?
153
160
  return traverse_url(uri, version)
154
161
  elsif available?
155
- return {url: uri.to_s, message: 'Override with this one' } if uri.path =~ Regexp.new(version)
162
+ return {url: uri.to_s, message: 'Override with this one' } if uri.path =~ Regexp.new(version) && !search_repo(version).empty?
156
163
 
157
- path = ping.body.to_s.scan(Regexp.new("href=\"[^\"]*#{version}[^\"]*\"")).uniq
158
- unless path.empty?
159
- uri.path += "#{path.pop.scan(/href="(.*)"/).pop.pop }"
164
+ path = search_path(version)
165
+ if path.empty?
166
+ return traverse_url(uri, version)
167
+ else
168
+ return traverse_url_forward(uri, version) if search_repo(version).empty?
169
+
170
+ uri.path += extract_path(path)
160
171
  return {url: uri.to_s, message: 'Override with this one' }
161
172
  end
162
173
 
163
- return {url: url, message: 'Can\'t find anything similar, try manually!' }
164
174
  end
165
175
 
166
176
  end
167
- end
168
177
 
178
+ def traverse_url_forward(uri, version)
179
+ ping(uri, true)
180
+
181
+ if search_repo(version).empty?
182
+
183
+ path = search_path(version)
184
+ if path.empty?
185
+ return {url: '', message: 'Can\'t find anything similar, try manually!' }
186
+ else
187
+ uri.path += extract_path(path)
188
+ return traverse_url_forward(uri, version)
189
+ end
190
+ else
191
+ return {url: uri.to_s, message: 'Override with this one' }
192
+ end
193
+ end
194
+
195
+ def search_path(version)
196
+ ping.body.to_s.scan(Regexp.new("href=\"[^\"]*#{version}[^\"]*\"")).delete_if { |x| x =~ Regexp.new("\"#{URI(url).path}\"") }.uniq
197
+ end
198
+
199
+ def search_repo(version)
200
+ ping.body.to_s.scan(Regexp.new("href=\"[^\"]*#{version}[^\"]*\.repo\"|repodata/")).uniq
201
+ end
202
+
203
+ def extract_path(path)
204
+ "#{path.pop.scan(/href="(.*)"/).pop.pop}"
205
+ end
206
+
207
+ end
169
208
 
170
209
  end
171
210
  end
@@ -44,22 +44,26 @@ module Zypper
44
44
  puts ' [W] '.bold.yellow + m
45
45
  end
46
46
 
47
- def self.available(num, name, url, max_col)
48
- Messages.ok("| #{num.to_s.rjust(2)} | #{name.ljust(max_col, ' ')} |")
47
+ end
48
+
49
+ class TableView
50
+
51
+ def self.available(num, repo, max_col)
52
+ Messages.ok("| #{num.to_s.rjust(2)} | #{repo.name.ljust(max_col, ' ')} | #{repo.enabled? ? ' Y ' : ' N '.yellow} |")
49
53
  end
50
54
 
51
- def self.redirected(num, name, url, max_col, redirected)
52
- Messages.warning("| #{num.to_s.rjust(2)} | #{name.ljust(max_col, ' ')} | Redirection of #{url} ")
53
- puts " #{' ' * 3} | #{' ' * 2} | #{ ' ' * max_col} | #{'To:'.bold.yellow} #{redirected}"
55
+ def self.redirected(num, repo, max_col, redirected)
56
+ Messages.warning("| #{num.to_s.rjust(2)} | #{repo.name.ljust(max_col, ' ')} | #{repo.enabled? ? ' Y ' : ' N '.yellow} | #{'Redirection'.bold.yellow} of #{repo.url} ")
57
+ puts " #{' ' * 3} | #{' ' * 2} | #{ ' ' * max_col} | #{ ' ' * 3 } | #{'To:'.bold.yellow} #{redirected}"
54
58
  end
55
59
 
56
- def self.not_found(num, name, url, max_col)
57
- Messages.error("| #{num.to_s.rjust(2)} | #{name.ljust(max_col, ' ')}")
60
+ def self.not_found(num, repo, max_col)
61
+ Messages.error("| #{num.to_s.rjust(2)} | #{repo.name.ljust(max_col, ' ')} | #{repo.enabled? ? ' Y ' : ' N '.yellow} |")
58
62
  end
59
63
 
60
- def self.alternative(num, name, url, max_col, res)
61
- Messages.error("| #{num.to_s.rjust(2)} | #{name.ljust(max_col, ' ')} | #{res[:message].bold.yellow}")
62
- puts " #{' ' * 3} | #{' ' * 2} | #{' ' * max_col} | #{res[:url]}" unless res[:url].to_s.empty?
64
+ def self.alternative(num, repo, max_col, alt)
65
+ Messages.error("| #{num.to_s.rjust(2)} | #{repo.name.ljust(max_col, ' ')} | #{repo.enabled? ? ' Y ' : ' N '.yellow} | #{alt[:message].bold.yellow}")
66
+ puts " #{' ' * 3} | #{' ' * 2} | #{' ' * max_col} | #{' ' * 3} | #{alt[:url]}" unless alt[:url].to_s.empty?
63
67
  end
64
68
 
65
69
  def self.separator
@@ -67,7 +71,7 @@ module Zypper
67
71
  end
68
72
 
69
73
  def self.header(max_col)
70
- puts " St. | # | #{'Name'.ljust(max_col, ' ')} | Hint"
74
+ puts " St. | # | #{'Name'.ljust(max_col, ' ')} | En. | Hint"
71
75
  end
72
76
 
73
77
  def self.footer
@@ -76,6 +80,56 @@ module Zypper
76
80
  end
77
81
 
78
82
 
83
+ class ReportView
84
+
85
+ def self.available(num, repo, max_col)
86
+ puts " #{num.to_s.rjust(2).bold.green} | Status: #{'Ok'.bold.green}"
87
+ self.info(repo)
88
+ end
89
+
90
+ def self.redirected(num, repo, max_col, redirected)
91
+ puts " #{num.to_s.rjust(2).bold.yellow} | Status: #{'Redirected'.bold.yellow}"
92
+ puts " #{' ' * 2} | #{'To:'.bold.yellow} #{redirected}"
93
+ self.info(repo)
94
+ end
95
+
96
+ def self.not_found(num, repo, max_col)
97
+ puts " #{num.to_s.rjust(2).bold.red} | Status: #{'Not Found'.bold.red}"
98
+ self.info(repo)
99
+ end
100
+
101
+ def self.alternative(num, repo, max_col, alt)
102
+ puts " #{num.to_s.rjust(2).bold.red} | Status: #{'Not Found'.bold.red}"
103
+ puts " #{' ' * 2} | Hint: #{alt[:message].bold.yellow}"
104
+ puts " #{' ' * 2} | #{'Suggested:'.bold.yellow} #{alt[:url]}" unless alt[:url].to_s.empty?
105
+ self.info(repo)
106
+ end
107
+
108
+ def self.separator
109
+ puts '-' * 90
110
+ end
111
+
112
+ def self.header(max_col)
113
+ puts " # | Report"
114
+ end
115
+
116
+ def self.footer
117
+ self.separator
118
+ end
119
+
120
+ private
121
+
122
+ def self.info(repo)
123
+ puts " #{ ' ' * 2 } | Name: #{repo.name}"
124
+ puts " #{ ' ' * 2 } | Alias: #{repo.alias}"
125
+ puts " #{ ' ' * 2 } | Url: #{repo.url}"
126
+ puts " #{ ' ' * 2 } | Priority: #{repo.priority}"
127
+ puts " #{ ' ' * 2 } | #{repo.enabled? ? 'Enabled: Yes' : 'Enabled: No'.yellow}"
128
+ puts " #{ ' ' * 2 } | Filename: #{repo.filename}"
129
+ end
130
+ end
131
+
132
+
79
133
  class ReleaseFileNotFound < StandardError
80
134
  def initialize
81
135
  super 'The release file is not found.'
@@ -96,7 +150,7 @@ module Zypper
96
150
 
97
151
  class AlreadyUpgraded < StandardError
98
152
  def initialize(version)
99
- super "The system is already upgraded to #{version}"
153
+ super "The system is already upgraded to the #{version} version"
100
154
  end
101
155
  end
102
156
 
@@ -1,5 +1,5 @@
1
1
  module Zypper
2
2
  module Upgraderepo
3
- VERSION = "1.0.2"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
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.0.2
4
+ version: 1.1.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-08-21 00:00:00.000000000 Z
11
+ date: 2018-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -113,7 +113,7 @@ licenses:
113
113
  - GPL-3.0
114
114
  metadata:
115
115
  bug_tracker_uri: https://github.com/fabiomux/zypper-upgraderepo/issues
116
- documentation_uri: https://www.rubydoc.info/gems/zypper-upgraderepo/1.0.2
116
+ documentation_uri: https://www.rubydoc.info/gems/zypper-upgraderepo/1.1.0
117
117
  homepage_uri: https://github.com/fabiomux/zypper-upgraderepo
118
118
  source_code_uri: https://github.com/fabiomux/zypper-upgraderepo
119
119
  wiki_uri: https://github.com/fabiomux/zypper-upgraderepo/wiki