[PATCH] Disable the "Closest mirror" option if there's no fastestmirror plugin (#876135).

Chris Lumens clumens at redhat.com
Thu Apr 11 20:02:18 UTC 2013


The goal here is to not allow selecting the Closest mirror option on trees that
do not include a repo config file supporting it.  This seems to be the easiest
way to do it, though I have not been able to test it thoroughly due to trees
being broken in other ways.  It does not break the standard Fedora case, though.

Additionally, I've moved Closest mirror to the last option in the combo box so
it can be removed without having to move all the other options around.
---
 pyanaconda/packaging/__init__.py      |  7 +++++++
 pyanaconda/packaging/yumpayload.py    |  5 +++++
 pyanaconda/ui/gui/spokes/source.glade |  2 +-
 pyanaconda/ui/gui/spokes/source.py    | 30 +++++++++++++++++++++---------
 4 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/pyanaconda/packaging/__init__.py b/pyanaconda/packaging/__init__.py
index f095dea..fb72e82 100644
--- a/pyanaconda/packaging/__init__.py
+++ b/pyanaconda/packaging/__init__.py
@@ -146,6 +146,13 @@ class Payload(object):
         """ The identifier of the current base repo. """
         return None
 
+    @property
+    def mirrorEnabled(self):
+        """Is the closest/fastest mirror option enabled?  This does not make
+           sense for those payloads that do not support this concept.
+        """
+        return True
+
     def getRepo(self, repo_id):
         """ Return the package repo object. """
         raise NotImplementedError()
diff --git a/pyanaconda/packaging/yumpayload.py b/pyanaconda/packaging/yumpayload.py
index 3209fe4..2dd81e1 100644
--- a/pyanaconda/packaging/yumpayload.py
+++ b/pyanaconda/packaging/yumpayload.py
@@ -410,6 +410,11 @@ reposdir=%s
 
         return base_repo_name
 
+    @property
+    def mirrorEnabled(self):
+        with _yum_lock:
+            return "fastestmirror" in self._yum.plugins.enabledPlugins
+
     def getRepo(self, repo_id):
         """ Return the yum repo object. """
         with _yum_lock:
diff --git a/pyanaconda/ui/gui/spokes/source.glade b/pyanaconda/ui/gui/spokes/source.glade
index 78ec539..2cc41f2 100644
--- a/pyanaconda/ui/gui/spokes/source.glade
+++ b/pyanaconda/ui/gui/spokes/source.glade
@@ -755,11 +755,11 @@
                             <property name="can_focus">False</property>
                             <property name="active">0</property>
                             <items>
-                              <item translatable="yes">Closest mirror</item>
                               <item translatable="yes">http://</item>
                               <item translatable="yes">https://</item>
                               <item translatable="yes">ftp://</item>
                               <item translatable="yes">nfs</item>
+                              <item translatable="yes">Closest mirror</item>
                             </items>
                             <signal name="changed" handler="on_protocol_changed" swapped="no"/>
                           </object>
diff --git a/pyanaconda/ui/gui/spokes/source.py b/pyanaconda/ui/gui/spokes/source.py
index accd19a..e9ecc7c 100644
--- a/pyanaconda/ui/gui/spokes/source.py
+++ b/pyanaconda/ui/gui/spokes/source.py
@@ -53,6 +53,13 @@ BASEREPO_SETUP_MESSAGE = N_("Setting up installation source...")
 METADATA_DOWNLOAD_MESSAGE = N_("Downloading package metadata...")
 METADATA_ERROR_MESSAGE = N_("Error downloading package metadata...")
 
+# These need to be in the same order as the items in protocolComboBox in source.glade.
+PROTOCOL_HTTP = 0
+PROTOCOL_HTTPS = 1
+PROTOCOL_FTP = 2
+PROTOCOL_NFS = 3
+PROTOCOL_MIRROR = 4
+
 # Repo Store Columns
 REPO_ENABLED_COL = 0
 REPO_NAME_COL = 1
@@ -554,6 +561,11 @@ class SourceSpoke(NormalSpoke):
 
         added = False
 
+        # If there's no fallback mirror to use, we should just disable that option
+        # in the UI.
+        if not self.payload.mirrorEnabled:
+            self._protocolComboBox.remove(PROTOCOL_MIRROR)
+
         # If we've previously set up to use a CD/DVD method, the media has
         # already been mounted by payload.setup.  We can't try to mount it
         # again.  So just use what we already know to create the selector.
@@ -621,7 +633,7 @@ class SourceSpoke(NormalSpoke):
 
         # We default to the mirror list, and then if the method tells us
         # something different later, we can change it.
-        self._protocolComboBox.set_active(0)
+        self._protocolComboBox.set_active(PROTOCOL_MIRROR)
         self._urlEntry.set_sensitive(False)
 
         # Set up the default state of UI elements.
@@ -630,13 +642,13 @@ class SourceSpoke(NormalSpoke):
 
             proto = self.data.method.url or self.data.method.mirrorlist
             if proto.startswith("http:"):
-                self._protocolComboBox.set_active(1)
+                self._protocolComboBox.set_active(PROTOCOL_HTTP)
                 l = 7
             elif proto.startswith("https:"):
-                self._protocolComboBox.set_active(2)
+                self._protocolComboBox.set_active(PROTOCOL_HTTPS)
                 l = 8
             elif proto.startswith("ftp:"):
-                self._protocolComboBox.set_active(3)
+                self._protocolComboBox.set_active(PROTOCOL_FTP)
                 l = 6
 
             self._urlEntry.set_sensitive(True)
@@ -644,7 +656,7 @@ class SourceSpoke(NormalSpoke):
             self._mirrorlistCheckbox.set_active(bool(self.data.method.mirrorlist))
         elif self.data.method.method == "nfs":
             self._networkButton.set_active(True)
-            self._protocolComboBox.set_active(4)
+            self._protocolComboBox.set_active(PROTOCOL_NFS)
 
             self._urlEntry.set_text("%s:%s" % (self.data.method.server, self.data.method.dir))
             self._urlEntry.set_sensitive(True)
@@ -683,16 +695,16 @@ class SourceSpoke(NormalSpoke):
         return not flags.livecdInstall
 
     def _mirror_active(self):
-        return self._protocolComboBox.get_active() == 0
+        return self._protocolComboBox.get_active() == PROTOCOL_MIRROR
 
     def _http_active(self):
-        return self._protocolComboBox.get_active() in [1, 2]
+        return self._protocolComboBox.get_active() in [PROTOCOL_HTTP, PROTOCOL_HTTPS]
 
     def _ftp_active(self):
-        return self._protocolComboBox.get_active() == 3
+        return self._protocolComboBox.get_active() == PROTOCOL_FTP
 
     def _nfs_active(self):
-        return self._protocolComboBox.get_active() == 4
+        return self._protocolComboBox.get_active() == PROTOCOL_NFS
 
     def _get_selected_partition(self):
         store = self.builder.get_object("partitionStore")
-- 
1.8.1.2



More information about the anaconda-patches mailing list