zypper-upgraderepo 1.0.1 → 1.4.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
- SHA1:
3
- metadata.gz: 27e53665796d2910957b34e8669b7fad8a829487
4
- data.tar.gz: 106b9d14dee4c7032db264d912d6b9d87aa3845e
2
+ SHA256:
3
+ metadata.gz: d4760ab0872714ea6449ab9f0ece3864e26c8c240f9b11633006fb12dd817499
4
+ data.tar.gz: 20adbb9f4e555758247171702c7adbd3513f94025cb4f02259b9c9fd2ed58de4
5
5
  SHA512:
6
- metadata.gz: 56913603985714e675afcf454dce13833ea4f2679703be415212fe1969e0882db81c2db6c6beea09cb1828d26ffcdc0186a969691c5d8c7ee9e2759ff562ec86
7
- data.tar.gz: f578d00830d05996a4a34c13f83cd019fbd5f6ce97f59fd8c64e703a6af0833b83a8e0e123256310c80af3622f87a19485f6e83453c1b0bed784295bdb360a08
6
+ metadata.gz: 8450283c28d80056aa8f9bc7c97f40e7778a728b200b04dacf38cd3697ab76da59332314f4de5d23328e11283d9365088d9d212cb5cfdab837b2954d306cb87e
7
+ data.tar.gz: 478fdd3fa080ae63049b077bc8ddf73a5d1d87655da3a1c17f0588c944766b09aba44b5f6b62ecbdd62cc641e7dcf0486a4a45ae25e04773502c3c99acc8546f
@@ -0,0 +1,13 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [fabiomux]
4
+ #patreon: # Replace with a single Patreon username
5
+ #open_collective: # Replace with a single Open Collective username
6
+ #ko_fi: # Replace with a single Ko-fi username
7
+ #tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
+ #community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ #liberapay: # Replace with a single Liberapay username
10
+ #issuehunt: # Replace with a single IssueHunt username
11
+ #otechie: # Replace with a single Otechie username
12
+ #custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
13
+ custom: ['https://www.buymeacoffee.com/DCkNYFg']
@@ -1,39 +1,39 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zypper-upgraderepo (1.0.1)
4
+ zypper-upgraderepo (1.4.0)
5
5
  iniparse
6
6
  minitar
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
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)
11
+ diff-lcs (1.4.4)
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.2)
20
+ rspec-support (~> 3.9.3)
21
+ rspec-expectations (3.9.2)
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.3)
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.16.2
39
+ 2.1.4
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
@@ -1,6 +1,10 @@
1
1
  require 'zypper/upgraderepo/repository'
2
+ require 'zypper/upgraderepo/request'
2
3
  require 'zypper/upgraderepo/os_release'
3
4
  require 'zypper/upgraderepo/utils'
5
+ require 'zypper/upgraderepo/view'
6
+ require 'zlib'
7
+ require 'minitar'
4
8
 
5
9
 
6
10
  module Zypper
@@ -11,11 +15,21 @@ module Zypper
11
15
  @os_release = OsRelease.new(options)
12
16
  @repos = RepositoryList.new(options)
13
17
  @print_hint = options.hint
18
+ @view_class = Zypper::Upgraderepo::View.const_get options.view.to_s.capitalize
19
+
20
+ @backup_path = options.backup_path
21
+
22
+ @exit_on_fail = options.exit_on_fail
14
23
  end
15
24
 
16
25
  def backup
17
- @repos.backup
18
- Messages.ok 'Repository backup executed!'
26
+ filename = File.join(@backup_path, "repos-backup-#{Time.now.to_s.delete(': +-')[0..-5]}.tgz")
27
+
28
+ raise InvalidWritePermissions, filename unless File.writable? @backup_path
29
+
30
+ Minitar.pack(RepositoryList::REPOSITORY_PATH, Zlib::GzipWriter.new(File.open(filename, 'wb')))
31
+
32
+ Messages.ok "Backup file generated at #{filename.bold.green}"
19
33
  end
20
34
 
21
35
  def check_current
@@ -23,47 +37,81 @@ module Zypper
23
37
  end
24
38
 
25
39
  def check_next
26
- @repos.upgrade(@os_release.next) unless @os_release.last?
40
+ raise AlreadyUpgraded, 'latest' if @os_release.last?
41
+ @repos.upgrade!(@os_release.next)
27
42
  check_repos(@os_release.next)
28
43
  end
29
44
 
30
45
  def check_to
31
- @repos.upgrade(@os_release.custom)
46
+ @repos.upgrade!(@os_release.custom)
32
47
  check_repos(@os_release.custom)
33
48
  end
34
49
 
35
50
  def upgrade
36
- @repos.upgrade(@os_release.next) unless @os_release.last?
37
- @repos.save
38
- Messages.ok 'Repositories upgraded!'
51
+ raise AlreadyUpgraded, 'latest' if @os_release.last?
52
+ @repos.upgrade!(@os_release.next)
53
+ upgrade_repos(@os_release.next)
39
54
  end
40
55
 
41
56
  def upgrade_to
42
- @repos.upgrade(@os_release.custom)
43
- @repos.save
44
- Messages.ok 'Repositories upgraded!'
57
+ raise AlreadyUpgraded, @os_release.custom if @os_release.current?(@os_release.custom)
58
+ @repos.upgrade!(@os_release.custom)
59
+ upgrade_repos(@os_release.custom)
60
+ end
61
+
62
+ def reset
63
+ upgrade_repos(@os_release.current)
45
64
  end
46
65
 
47
66
 
48
67
  private
49
68
 
50
69
  def check_repos(version)
51
- Messages.header(@repos.max_col)
52
- @repos.list.each_with_index do |r, i|
53
- Messages.separator
54
- if r.available?
55
- Messages.available i.next, r.name, r.url, @repos.max_col
56
- elsif r.redirected?
57
- Messages.redirect i.next, r.name, r.url, @repos.max_col, r.redirected_to
58
- elsif r.not_found?
59
- if @print_hint
60
- Messages.alternative i.next, r.name, r.url, @repos.max_col, r.evaluate_alternative(version)
61
- else
62
- Messages.not_found i.next, r.name, r.url, @repos.max_col
70
+ @view_class.header(@repos.max_col)
71
+
72
+ @repos.each_with_number do |repo, num|
73
+
74
+ @view_class.separator
75
+
76
+ if repo.available?
77
+ @view_class.available num, repo, @repos.max_col
78
+ else
79
+ raise UnableToUpgrade, { num: num, repo: repo } if @exit_on_fail
80
+ if repo.redirected?
81
+ @view_class.redirected num, repo, @repos.max_col, repo.redirected_to
82
+ elsif repo.not_found?
83
+ if @print_hint
84
+ @view_class.alternative num, repo, @repos.max_col, repo.evaluate_alternative(version)
85
+ else
86
+ @view_class.not_found num, repo, @repos.max_col
87
+ end
88
+ elsif repo.timeout?
89
+ @view_class.timeout num, repo, @repos.max_col
63
90
  end
64
91
  end
65
92
  end
66
- Messages.footer
93
+
94
+ @view_class.footer
95
+ end
96
+
97
+ def upgrade_repos(version)
98
+ @view_class.header(@repos.max_col, true)
99
+
100
+ @repos.each_with_number do |repo, num|
101
+
102
+ @view_class.separator
103
+
104
+ if repo.upgraded?
105
+ @view_class.upgraded num, repo, @repos.max_col
106
+ else
107
+ @view_class.untouched num, repo, @repos.max_col
108
+ end
109
+ end
110
+
111
+ @view_class.separator
112
+
113
+ @repos.save
114
+ Messages.ok 'Repositories upgraded!'
67
115
  end
68
116
 
69
117
  end
@@ -13,14 +13,21 @@ 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
-
23
- OptionParser.new do |opt|
22
+ options.sort_by = :alias
23
+ options.view = :table
24
+ options.only_repo = nil
25
+ options.timeout = 10.0
26
+ options.exit_on_fail = false
27
+ options.overrides_filename = nil
28
+ options.only_invalid = false
29
+
30
+ opt_parser = OptionParser.new do |opt|
24
31
 
25
32
  if ENV['ZYPPER_UPGRADEREPO']
26
33
  opt.banner = 'Usage: zypper upgraderepo [OPTIONS] [OPERATION]'
@@ -50,6 +57,10 @@ module Zypper
50
57
  options.operation = :check_to
51
58
  end
52
59
 
60
+ opt.on('-R', '--reset', 'Reset the repositories to the current OS version.') do |v|
61
+ options.operation = :reset
62
+ end
63
+
53
64
  opt.on('-u', '--upgrade', 'Upgrade to the last version available') do |o|
54
65
  options.operation = :upgrade
55
66
  end
@@ -62,26 +73,77 @@ module Zypper
62
73
  opt.separator ''
63
74
  opt.separator 'Options:'
64
75
 
65
- opt.on('--[no-]only-enabled', 'Include or not the disabled repositories') do |o|
66
- options.only_enabled = o
76
+ opt.on('--no-name', 'Don\'t upgrade the name') do |o|
77
+ options.name = false
78
+ end
79
+
80
+ opt.on('--no-alias', 'Don\'t upgrade the alias') do |o|
81
+ options.alias = false
82
+ end
83
+
84
+ opt.on('--no-hint', 'Don\'t find a working URL when the current is invalid') do |o|
85
+ options.hint = false
86
+ end
87
+
88
+ opt.on('--override-url <NUMBER>,<URL>', Array, 'Overwrite the repository NUMBER with URL') do |r|
89
+ options.overrides[r[0].to_i] = r[1]
90
+ end
91
+
92
+ opt.on('--load-overrides <FILENAME>', 'Check the URLs in the exported FILENAME') do |f|
93
+ options.overrides_filename = f
94
+ end
95
+
96
+ opt.on('--exit-on-fail', 'Exit with error when a repository upgrade check fails') do |o|
97
+ options.exit_on_fail = true
67
98
  end
68
99
 
69
- opt.on('--[no-]name', 'Upgrade or not the name') do |o|
70
- options.name = o
100
+ opt.on('--timeout <SECONDS>', "Adjust the waiting SECONDS used to catch an HTTP Timeout Error (Default: #{options.timeout})") do |o|
101
+ options.timeout = o.to_f
71
102
  end
72
103
 
73
- opt.on('--[no-]alias', 'Upgrade or not the alias') do |o|
74
- options.alias = o
104
+ opt.separator ''
105
+ opt.separator 'Filter options:'
106
+
107
+ opt.on('--only-enabled', 'Include only the enabled repositories') do |o|
108
+ options.only_enabled = true
75
109
  end
76
110
 
77
- opt.on('--[no-]hint', 'Suggest a new url when the current is not found') do |o|
78
- options.hint = o
111
+ opt.on('--only-repo <NUMBER>[,NUMBER2,...]', 'Include only the repositories specified by NUMBER') do |o|
112
+ options.only_repo = o.split(',').map(&:to_i)
79
113
  end
80
114
 
81
- opt.on('--override-url <NUMBER>,<URL>', Array, 'Overwrite the repository\'s url NUMBER with URL') do |r|
82
- options.overrides[r[0]] = r[1]
115
+ opt.on('--only-invalid', 'Show only invalid repositories') do |o|
116
+ options.only_invalid = true
83
117
  end
84
118
 
119
+ opt.separator ''
120
+ opt.separator 'View options:'
121
+
122
+ opt.on('--sort-by-alias', 'Sort repositories by alias (Default)') do |o|
123
+ options.sort_by = :alias
124
+ end
125
+
126
+ opt.on('--sort-by-name', 'Sort repositories by name') do |o|
127
+ options.sort_by = :name
128
+ end
129
+
130
+ opt.on('--sort-by-priority', 'Sort repositories by priority') do |o|
131
+ options.sort_by = :priority
132
+ end
133
+
134
+ opt.on('--ini', 'Output the result in Ini format') do |o|
135
+ options.view = :ini
136
+ end
137
+
138
+ opt.on('--quiet', 'Quiet mode, show only error messages') do |o|
139
+ options.view = :quiet
140
+ end
141
+
142
+ opt.on('--report', 'View the data as report') do |o|
143
+ options.view = :report
144
+ end
145
+
146
+
85
147
  unless ENV['ZYPPER_UPGRADEREPO']
86
148
  opt.separator ''
87
149
  opt.separator 'Other:'
@@ -97,7 +159,13 @@ module Zypper
97
159
  end
98
160
  end
99
161
 
100
- end.parse!(ARGV)
162
+ end
163
+
164
+ if ARGV.empty?
165
+ puts opt_parser; exit
166
+ else
167
+ opt_parser.parse!(ARGV)
168
+ end
101
169
 
102
170
  options
103
171
  end
@@ -105,14 +173,14 @@ module Zypper
105
173
  end
106
174
 
107
175
 
108
- class CLI
176
+ class CLI
109
177
  def self.start
110
178
  begin
111
179
  options = OptParseMain.parse(ARGV)
112
180
  Upgraderepo::Builder.new(options).send(options.operation)
113
181
  rescue => e
114
182
  Messages.error e
115
- exit 1
183
+ exit e.error_code
116
184
  end
117
185
  end
118
186
  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']
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)
@@ -24,7 +24,6 @@ module Zypper
24
24
 
25
25
  if options.version
26
26
  raise InvalidVersion, options.version unless OS_VERSIONS.include?(options.version)
27
- raise AlreadyUpgraded, options.version unless OS_VERSIONS.index(options.version) != @current_idx
28
27
  @custom = options.version
29
28
  end
30
29
  end
@@ -60,6 +59,10 @@ module Zypper
60
59
  def valid?(version)
61
60
  OS_VERSIONS.include? version
62
61
  end
62
+
63
+ def current?(version)
64
+ OS_VERSIONS.index(version) == @current_idx
65
+ end
63
66
  end
64
67
 
65
68
 
@@ -1,46 +1,60 @@
1
1
  require 'iniparse'
2
- require 'net/http'
3
- require 'zlib'
4
- require 'minitar'
5
2
 
6
3
  module Zypper
7
4
  module Upgraderepo
8
5
 
9
6
 
10
7
  class RepositoryList
8
+
9
+ REPOSITORY_PATH = '/etc/zypp/repos.d'
10
+
11
11
  attr_reader :list, :max_col
12
12
 
13
13
  def initialize(options)
14
14
  @alias = options.alias
15
15
  @name = options.name
16
+ @only_repo = options.only_repo
17
+ @only_enabled = options.only_enabled
18
+ @only_invalid = options.only_invalid
16
19
  @overrides = options.overrides
20
+ @upgrade_options = {alias: options.alias, name: options.name}
17
21
  @list = []
18
- @backup_path = options.backup_path
19
22
 
20
- Dir.glob('/etc/zypp/repos.d/*.repo').sort.each do |i|
21
- r = Repository.new(i)
22
- next if options.only_enabled && (!r.enabled?)
23
+ Dir.glob(File.join(REPOSITORY_PATH, '*.repo')).each do |i|
24
+ r = RepositoryRequest.new(Repository.new(i), options.timeout)
23
25
  @list << r
24
26
  end
25
- @max_col = @list.max_by { |x| x.name.length }.name.length
27
+ @max_col = @list.max_by { |r| r.name.length }.name.length
28
+
29
+ @list = @list.sort_by { |r| r.alias }.map.with_index(1) { |r, i| { num: i, repo: r } }
30
+
31
+ @list.sort_by! { |x| x[:repo].send(options.sort_by) } if options.sort_by != :alias
32
+
33
+ load_overrides(options.filename) if options.filename
26
34
  end
27
35
 
28
- def backup
29
- filename = File.join(@backup_path, "repos-backup-#{Time.now.to_s.delete(': +-')[0..-5]}.tgz")
30
- raise InvalidPermissions, filename unless File.writable? @backup_path
31
- Minitar.pack('/etc/zypp/repos.d',
32
- Zlib::GzipWriter.new(File.open(filename, 'wb')))
36
+ def only_enabled?
37
+ @only_enabled
33
38
  end
34
39
 
35
- def upgrade(version)
36
- @list.each_with_index do |repo, i|
37
- if @overrides.has_key? i.next.to_s
38
- repo.url = @overrides[i.next.to_s]
39
- else
40
- repo.url = repo.url.gsub(/\d\d\.\d/, version)
41
- end
42
- repo.alias = repo.alias.gsub(/\d\d\.\d/, version) if @alias
43
- repo.name = repo.name.gsub(/\d\d\.\d/, version) if @name
40
+ def upgrade!(version)
41
+ each_with_number(only_invalid: false) do |repo, num|
42
+ repo.upgrade! version, @upgrade_options.merge(url_override: @overrides[num])
43
+ repo.cache!
44
+ end
45
+ end
46
+
47
+ def each_with_number(options = {})
48
+ only_repo = options[:only_repo].nil? ? @only_repo : options[:only_repo]
49
+ only_enabled = options[:only_enabled].nil? ? @only_enabled : options[:only_enabled]
50
+ only_invalid = options[:only_invalid].nil? ? @only_invalid : options[:only_invalid]
51
+
52
+ @list.each do |x|
53
+ next if only_repo && !only_repo.include?(x[:num])
54
+ next if only_enabled && !x[:repo].enabled?
55
+ next if only_invalid && x[:repo].available?
56
+
57
+ yield x[:repo], x[:num] if block_given?
44
58
  end
45
59
  end
46
60
 
@@ -49,23 +63,50 @@ module Zypper
49
63
  i.save
50
64
  end
51
65
  end
66
+
67
+
68
+ private
69
+
70
+ def load_overrides(filename)
71
+ raise FileNotFound, filename unless File.exist?(filename)
72
+ ini = IniParse.parse(File.read(filename))
73
+ each_with_number(only_invalid: false) do |repo, num|
74
+ if x = ini["repository_#{num}"]
75
+ repo.enable!(x['enabled'])
76
+ raise UnmatchingOverrides, { num: num, ini: x, repo: repo } if repo.url != x['old_url']
77
+ if (@repos.only_enabled?)
78
+ raise MissingOverride, { num: num, ini: x } unless x['url'] || x['enabled'] =~ /no|false|0/i
79
+ else
80
+ raise MissingOverride, { num: num, ini: x } unless x['url']
81
+ end
82
+ @overrides[num] = x['url'] if x['url']
83
+ end
84
+ end
85
+ end
86
+
52
87
  end
53
88
 
54
89
 
55
90
  class Repository
56
- attr_reader :filename
57
-
91
+ attr_reader :filename, :old_url, :old_alias, :old_name
92
+
58
93
  def initialize(filename)
59
94
  @filename = filename
60
95
  @repo = IniParse.parse(File.read(filename))
61
- @key = get_key
62
- @res = nil
96
+ @key = get_key
97
+ @old_url = nil
98
+ @old_name = nil
99
+ @old_alias = nil
63
100
  end
64
101
 
65
102
  def enabled?
66
103
  @repo[@key]['enabled'].to_i == 1
67
104
  end
68
105
 
106
+ def enable!(value = true)
107
+ @repo[@key]['enabled'] = (value.to_s =~ /true|1|yes/i) ? 1 : 0
108
+ end
109
+
69
110
  def type
70
111
  @repo[@key]['type']
71
112
  end
@@ -78,6 +119,10 @@ module Zypper
78
119
  @repo[@key]['name'] = value
79
120
  end
80
121
 
122
+ def priority
123
+ @repo[@key]['priority'] || 99
124
+ end
125
+
81
126
  def url
82
127
  @repo[@key]['baseurl']
83
128
  end
@@ -95,75 +140,45 @@ module Zypper
95
140
  @key = get_key
96
141
  end
97
142
 
98
- def available?
99
- ping.is_a?(Net::HTTPSuccess)
100
- end
143
+ def upgrade!(version, args = {})
144
+ @old_url ||= self.url
145
+ @old_alias ||= self.alias
146
+ @old_name ||= self.name
101
147
 
102
- def redirected?
103
- ping.is_a?(Net::HTTPRedirection)
104
- end
148
+ if args[:url_override]
149
+ self.url = args[:url_override]
150
+ else
151
+ self.url = self.url.gsub(/\d\d\.\d/, version)
152
+ end
105
153
 
106
- def redirected_to
107
- ping['location']
154
+ self.alias = self.alias.gsub(/\d\d\.\d/, version) if args[:alias]
155
+ self.name = self.name.gsub(/\d\d\.\d/, version) if args[:name]
108
156
  end
109
157
 
110
- def not_found?
111
- ping.is_a?(Net::HTTPNotFound)
158
+ def upgraded?(item = :url)
159
+ (!self.send("old_#{item}").nil?) && (self.send("old_#{item}") != self.send(item))
112
160
  end
113
161
 
114
162
  def save
115
- raise InvalidPermissions, @filename unless File.writable? @filename
116
- @repo.save(@filename)
163
+ raise InvalidWritePermissions, @filename unless File.writable? @filename
164
+ process, pid = libzypp_process
165
+ raise SystemUpdateRunning, { pid: pid, process: process } if pid
166
+ @repo.save(@filename)
117
167
  end
118
168
 
119
- def evaluate_alternative(version)
120
- if url =~ /dl\.google\.com/
121
- return { url: '', message: 'Just Google security, use this repo anyway ;)'}
122
- elsif not_found?
123
- return traverse_url(URI(url.clone), version)
124
- elsif redirected?
125
- return { url: redirected_to, message: 'Redirected to:' }
126
- end
127
- end
128
169
 
129
170
  private
130
171
 
131
- def ping(uri = URI(url), force = false)
132
- begin
133
- @res = Net::HTTP.get_response(uri) if @res.nil? || force
134
- rescue SocketError
135
- raise NoConnection
136
- end
137
- @res
172
+ def libzypp_process
173
+ libpath = `ldd /usr/bin/zypper | grep "libzypp.so"`.split(' => ')[1].split(' ').shift
174
+ process = `sudo lsof #{libpath} | tail -n 1`
175
+ process, pid = process.split(' ')
176
+ [process, pid]
138
177
  end
139
178
 
140
179
  def get_key
141
180
  @repo.to_hash.keys.delete_if {|k| k == '0'}.pop
142
181
  end
143
-
144
- def traverse_url(uri, version)
145
- uri.path = File.dirname(uri.path)
146
-
147
- return {url: '', message: 'None, try to find it manually'} if uri.path == '/'
148
-
149
- uri.path += '/'
150
- ping(uri, true)
151
-
152
- if not_found?
153
- return traverse_url(uri, version)
154
- elsif available?
155
- return {url: uri.to_s, message: 'Override with this one' } if uri.path =~ Regexp.new(version)
156
-
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 }"
160
- return {url: uri.to_s, message: 'Override with this one' }
161
- end
162
-
163
- return {url: url, message: 'Can\'t find anything similar, try manually!' }
164
- end
165
-
166
- end
167
182
  end
168
183
 
169
184