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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
|
#
# task_gui.py: Choose tasks for installation
#
# Copyright (C) 2006, 2007, 2008 Red Hat, Inc. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.
#
import gtk
import gtk.glade
import gobject
import gui
from iw_gui import *
from rhpl.translate import _, N_
from constants import productName
import isys
from netconfig_dialog import NetworkConfigurator
import network
from yuminstall import AnacondaYumRepo
import yum.Errors
import logging
log = logging.getLogger("anaconda")
def setupRepo(anaconda, repo):
try:
anaconda.backend.doRepoSetup(anaconda, thisrepo = repo.id, fatalerrors = False)
log.info("added repository %s with with source URL %s" % (repo.name, repo.baseurl[0]))
except yum.Errors.RepoError, e:
anaconda.intf.messageWindow(_("Error"),
_("Unable to read package metadata from repository. "
"This may be due to a missing repodata directory. "
"Please ensure that your repository has been "
"correctly generated.\n\n%s" %(e,)),
type="ok", custom_icon="error")
anaconda.backend.ayum.repos.delete(self.repo.id)
return False
if not repo.groups_added:
anaconda.intf.messageWindow(_("Warning"),
_("Unable to find a group file for %s. "
"This will prevent manual selection of packages "
"from the repository from working") %(repo.id,),
type="warning")
return True
class RepoEditor:
def __init__(self, anaconda, repoObj):
self.anaconda = anaconda
self.backend = self.anaconda.backend
self.intf = self.anaconda.intf
self.repo = repoObj
(self.dxml, self.dialog) = gui.getGladeWidget("addrepo.glade", "addRepoDialog")
self.nameEntry = self.dxml.get_widget("nameEntry")
self.baseurlButton = self.dxml.get_widget("baseurlButton")
self.baseurlEntry = self.dxml.get_widget("baseurlEntry")
self.mirrorlistButton = self.dxml.get_widget("mirrorlistButton")
self.mirrorlistEntry = self.dxml.get_widget("mirrorlistEntry")
self.proxyCheckbox = self.dxml.get_widget("proxyCheckbox")
self.proxyEntry = self.dxml.get_widget("proxyEntry")
self.proxyTable = self.dxml.get_widget("proxyTable")
self.usernameEntry = self.dxml.get_widget("usernameEntry")
self.passwordEntry = self.dxml.get_widget("passwordEntry")
def _enableRepo(self, repourl):
# Only do this for the real base repo, as that's what will get
# written out to anaconda-ks.cfg as the method.
if not self.repo.addon and not self.repo.name.startswith("Driver Disk"):
self.anaconda.setMethodstr(repourl)
# Ideally we should be able to unmount here, but if not
# it's probably not a big deal.
try:
isys.umount(self.backend.ayum.tree)
if self.backend.ayum.isodir:
isys.umount(self.backend.ayum.isodir)
except:
pass
return True
def _proxyToggled(self, *args):
self.proxyTable.set_sensitive(self.proxyCheckbox.get_active())
def _radioChanged(self, *args):
active = self.baseurlButton.get_active()
self.baseurlEntry.set_sensitive(active)
self.mirrorlistEntry.set_sensitive(not active)
def _validURL(self, url):
return len(url) > 0 and (url.startswith("http://") or
url.startswith("https://") or
url.startswith("ftp://"))
def createDialog(self):
if self.repo:
self.nameEntry.set_text(self.repo.name)
if self.repo.mirrorlist:
self.mirrorlistEntry.set_text(self.repo.mirrorlist)
self.mirrorlistButton.set_active(True)
else:
self.baseurlEntry.set_text(self.repo.baseurl[0])
self.baseurlButton.set_active(True)
if self.repo.proxy:
self.proxyCheckbox.set_active(True)
self.proxyTable.set_sensitive(True)
self.proxyEntry.set_text(self.repo.proxy)
self.usernameEntry.set_text(self.repo.proxy_username)
self.passwordEntry.set_text(self.repo.proxy_password)
gui.addFrame(self.dialog)
# Initialize UI elements that should be sensitive or not.
self._proxyToggled()
self._radioChanged()
self.proxyCheckbox.connect("toggled", self._proxyToggled)
self.baseurlButton.connect("toggled", self._radioChanged)
lbl = self.dxml.get_widget("descLabel")
txt = lbl.get_text()
lbl.set_text(txt %(productName,))
self.dialog.show_all()
def run(self, createNewRepoObj=False):
while True:
rc = self.dialog.run()
if rc == gtk.RESPONSE_CANCEL:
break
reponame = self.nameEntry.get_text()
reponame.strip()
if len(reponame) == 0:
self.intf.messageWindow(_("Invalid Repository Name"),
_("You must provide a repository name."))
continue
proxy = None
proxy_username = None
proxy_password = None
if self.proxyCheckbox.get_active():
proxy = self.proxyEntry.get_text()
proxy.strip()
if not self._validURL(proxy):
self.intf.messageWindow(_("Invalid Proxy URL"),
_("You must provide an HTTP, HTTPS, "
"or FTP URL to a proxy."))
continue
proxy_username = self.usernameEntry.get_text()
proxy_password = self.passwordEntry.get_text()
if createNewRepoObj:
self.repo = AnacondaYumRepo(repoid=reponame.replace(" ", ""))
else:
self.repo.repoid = reponame.replace(" ", "")
if self.baseurlButton.get_active():
repourl = self.baseurlEntry.get_text()
else:
repourl = self.mirrorlistEntry.get_text()
repourl.strip()
if not self._validURL(repourl):
self.intf.messageWindow(_("Invalid Repository URL"),
_("You must provide an HTTP, HTTPS, "
"or FTP URL to a repository."))
continue
if self.baseurlButton.get_active():
self.repo.baseurl = [repourl]
else:
self.repo.mirrorlist = repourl
self.repo.name = reponame
self.repo.basecachedir = self.backend.ayum.conf.cachedir
if proxy:
self.repo.proxy = proxy
self.repo.proxy_username = proxy_username
self.repo.proxy_password = proxy_password
self.repo.enable()
if not self._enableRepo(repourl):
continue
if not setupRepo(self.anaconda, self.repo):
continue
break
self.dialog.hide()
return rc
class RepoCreator(RepoEditor):
def __init__(self, anaconda):
RepoEditor.__init__(self, anaconda, None)
def _enableRepo(self, repourl):
try:
self.backend.ayum.repos.add(self.repo)
except yum.Errors.DuplicateRepoError, e:
self.intf.messageWindow(_("Error"),
_("The repository %s has already been added. Please "
"choose a different repository name and "
"URL.") % reponame, type="ok", custom_icon="error")
return False
return True
def run(self, createNewRepoObj=True):
return RepoEditor.run(self, createNewRepoObj)
class TaskWindow(InstallWindow):
def getNext(self):
if self.xml.get_widget("customRadio").get_active():
self.dispatch.skipStep("group-selection", skip = 0)
else:
self.dispatch.skipStep("group-selection", skip = 1)
tasks = self.xml.get_widget("taskList").get_model()
for (cb, task, grps) in tasks:
if cb:
map(self.backend.selectGroup, grps)
else:
map(self.backend.deselectGroup, grps)
if self.anaconda.id.instClass.allowExtraRepos:
repos = self.xml.get_widget("repoList").get_model()
for (cb, reponame, repo) in repos:
if cb:
repo.enable()
# Setup any repositories that were in the installclass's
# default list.
_setupRepo(self.anaconda, repo)
else:
repo.disable()
def groupsInstalled(self, lst):
# FIXME: yum specific
rc = False
for gid in lst:
g = self.backend.ayum.comps.return_group(gid)
if g and not g.selected:
return False
elif g:
rc = True
return rc
def groupsExist(self, lst):
# FIXME: yum specific
for gid in lst:
g = self.backend.ayum.comps.return_group(gid)
if not g:
return False
return True
def _editRepo(self, *args):
repo = None
if not network.hasActiveNetDev():
net = NetworkConfigurator(self.anaconda.id.network)
ret = net.run()
net.destroy()
if ret == gtk.RESPONSE_CANCEL:
return gtk.RESPONSE_CANCEL
# If we were passed an extra argument, it's the repo store and we
# are editing an existing repo as opposed to adding a new one.
if len(args) > 1:
(model, iter) = args[1].get_selection().get_selected()
if iter:
repo = model.get_value(iter, 2)
else:
return
else:
return
dialog = RepoEditor(self.anaconda, repo)
dialog.createDialog()
dialog.run()
def _addRepo(self, *args):
if not network.hasActiveNetDev():
net = NetworkConfigurator(self.anaconda.id.network)
ret = net.run()
net.destroy()
if ret == gtk.RESPONSE_CANCEL:
return gtk.RESPONSE_CANCEL
dialog = RepoCreator(self.anaconda)
dialog.createDialog()
if dialog.run() == gtk.RESPONSE_CANCEL:
return gtk.RESPONSE_CANCEL
s = self.xml.get_widget("repoList").get_model()
s.append([dialog.repo.isEnabled(), dialog.repo.name, dialog.repo])
def _taskToggled(self, button, row, store):
i = store.get_iter(int(row))
val = store.get_value(i, 0)
store.set_value(i, 0, not val)
def _repoToggled(self, button, row, store):
i = store.get_iter(int(row))
val = store.get_value(i, 0)
# The base repositories can never be disabled, but they can be edited.
if val and not store.get_value(i, 2).addon:
button.set_active(True)
return
if not val and not network.hasActiveNetDev():
net = NetworkConfigurator(self.anaconda.id.network)
ret = net.run()
net.destroy()
if ret == gtk.RESPONSE_CANCEL:
return
store.set_value(i, 0, not val)
def _createTaskStore(self):
store = gtk.ListStore(gobject.TYPE_BOOLEAN,
gobject.TYPE_STRING,
gobject.TYPE_PYOBJECT)
tl = self.xml.get_widget("taskList")
tl.set_model(store)
cbr = gtk.CellRendererToggle()
col = gtk.TreeViewColumn('', cbr, active = 0)
cbr.connect("toggled", self._taskToggled, store)
tl.append_column(col)
col = gtk.TreeViewColumn('Text', gtk.CellRendererText(), text = 1)
col.set_clickable(False)
tl.append_column(col)
for (txt, grps) in self.tasks:
if not self.groupsExist(grps):
continue
store.append([self.groupsInstalled(grps), _(txt), grps])
return tl
def _createRepoStore(self):
store = gtk.ListStore(gobject.TYPE_BOOLEAN,
gobject.TYPE_STRING,
gobject.TYPE_PYOBJECT)
tl = self.xml.get_widget("repoList")
tl.set_model(store)
cbr = gtk.CellRendererToggle()
col = gtk.TreeViewColumn('', cbr, active = 0)
cbr.connect("toggled", self._repoToggled, store)
tl.append_column(col)
col = gtk.TreeViewColumn('Text', gtk.CellRendererText(), text = 1)
col.set_clickable(False)
tl.append_column(col)
for (reponame, repo) in self.repos.repos.items():
store.append([repo.isEnabled(), repo.name, repo])
return tl
def getScreen (self, anaconda):
self.intf = anaconda.intf
self.dispatch = anaconda.dispatch
self.backend = anaconda.backend
self.anaconda = anaconda
self.tasks = anaconda.id.instClass.tasks
self.repos = anaconda.backend.ayum.repos
(self.xml, vbox) = gui.getGladeWidget("tasksel.glade", "taskBox")
lbl = self.xml.get_widget("mainLabel")
if anaconda.id.instClass.description:
lbl.set_text(_(anaconda.id.instClass.description))
else:
txt = lbl.get_text()
lbl.set_text(txt %(productName,))
custom = not self.dispatch.stepInSkipList("group-selection")
if custom:
self.xml.get_widget("customRadio").set_active(True)
else:
self.xml.get_widget("customRadio").set_active(False)
self.ts = self._createTaskStore()
self.rs = self._createRepoStore()
if len(self.ts.get_model()) == 0:
self.xml.get_widget("cbVBox").hide()
self.xml.get_widget("mainLabel").hide()
if not anaconda.id.instClass.allowExtraRepos:
vbox.remove(self.xml.get_widget("addRepoBox"))
self.xml.get_widget("addRepoButton").connect("clicked", self._addRepo)
self.xml.get_widget("editRepoButton").connect("clicked", self._editRepo, self.rs)
return vbox
|