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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
|
#
# 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
import gzip
from iw_gui import *
from image import *
from constants import *
import isys
import shutil
import gettext
_ = lambda x: gettext.ldgettext("anaconda", x)
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)
anaconda.backend.doSackSetup(anaconda, thisrepo=repo.id, fatalerrors=False)
log.info("added repository %s with with source URL %s" % (repo.name, repo.mirrorlist or repo.baseurl))
# FIXME: need a per-repo way of doing this; largely cut and paste
# from yum right now
if not repo.groups_added:
try:
groupfile = repo.getGroups()
# open it up as a file object so iterparse can cope
# with our gz file
if groupfile is not None and groupfile.endswith('.gz'):
groupfile = gzip.open(groupfile)
anaconda.backend.ayum._comps.add(groupfile)
except Exception, e:
log.debug("unable to add group information for repository %s" %(repo.name))
else:
repo.groups_added = True
log.info("added group information for repository %s" %(repo.name))
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(repo.id)
return False
return True
class RepoEditor:
# Window-level callbacks
def on_addRepoDialog_destroy(self, widget, *args):
pass
def on_cancelButton_clicked(self, widget, *args):
pass
def on_okButton_clicked(self, widget, *args):
pass
def on_typeComboBox_changed(self, widget, *args):
if widget.get_active() == -1:
return
# When the combo box's value is changed, set the notebook's current
# page to match. This requires that the combo box and notebook have
# the same method types at the same indices (so, HTTP must be the
# same position on both, etc.).
self.notebook.set_current_page(widget.get_active())
if widget.get_active() == 1:
if self.repo:
self.proxyCheckbox.set_active(self.repo.proxy is True)
self.proxyTable.set_sensitive(self.repo.proxy is True)
else:
self.proxyCheckbox.set_active(False)
self.proxyTable.set_sensitive(False)
# URL-specific callbacks
def on_proxyCheckbox_toggled(self, widget, *args):
table = self.dxml.get_widget("proxyTable")
table.set_sensitive(widget.get_active())
def on_mirrorlistCheckbox_toggled(self, widget, *args):
pass
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.dxml.signal_autoconnect(self)
self.notebook = self.dxml.get_widget("typeNotebook")
self.nameEntry = self.dxml.get_widget("nameEntry")
self.typeComboBox = self.dxml.get_widget("typeComboBox")
self.baseurlEntry = self.dxml.get_widget("baseurlEntry")
self.mirrorlistCheckbox = self.dxml.get_widget("mirrorlistCheckbox")
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")
self.nfsServerEntry = self.dxml.get_widget("nfsServerEntry")
self.nfsPathEntry = self.dxml.get_widget("nfsPathEntry")
self.nfsOptionsEntry = self.dxml.get_widget("nfsOptionsEntry")
self.partitionComboBox = self.dxml.get_widget("partitionComboBox")
self.directoryChooser = self.dxml.get_widget("directoryChooserButton")
# Remove these until they are actually implemented
self.typeComboBox.remove_text(3)
# Given a method string, return the index of the typeComboBox that should
# be made active in order to match.
def _methodToIndex(self, method):
mapping = {"http": 0, "ftp": 0, "https": 0,
"cdrom": 1,
"nfs": 2}
# "nfs": 2, "nfsiso": 2,
# "hd": 3}
try:
return mapping[method.split(':')[0].lower()]
except:
return 0
def _enableRepo(self):
try:
self.backend.ayum.repos.add(self.repo)
self.backend.ayum.repos.enableRepo(self.repo.id)
except yum.Errors.DuplicateRepoError, e:
self.intf.messageWindow(_("Error"),
_("The repository %s has already been added. Please "
"choose a different repository name and "
"URL.") % self.repo.name, type="ok", custom_icon="error")
return False
return True
def _validURL(self, url):
return len(url) > 0 and (url.startswith("http://") or
url.startswith("https://") or
url.startswith("ftp://"))
def createDialog(self):
self.dialog.set_title(_("Edit Repository"))
if self.repo:
self.nameEntry.set_text(self.repo.name)
self.typeComboBox.set_active(self._methodToIndex(self.anaconda.methodstr))
if not self.anaconda.methodstr or self.anaconda.methodstr.startswith("http") or self.anaconda.methodstr.startswith("ftp"):
if self.repo.mirrorlist:
self.baseurlEntry.set_text(self.repo.mirrorlist)
self.mirrorlistCheckbox.set_active(True)
else:
if self.repo.baseurl:
self.baseurlEntry.set_text(self.repo.baseurl[0])
else:
self.baseurlEntry.set_text("")
self.mirrorlistCheckbox.set_active(False)
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)
else:
self.proxyCheckbox.set_active(False)
self.proxyTable.set_sensitive(False)
elif self.anaconda.methodstr.startswith("nfs"):
(method, server, dir) = self.anaconda.methodstr.split(":")
self.nfsServerEntry.set_text(server)
self.nfsPathEntry.set_text(dir)
self.nfsOptionsEntry.set_text("")
elif self.anaconda.methodstr.startswith("cdrom:"):
pass
elif self.anaconda.methodstr.startswith("hd:"):
m = self.anaconda.methodstr[3:]
if m.count(":") == 1:
(device, path) = m.split(":")
fstype = "auto"
else:
(device, fstype, path) = m.split(":")
# find device in self.partitionComboBox and select it
self.directoryChooser.set_current_folder("%s%s" % (self.anaconda.backend.ayum.isodir, path))
else:
self.typeComboBox.set_active(0)
self.proxyCheckbox.set_active(False)
self.proxyTable.set_sensitive(False)
gui.addFrame(self.dialog)
lbl = self.dxml.get_widget("descLabel")
txt = lbl.get_text()
lbl.set_text(txt)
self.dialog.show_all()
def _applyURL(self, repo):
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."))
return False
repo.proxy = proxy
repo.proxy_username = self.usernameEntry.get_text()
repo.proxy_password = self.passwordEntry.get_text()
repourl = self.baseurlEntry.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."))
return False
if self.mirrorlistCheckbox.get_active():
repo.baseurl = []
repo.mirrorlist = repourl
else:
repo.baseurl = [repourl]
repo.mirrorlist = None
repo.name = self.nameEntry.get_text()
repo.basecachedir = self.backend.ayum.conf.cachedir
if repo.name == "Installation Repo":
self.anaconda.setMethodstr(repourl)
return True
def _applyMedia(self, repo):
cdr = scanForMedia(self.anaconda.backend.ayum.tree, self.anaconda.id.storage)
if not cdr:
self.intf.messageWindow(_("No Media Found"),
_("No installation media was found. "
"Please insert a disc into your drive "
"and try again."))
return False
self.anaconda.setMethodstr("cdrom://%s:%s" % (cdr, self.anaconda.backend.ayum.tree))
self.anaconda.backend.ayum.configBaseURL()
self.anaconda.backend.ayum.configBaseRepo(replace=True)
return True
def _applyNfs(self, repo):
server = self.nfsServerEntry.get_text()
server.strip()
path = self.nfsPathEntry.get_text()
path.strip()
if not server or not path:
self.intf.messageWindow(_("Error"),
_("Please enter an NFS server and path."))
return False
self.anaconda.setMethodstr("nfs:%s:%s" % (server, path))
try:
self.anaconda.backend.ayum.configBaseURL()
except SystemError, e:
self.intf.messageWindow(_("Error Setting Up Repository"),
_("The following error occurred while setting up the "
"installation repository:\n\n%s\n\nPlease provide the "
"correct information for installing %s.") % (e, productName))
return False
self.anaconda.backend.ayum.configBaseRepo(replace=True)
return True
def _applyHd(self, repo):
return True
def run(self):
applyFuncs = [ self._applyURL, self._applyMedia, self._applyNfs,
self._applyHd ]
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
# Always create a new repo object here instead of attempting to
# somehow expire the metadata and refetch. We'll just have to make
# sure that if we're just editing the repo, we grab all the
# attributes from the old one before deleting it.
if self.repo:
newRepoObj = AnacondaYumRepo(self.repo.id)
try:
os.unlink("%s/cachecookie" % self.repo.cachedir)
os.unlink("%s/repomd.xml" % self.repo.cachedir)
except:
pass
self.repo.close()
self.anaconda.backend.ayum.repos.delete(self.repo.id)
try:
shutil.rmtree(self.repo.cachedir)
except Exception, e:
log.warning("error removing cachedir for %s: %s" %(self.repo,e))
pass
else:
newRepoObj = AnacondaYumRepo(reponame.replace(" ", ""))
self.repo = newRepoObj
type = self.typeComboBox.get_active()
if not applyFuncs[type](self.repo):
continue
if not self._enableRepo():
continue
if not setupRepo(self.anaconda, self.repo):
continue
break
self.dialog.hide()
return rc
class RepoMethodstrEditor(RepoEditor):
def __init__(self, anaconda):
RepoEditor.__init__(self, anaconda, None)
def createDialog(self):
RepoEditor.createDialog(self)
# Hide a bunch of stuff that doesn't apply when we're just prompting
# for enough information to form a methodstr.
self.dxml.get_widget("nameLabel").hide()
self.nameEntry.hide()
self.mirrorlistCheckbox.hide()
self.proxyCheckbox.hide()
self.proxyTable.hide()
def _applyURL(self):
repourl = self.baseurlEntry.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."))
return False
return repourl
def _applyMedia(self):
cdr = scanForMedia(self.anaconda.backend.ayum.tree, self.anaconda.id.storage)
if not cdr:
self.intf.messageWindow(_("No Media Found"),
_("No installation media was found. "
"Please insert a disc into your drive "
"and try again."))
return False
return "cdrom://%s:%s" % (cdr, self.anaconda.backend.ayum.tree)
def _applyNfs(self):
server = self.nfsServerEntry.get_text()
server.strip()
path = self.nfsPathEntry.get_text()
path.strip()
if not server or not path:
self.intf.messageWindow(_("Error"),
_("Please enter an NFS server and path."))
return False
return "nfs:%s:%s" % (server, path)
def _applyHd(self):
return None
def run(self):
applyFuncs = [ self._applyURL, self._applyMedia, self._applyNfs,
self._applyHd ]
while True:
rc = self.dialog.run()
if rc == gtk.RESPONSE_CANCEL:
rc = None
break
type = self.typeComboBox.get_active()
retval = applyFuncs[type]()
if not retval:
continue
rc = retval
break
self.dialog.hide()
return rc
class RepoCreator(RepoEditor):
def __init__(self, anaconda):
RepoEditor.__init__(self, anaconda, None)
def createDialog(self):
RepoEditor.createDialog(self)
self.dialog.set_title(_("Add Repository"))
class TaskWindow(InstallWindow):
def getNext(self):
if not self._anyRepoEnabled():
self.anaconda.intf.messageWindow(_("No Software Repos Enabled"),
_("You must have at least one software repository enabled to "
"continue installation."))
raise gui.StayOnScreen
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:
# we just set things as default or not; group selection
# happens after this screen.
if cb:
map(lambda g: setattr(self.backend.ayum.comps.return_group(g),
"default", True), grps)
else:
map(lambda g: setattr(self.backend.ayum.comps.return_group(g),
"default", False), grps)
def _editRepo(self, *args):
repo = None
# 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
if repo.needsNetwork() and not network.hasActiveNetDev():
if not self.anaconda.intf.enableNetwork(self.anaconda):
return gtk.RESPONSE_CANCEL
dialog = RepoEditor(self.anaconda, repo)
dialog.createDialog()
dialog.run()
model.set_value(iter, 2, dialog.repo)
def _addRepo(self, *args):
dialog = RepoCreator(self.anaconda)
dialog.createDialog()
if dialog.run() == gtk.RESPONSE_CANCEL:
return gtk.RESPONSE_CANCEL
if dialog.repo.needsNetwork() and not network.hasActiveNetDev():
if not self.anaconda.intf.enableNetwork(self.anaconda):
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 _anyRepoEnabled(self):
model = self.rs.get_model()
iter = model.get_iter_first()
while True:
if model.get_value(iter, 0):
return True
iter = model.iter_next(iter)
if not iter:
return False
return False
def _repoToggled(self, button, row, store):
i = store.get_iter(int(row))
wasChecked = store.get_value(i, 0)
repo = store.get_value(i, 2)
if not wasChecked:
if repo.needsNetwork() and not network.hasActiveNetDev():
if not self.anaconda.intf.enableNetwork(self.anaconda):
return
repo.enable()
if not setupRepo(self.anaconda, repo):
return
else:
repo.disable()
repo.close()
store.set_value(i, 0, not wasChecked)
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.backend.groupListExists(grps):
continue
store.append([self.backend.groupListDefault(grps), _(txt), grps])
return tl
def __sortRepos(self, store, aIter, bIter):
aStr = store.get_value(aIter, 1)
bStr = store.get_value(bIter, 1)
if aStr == "Installation Repo":
return -1
elif bStr == "Installation Repo":
return 1
elif aStr < bStr or bStr is None:
return -1
elif aStr > bStr or aStr is None:
return 1
else:
return aStr == bStr
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])
store.set_sort_column_id(1, gtk.SORT_ASCENDING)
store.set_sort_func(1, self.__sortRepos)
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()
self.xml.get_widget("addRepoButton").connect("clicked", self._addRepo)
self.xml.get_widget("editRepoButton").connect("clicked", self._editRepo, self.rs)
return vbox
|