-
Notifications
You must be signed in to change notification settings - Fork 44
/
inst_addon_update_sources.rb
193 lines (167 loc) · 5.69 KB
/
inst_addon_update_sources.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# ------------------------------------------------------------------------------
# Copyright (c) 2006-2012 Novell, Inc. All Rights Reserved.
#
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail, you may find
# current contact information at www.novell.com.
# ------------------------------------------------------------------------------
# File: clients/inst_addon_update_sources.ycp
# Package: yast2-installation
# Summary: Add installation sources for online update, #163192
# Authors: Martin Vidner <mvidner@suse.cz>
#
# Assumptions:
# - the sources will be saved afterwards
# (this means that running this client alone will not work)
require "y2packager/resolvable"
module Yast
class InstAddonUpdateSourcesClient < Client
def main
Yast.import "Pkg"
textdomain "installation"
Yast.import "GetInstArgs"
Yast.import "PackageCallbacks"
Yast.import "Popup"
Yast.import "SourceManager"
Yast.import "Report"
Yast.import "Installation"
Yast.import "String"
Yast.include self, "packager/inst_source_dialogs.rb"
return :auto if GetInstArgs.going_back # going backwards? # don't execute this once more
@aliases = {}
# feedback heading
@heading = _("Add-on Product Installation")
# feedback message
@message = _("Reading packages available in the repositories...")
# bugzilla #270899#c29
Pkg.TargetInitialize(Installation.destdir)
Pkg.TargetLoad
Pkg.SourceStartManager(true)
@knownUrls = KnownUrls()
Builtins.y2milestone("sources known: %1", @knownUrls)
@is_known = Builtins.listmap(@knownUrls) { |u| { u => true } }
@updateUrls = UpdateUrls()
Builtins.y2milestone("sources for updates: %1", @updateUrls)
@addUrls = Builtins.filter(@updateUrls) do |url, _name|
!Ops.get(@is_known, url, false)
end
Builtins.y2milestone("sources to add: %1", @addUrls)
if @addUrls != {}
Popup.ShowFeedback(@heading, @message)
Builtins.foreach(@addUrls) do |url, name|
again = true
while again
# BNC #557723: Repositories migh be created without access to network
# Libzypp must not probe the repo
alias_ = Ops.get(@aliases, url, "")
if alias_ == ""
# don't use spaces in alias (hard to use with zypper)
alias_ = String.Replace(
Ops.greater_than(Builtins.size(name), 0) ? name : url,
" ",
"-"
)
end
repo_prop = {
"enabled" => true,
"autorefresh" => true,
"name" => Ops.greater_than(Builtins.size(name), 0) ? name : url,
"alias" => alias_,
"base_urls" => [url],
"prod_dir" => "/"
}
srcid = Pkg.RepositoryAdd(repo_prop)
Builtins.y2milestone("got %1 from creating %2/%3", srcid, url, name)
# wrong srcid, must have failed
if srcid == -1
# popup error message
# %1 represents the the error message details
if Popup.YesNo(
Builtins.sformat(
_(
"An error occurred while connecting to the server.\n" \
"Details: %1\n" \
"\n" \
"Try again?"
),
Pkg.LastError
)
)
# try again
url = editUrl(url)
else
# abort
again = false
end
# everything is ok
else
again = false
end
end
end
Popup.ClearFeedback
end
:auto
# EOF
end
# @return the urls of known installation sources
def KnownUrls
src_ids = Pkg.SourceGetCurrent(
true # enabled only?
)
urls = Builtins.maplist(src_ids) do |src_id|
gendata = Pkg.SourceGeneralData(src_id)
Ops.get_string(gendata, "url", "")
end
deep_copy(urls)
end
# @return the installation sources to be added
def UpdateUrls
urls = {}
products = Y2Packager::Resolvable.find(kind: :product)
Builtins.foreach(products) do |p|
Builtins.foreach(p.update_urls) do |u|
# bnc #542792
# Repository name must be generated from product details
p_name =
[p.display_name, p.name, p.summary, _("Unknown Product")].reject(&:empty?).first
Ops.set(
urls,
u,
Builtins.sformat(
_("Updates for %1 %2"),
p_name,
p.version
)
)
# alias should be simple (bnc#768624)
p_alias = [p.display_name, p.name, "repo"].reject(&:empty?).first
Ops.set(
@aliases,
u,
String.Replace(
Ops.add(
"update-",
p_alias
),
" ",
"-"
)
)
end
end
deep_copy(urls)
end
end
end