[master 5/11] Add IDs to identify addon repositories
wgwoods
installerbot-noreply at redhat.com
Wed Jul 22 21:32:49 UTC 2015
From: Jiri Konecny <jkonecny at redhat.com>
Choose to use identifiers for the repositories because I have found nothing
which wasn't changing in time.
This seems to fix most of the problems with the Source spoke.
Add generator for IDs to iutil.py this could be helpful for future.
---
pyanaconda/iutil.py | 11 +++++++
pyanaconda/kickstart.py | 1 +
pyanaconda/ui/gui/spokes/source.py | 62 ++++++++++++++++++++++----------------
3 files changed, 48 insertions(+), 26 deletions(-)
diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py
index 8e9592b..07fc4cb 100644
--- a/pyanaconda/iutil.py
+++ b/pyanaconda/iutil.py
@@ -1334,3 +1334,14 @@ def _opener(path, open_flags):
return eintr_retry_call(os.open, path, open_flags, perm)
return open(path, mode, opener=_opener, **kwargs)
+
+def id_generator():
+ """ Id numbers generator.
+ Generating numbers from 0 to X and increments after every call.
+
+ :returns: Generator which gives you unique numbers.
+ """
+ actual_id = 0
+ while(True):
+ yield actual_id
+ actual_id += 1
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index 7f9a0e0..13a729a 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -1581,6 +1581,7 @@ def __init__(self, *args, **kwargs):
:type enabled: bool
"""
self.enabled = kwargs.pop("enabled", True)
+ self.repo_id = kwargs.pop("repo_id", None)
commands.repo.F21_RepoData.__init__(self, *args, **kwargs)
diff --git a/pyanaconda/ui/gui/spokes/source.py b/pyanaconda/ui/gui/spokes/source.py
index 624b077..8fc1749 100644
--- a/pyanaconda/ui/gui/spokes/source.py
+++ b/pyanaconda/ui/gui/spokes/source.py
@@ -52,6 +52,7 @@
from pyanaconda.regexes import REPO_NAME_VALID, URL_PARSE, HOSTNAME_PATTERN_WITHOUT_ANCHORS
from pyanaconda import constants
from pyanaconda import nm
+from pyanaconda.iutil import id_generator
from blivet.util import get_mount_device, get_mount_paths
@@ -394,6 +395,7 @@ def __init__(self, *args, **kwargs):
self._proxyUrl = ""
self._proxyChange = False
self._cdrom = None
+ self._repo_counter = id_generator()
self._repoChecks = {}
@@ -955,7 +957,7 @@ def _checkURL(self, inputcheck, combo):
is_additional_repo = combo is None
if is_additional_repo:
# Input object contains repository name
- repo = self._get_repo_by_name(inputcheck.input_obj)
+ repo = self._get_repo_by_id(inputcheck.input_obj)
protocol = urlsplit(repo.baseurl)[0]
url_string = repo.baseurl.strip()[len(protocol) + 3:]
else:
@@ -1032,7 +1034,7 @@ def _checkDuplicateRepos(self, inputcheck):
def _checkRepoName(self, inputcheck):
# Input object is name of the repository
- repo_name = inputcheck.input_obj
+ repo_name = self._get_repo_by_id(inputcheck.input_obj).name
if not repo_name:
return _("Empty repository name")
@@ -1050,7 +1052,7 @@ def _checkRepoName(self, inputcheck):
def _checkRepoProxy(self, inputcheck):
# Input object contains repo name
- repo = self._get_repo_by_name(inputcheck.input_obj)
+ repo = self._get_repo_by_id(inputcheck.input_obj)
# If nfs is selected as the protocol, skip the proxy check
if repo.baseurl.startswith(PROTOCOL_NFS):
return InputCheck.CHECK_OK
@@ -1243,6 +1245,8 @@ def _reset_repoStore(self):
If the list has no element, clear the repo entry fields.
"""
+ log.debug("Clearing checks in source spoke")
+
# Remove the repo checks
for checks in self._repoChecks.values():
self.remove_check(checks.name_check)
@@ -1262,6 +1266,8 @@ def _reset_repoStore(self):
enabled=repo.enabled)
# Track the original name, user may change .name
ks_repo.orig_name = name
+ # Add addon repository id for identification
+ ks_repo.repo_id = next(self._repo_counter)
self._repoStore.append([self.payload.isRepoEnabled(name),
ks_repo.name,
ks_repo])
@@ -1300,11 +1306,12 @@ 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"""
+ def _get_repo_by_id(self, repo_id):
+ """ Return a repository by given name
+ """
for repo in self._repoStore:
- if repo.name == name:
- return repo
+ if repo[REPO_OBJ].repo_id == repo_id:
+ return repo[REPO_OBJ]
return None
def on_repoSelection_changed(self, *args):
@@ -1428,6 +1435,8 @@ def on_addRepo_clicked(self, button):
repo = self.data.RepoData(name=name)
repo.ks_repo = True
repo.orig_name = ""
+ # Set addon repo id and increment counter
+ repo.repo_id = next(self._repo_counter)
itr = self._repoStore.append([True, repo.name, repo])
self._repoSelection.select_iter(itr)
@@ -1442,10 +1451,10 @@ def on_removeRepo_clicked(self, button):
# Remove the input validation checks for this repo
repo = self._repoStore[itr][REPO_OBJ]
- self.remove_check(self._repoChecks[repo.name].name_check)
- self.remove_check(self._repoChecks[repo.name].url_check)
- self.remove_check(self._repoChecks[repo.name].proxy_check)
- del self._repoChecks[repo.name]
+ self.remove_check(self._repoChecks[repo.repo_id].name_check)
+ self.remove_check(self._repoChecks[repo.repo_id].url_check)
+ self.remove_check(self._repoChecks[repo.repo_id].proxy_check)
+ del self._repoChecks[repo.repo_id]
self._repoStore.remove(itr)
if len(self._repoStore) == 0:
@@ -1466,17 +1475,12 @@ def on_repoNameEntry_changed(self, entry):
repo = self._repoStore[itr][REPO_OBJ]
name = self._repoNameEntry.get_text().strip()
- old_name = repo.name
- if name == old_name:
- # nothing changed
- return
-
repo.name = name
self._repoStore.set_value(itr, REPO_NAME_COL, name)
-
- self._repoChecks[name] = self._repoChecks[old_name]
- del self._repoChecks[old_name]
- self._repoChecks[name].name_check.update_check_status()
+ # do not update check status if check are not yet set up
+ # (populationg/refreshing the spoke)
+ if repo.repo_id in self._repoChecks:
+ self._repoChecks[repo.repo_id].name_check.update_check_status()
def on_repoUrl_changed(self, editable, data=None):
""" proxy url or protocol changed
@@ -1493,7 +1497,10 @@ def on_repoUrl_changed(self, editable, data=None):
else:
repo.baseurl = proto + url
- self._repoChecks[repo.name].url_check.update_check_status()
+ # do not update check status if check are not yet set up
+ # (populationg/refreshing the spoke)
+ if repo.repo_id in self._repoChecks:
+ self._repoChecks[repo.repo_id].url_check.update_check_status()
# Check for and remove a URL prefix that matches the protocol dropdown
self._removeUrlPrefix(editable, self._repoProtocolComboBox, self.on_repoUrl_changed)
@@ -1530,7 +1537,7 @@ def on_repoProxy_changed(self, *args):
# do not update check status if checks are not yet set up
# (populating/refreshing the spoke)
if repo.name in self._repoChecks:
- self._repoChecks[repo.name].proxy_check.update_check_status()
+ self._repoChecks[repo.repo_id].proxy_check.update_check_status()
try:
proxy = ProxyString(url=url, username=username, password=password)
@@ -1560,13 +1567,16 @@ def on_repoStore_row_inserted(self, model, path, itr, user_data=None):
# to this method is different from the iter used everywhere else, and is useless
# once this method returns. Instead, create a TreeRowReference and work backwards
# from that using paths any time we need to reference the store.
- self._repoChecks[repo.name] = RepoChecks(InputCheckHandler.add_check(self, self._repoNameEntry,
+ self._repoChecks[repo.repo_id] = RepoChecks(InputCheckHandler.add_check(self,
+ repo.repo_id,
self._checkRepoName,
Gtk.TreeRowReference.new(model, path)),
- InputCheckHandler.add_check(self, self._repoUrlEntry,
+ InputCheckHandler.add_check(self,
+ repo.repo_id,
self._checkRepoURL,
Gtk.TreeRowReference.new(model, path)),
- InputCheckHandler.add_check(self, self._repoProxyUrlEntry,
+ InputCheckHandler.add_check(self,
+ repo.repo_id,
self._checkRepoProxy,
Gtk.TreeRowReference.new(model, path)))
@@ -1582,7 +1592,7 @@ def on_repoProtocolComboBox_changed(self, combobox, user_data=None):
itr = self._repoSelection.get_selected()[1]
if itr:
repo = self._repoStore[itr][REPO_OBJ]
- self._repoChecks[repo.name].proxy_check.update_check_status()
+ self._repoChecks[repo.repo_id].proxy_check.update_check_status()
# Run the URL entry handler too as it might be needed
self._repoUrlEntry.emit("changed")
--
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/10161a103c457022a16b17171726de273b141b40
More information about the anaconda-patches
mailing list