summaryrefslogtreecommitdiffstats
path: root/iw
diff options
context:
space:
mode:
authorChris Lumens <clumens@redhat.com>2008-02-21 10:14:25 -0500
committerChris Lumens <clumens@redhat.com>2008-02-28 14:27:19 -0500
commit3fd93c9585c708acb1c39d0887bffdd774e288ed (patch)
treefc0b683f34ad26ed5a7191d6ba2a95cd3f7accb9 /iw
parentdb61534532f0e3dfc3191b754641dc164dbbcc02 (diff)
downloadanaconda-3fd93c9585c708acb1c39d0887bffdd774e288ed.tar.gz
anaconda-3fd93c9585c708acb1c39d0887bffdd774e288ed.tar.xz
anaconda-3fd93c9585c708acb1c39d0887bffdd774e288ed.zip
Rework the repo editor screen to be more modular.
Diffstat (limited to 'iw')
-rw-r--r--iw/task_gui.py416
1 files changed, 219 insertions, 197 deletions
diff --git a/iw/task_gui.py b/iw/task_gui.py
index 495a2c47a..7779183b9 100644
--- a/iw/task_gui.py
+++ b/iw/task_gui.py
@@ -35,177 +35,131 @@ import yum.Errors
import logging
log = logging.getLogger("anaconda")
-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.
- self._setupRepo(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 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
- 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 _setupRepo(self, repo):
- try:
- self.backend.doRepoSetup(self.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:
- self.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")
- self.backend.ayum.repos.delete(repo.id)
- return False
-
- if not repo.groups_added:
- self.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")
+ def _proxyToggled(self, *args):
+ self.proxyTable.set_sensitive(self.proxyCheckbox.get_active())
- return True
+ 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 _addRepo(self, *args):
- repo = None
- editing = False
-
- if not network.hasActiveNetDev():
- net = NetworkConfigurator(self.anaconda.id.network)
- ret = net.run()
- net.destroy()
- if ret == gtk.RESPONSE_CANCEL:
- return gtk.RESPONSE_CANCEL
+ def createDialog(self):
+ if self.repo:
+ self.nameEntry.set_text(self.repo.name)
- # 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)
- editing = True
+ if self.repo.mirrorlist:
+ self.mirrorlistEntry.set_text(self.repo.mirrorlist)
+ self.mirrorlistButton.set_active(True)
else:
- return
+ self.baseurlEntry.set_text(self.repo.baseurl[0])
+ self.baseurlButton.set_active(True)
- (self.dxml, dialog) = gui.getGladeWidget("addrepo.glade", "addRepoDialog")
- nameEntry = self.dxml.get_widget("nameEntry")
- baseurlButton = self.dxml.get_widget("baseurlButton")
- baseurlEntry = self.dxml.get_widget("baseurlEntry")
- mirrorlistButton = self.dxml.get_widget("mirrorlistButton")
- mirrorlistEntry = self.dxml.get_widget("mirrorlistEntry")
- proxyCheckbox = self.dxml.get_widget("proxyCheckbox")
- proxyEntry = self.dxml.get_widget("proxyEntry")
- proxyTable = self.dxml.get_widget("proxyTable")
- usernameEntry = self.dxml.get_widget("usernameEntry")
- passwordEntry = self.dxml.get_widget("passwordEntry")
-
- # If we are editing an existing repo, use the existing values to
- # populate the UI.
- # FIXME: this is yum specific
- if editing:
- nameEntry.set_text(repo.name)
-
- if repo.mirrorlist:
- mirrorlistEntry.set_text(repo.mirrorlist)
- mirrorlistButton.set_active(True)
- else:
- baseurlEntry.set_text(repo.baseurl[0])
- 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)
- if repo.proxy:
- proxyCheckbox.set_active(True)
- proxyTable.set_sensitive(True)
- proxyEntry.set_text(repo.proxy)
- usernameEntry.set_text(repo.proxy_username)
- passwordEntry.set_text(repo.proxy_password)
-
- gui.addFrame(dialog)
+ gui.addFrame(self.dialog)
# Initialize UI elements that should be sensitive or not.
self._proxyToggled()
self._radioChanged()
- proxyCheckbox.connect("toggled", self._proxyToggled)
- baseurlButton.connect("toggled", 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,))
- dialog.show_all()
+ self.dialog.show_all()
- while 1:
- rc = dialog.run()
+ def run(self, createNewRepoObj=False):
+ while True:
+ rc = self.dialog.run()
if rc == gtk.RESPONSE_CANCEL:
break
- reponame = nameEntry.get_text()
+ reponame = self.nameEntry.get_text()
reponame.strip()
if len(reponame) == 0:
self.intf.messageWindow(_("Invalid Repository Name"),
_("You must provide a repository name."))
continue
- if baseurlButton.get_active():
- repourl = baseurlEntry.get_text()
- else:
- repourl = 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
-
proxy = None
proxy_username = None
proxy_password = None
- if proxyCheckbox.get_active():
- proxy = proxyEntry.get_text()
+ if self.proxyCheckbox.get_active():
+ proxy = self.proxyEntry.get_text()
proxy.strip()
if not self._validURL(proxy):
self.intf.messageWindow(_("Invalid Proxy URL"),
@@ -213,88 +167,156 @@ class TaskWindow(InstallWindow):
"or FTP URL to a proxy."))
continue
- proxy_username = usernameEntry.get_text()
- proxy_password = passwordEntry.get_text()
+ proxy_username = self.usernameEntry.get_text()
+ proxy_password = self.passwordEntry.get_text()
- # Don't create a new repo object if we are editing.
- # FIXME: this is yum specific
- if editing:
- if baseurlButton.get_active():
- repo.baseurl = [repourl]
- else:
- repo.mirrorlist = repourl
+ if createNewRepoObj:
+ self.repo = AnacondaYumRepo(repoid=reponame.replace(" ", ""))
+ else:
+ self.repo.repoid = reponame.replace(" ", "")
- repo.repoid = reponame.replace(" ", "")
+ if self.baseurlButton.get_active():
+ repourl = self.baseurlEntry.get_text()
else:
- repoid = reponame.replace(" ", "")
+ repourl = self.mirrorlistEntry.get_text()
- if baseurlButton.get_active():
- repo = AnacondaYumRepo(uri=repourl, repoid=repoid)
- else:
- repo = AnacondaYumRepo(mirrorlist=repourl, repoid=repoid)
+ 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
- repo.name = reponame
- repo.basecachedir = self.backend.ayum.conf.cachedir
+ self.repo.name = reponame
+ self.repo.basecachedir = self.backend.ayum.conf.cachedir
if proxy:
- repo.proxy = proxy
- repo.proxy_username = proxy_username
- repo.proxy_password = proxy_password
+ self.repo.proxy = proxy
+ self.repo.proxy_username = proxy_username
+ self.repo.proxy_password = proxy_password
- repo.enable()
+ self.repo.enable()
- if editing:
- # 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 repo.addon and not repo.name.startswith("Driver Disk"):
- self.anaconda.setMethodstr(repourl)
+ if not self._enableRepo(repourl):
+ continue
- # 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 not setupRepo(self.anaconda, self.repo):
+ continue
- if self.backend.ayum.isodir:
- isys.umount(self.backend.ayum.isodir)
- except:
- pass
+ break
- if not self._setupRepo(repo):
- continue
- else:
- try:
- self.backend.ayum.repos.add(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")
- continue
+ self.dialog.hide()
+ return rc
- if not self._setupRepo(repo):
- continue
+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
- s = self.xml.get_widget("repoList").get_model()
- s.append([repo.isEnabled(), repo.name, repo])
+ return True
- break
+ def run(self, createNewRepoObj=True):
+ return RepoEditor.run(self, createNewRepoObj)
- dialog.destroy()
+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 _radioChanged(self, *args):
- baseurlButton = self.dxml.get_widget("baseurlButton")
- baseurlEntry = self.dxml.get_widget("baseurlEntry")
- mirrorlistEntry = self.dxml.get_widget("mirrorlistEntry")
+ 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
- active = baseurlButton.get_active()
- baseurlEntry.set_sensitive(active)
- mirrorlistEntry.set_sensitive(not active)
+ def _editRepo(self, *args):
+ repo = None
- def _proxyToggled(self, *args):
- table = self.dxml.get_widget("proxyTable")
- checkbox = self.dxml.get_widget("proxyCheckbox")
- table.set_sensitive(checkbox.get_active())
+ 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))
@@ -381,7 +403,7 @@ class TaskWindow(InstallWindow):
txt = lbl.get_text()
lbl.set_text(txt %(productName,))
- custom = not self.dispatch.stepInSkipList("group-selection")
+ custom = not self.dispatch.stepInSkipList("group-selection")
if custom:
self.xml.get_widget("customRadio").set_active(True)
else:
@@ -398,6 +420,6 @@ class TaskWindow(InstallWindow):
vbox.remove(self.xml.get_widget("addRepoBox"))
self.xml.get_widget("addRepoButton").connect("clicked", self._addRepo)
- self.xml.get_widget("editRepoButton").connect("clicked", self._addRepo, self.rs)
+ self.xml.get_widget("editRepoButton").connect("clicked", self._editRepo, self.rs)
return vbox