Skip to content

Commit

Permalink
Repositories can be checked without a selection
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jkonecny12 committed Jul 20, 2015
1 parent 6a71eb0 commit ebe01dd
Showing 1 changed file with 56 additions and 19 deletions.
75 changes: 56 additions & 19 deletions pyanaconda/ui/gui/spokes/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -940,44 +941,70 @@ 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

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):
Expand All @@ -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")
Expand All @@ -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):
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ebe01dd

Please sign in to comment.