[master 1/5] Repositories can be checked without a selection

jkonecny12 installerbot-noreply at redhat.com
Tue Jul 21 08:24:41 UTC 2015


From: Jiri Konecny <jkonecny at redhat.com>

In SourceSpoke before this patch InpuChecks reads information from
GtkWidgets which means only selected repository could be tested.
This is problematic in some circumstances for example when we want to run
tests in on_back_clicked method.
---
 pyanaconda/ui/gui/spokes/source.py | 75 ++++++++++++++++++++++++++++----------
 1 file changed, 56 insertions(+), 19 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/source.py b/pyanaconda/ui/gui/spokes/source.py
index d909ec9..c902655 100644
--- a/pyanaconda/ui/gui/spokes/source.py
+++ b/pyanaconda/ui/gui/spokes/source.py
@@ -27,6 +27,7 @@
 
 import os, signal, re
 from collections import namedtuple
+from urllib.parse import urlsplit
 
 import gi
 gi.require_version("GLib", "2.0")
@@ -940,36 +941,62 @@ def _sanitize_model(self, model):
 
     # This method is shared by the checks on urlEntry and repoUrlEntry
     def _checkURL(self, inputcheck, combo):
-        url_string = self.get_input(inputcheck.input_obj).strip()
+        # If combo is not set inputcheck holds repo
+        is_additional_repo = combo is None
+        if is_additional_repo:
+            # Input object contains repository name
+            repo = self._get_repo_by_name(inputcheck.input_obj)
+            protocol = urlsplit(repo.baseurl)[0]
+            url_string = repo.baseurl.strip()[len(protocol) + 3:]
+        else:
+            url_string = self.get_input(inputcheck.input_obj).strip()
+            protocol = combo.get_active_id()
 
         # If this is HTTP/HTTPS/FTP, use the URL_PARSE regex
-        combo_protocol = combo.get_active_id()
-        if combo_protocol in (PROTOCOL_HTTP, PROTOCOL_HTTPS, PROTOCOL_FTP):
+        if protocol in (PROTOCOL_HTTP, PROTOCOL_HTTPS, PROTOCOL_FTP):
             if not url_string:
-                return _("URL is empty")
+                if is_additional_repo and repo.name:
+                    return _("Repository %s has empty url") % repo.name
+                else:
+                    return _("URL is empty")
 
             m = URL_PARSE.match(url_string)
             if not m:
-                return _("Invalid URL")
+                if is_additional_repo and repo.name:
+                    return _("Repository %s has invalid url") % repo.name
+                else:
+                    return _("Invalid URL")
 
             # Matching protocols in the URL should already have been removed
             # by _removeUrlPrefix. If there's still one there, it's wrong.
             url_protocol = m.group('protocol')
             if url_protocol:
-                return _("Protocol in URL does not match selected protocol")
-        elif combo_protocol == PROTOCOL_NFS:
+                if is_additional_repo and repo.name:
+                    return _("Repository %s does not match selected protocol") % repo.name
+                else:
+                    return _("Protocol in URL does not match selected protocol")
+        elif protocol == PROTOCOL_NFS:
             if not url_string:
-                return _("NFS server is empty")
+                if is_additional_repo and repo.name:
+                    return _("Repository %s has empty NFS server") % repo.name
+                else:
+                    return _("NFS server is empty")
 
             # Make sure the part before the colon looks like a hostname,
             # and that the path is not empty
             host, _colon, path = url_string.partition(':')
 
             if not re.match('^' + HOSTNAME_PATTERN_WITHOUT_ANCHORS + '$', host):
-                return _("Invalid host name")
+                if is_additional_repo and repo.name:
+                    return _("Repository %s has invalid host name") % repo.name
+                else:
+                    return _("Invalid host name")
 
             if not path:
-                return _("Remote directory is required")
+                if is_additional_repo and repo.name:
+                    return _("Repository %s required remote directory") % repo.name
+                else:
+                    return _("Remote directory is required")
 
         return InputCheck.CHECK_OK
 
@@ -977,7 +1004,7 @@ def _checkURLEntry(self, inputcheck):
         return self._checkURL(inputcheck, self._protocolComboBox)
 
     def _checkRepoURL(self, inputcheck):
-        return self._checkURL(inputcheck, self._repoProtocolComboBox)
+        return self._checkURL(inputcheck, None)
 
     # Update the check on urlEntry when the sensitity or selected protocol changes
     def _updateURLEntryCheck(self, *args):
@@ -994,7 +1021,8 @@ def _checkDuplicateRepos(self, inputcheck):
         return InputCheck.CHECK_OK
 
     def _checkRepoName(self, inputcheck):
-        repo_name = self.get_input(inputcheck.input_obj).strip()
+        # Input object is name of the repository
+        repo_name = inputcheck.input_obj
 
         if not repo_name:
             return _("Empty repository name")
@@ -1011,19 +1039,21 @@ def _checkRepoName(self, inputcheck):
         return InputCheck.CHECK_OK
 
     def _checkRepoProxy(self, inputcheck):
+        # Input object contains repo name
+        repo = self._get_repo_by_name(inputcheck.input_obj)
         # If nfs is selected as the protocol, skip the proxy check
-        if self._repoProtocolComboBox.get_active_id() == PROTOCOL_NFS:
+        if repo.baseurl.startswith(PROTOCOL_NFS):
             return InputCheck.CHECK_OK
 
-        # Empty proxies are OK, as long as the username and password are empty too
-        proxy_string = self.get_input(inputcheck.input_obj).strip()
-        username_set = self._repoProxyUsernameEntry.is_sensitive() and self._repoProxyUsernameEntry.get_text().strip()
-        password_set = self._repoProxyPasswordEntry.is_sensitive() and self._repoProxyPasswordEntry.get_text().strip()
+        if not repo.proxy:
+            return InputCheck.CHECK_OK
 
-        if not (proxy_string or username_set or password_set):
+        # Empty proxies are OK, as long as the username and password are empty too
+        proxy_obj = ProxyString(repo.proxy)
+        if not (repo.proxy or proxy_obj.username or proxy_obj.password):
             return InputCheck.CHECK_OK
 
-        return _validateProxy(proxy_string, username_set, password_set)
+        return _validateProxy(proxy_obj.noauth_url, proxy_obj.username, proxy_obj.password)
 
     # Signal handlers.
     def on_source_toggled(self, button, relatedBox):
@@ -1243,6 +1273,13 @@ def _unique_repo_name(self, name):
         highest_index = max(matches) if matches else 0
         return name + ("_%d" % (highest_index + 1))
 
+    def _get_repo_by_name(self, name):
+        """ Return a repository by given name"""
+        for repo in self._repoStore:
+            if repo.name == name:
+                return repo
+        return None
+
     def on_repoSelection_changed(self, *args):
         """ Called when the selection changed.
 


-- 
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/ebe01dd8e09c259a78b4a301eec2e1eb901ebf1a


More information about the anaconda-patches mailing list