def _update_payload_repos(self): """ Change the packaging repos to match the new edits This will add new repos to the addon repo list, remove ones that were removed and update any changes made to existing ones. :returns: True if any repo was changed, added or removed :rtype: bool """ REPO_ATTRS=("name", "baseurl", "mirrorlist", "proxy", "enabled") changed = False ui_orig_names = [r[REPO_OBJ].orig_name for r in self._repoStore] # Remove repos from payload that were removed in the UI for repo_name in [r for r in self.payload.addOns if r not in ui_orig_names]: repo = self.payload.getAddOnRepo(repo_name) # TODO: Need an API to do this w/o touching yum (not addRepo) self.payload.data.repo.dataList().remove(repo) changed = True for repo, orig_repo in [(r[REPO_OBJ],self.payload.getAddOnRepo(r[REPO_OBJ].orig_name)) for r in self._repoStore]: if not orig_repo: # TODO: Need an API to do this w/o touching yum (not addRepo) self.payload.data.repo.dataList().append(repo) changed = True elif not cmp_obj_attrs(orig_repo, repo, REPO_ATTRS): for attr in REPO_ATTRS: setattr(orig_repo, attr, getattr(repo, attr)) changed = True return changed
def _update_payload_repos(self): """ Change the packaging repos to match the new edits This will add new repos to the addon repo list, remove ones that were removed and update any changes made to existing ones. :returns: True if any repo was changed, added or removed :rtype: bool """ REPO_ATTRS = ("name", "baseurl", "mirrorlist", "proxy", "enabled") changed = False for repo in [r[REPO_OBJ] for r in self._repoStore]: orig_repo = self.payload.getAddOnRepo(repo.orig_name) if not orig_repo: # TODO: Need an API to do this w/o touching yum (not addRepo) self.payload.data.repo.dataList().append(repo) changed = True elif not cmp_obj_attrs(orig_repo, repo, REPO_ATTRS): for attr in REPO_ATTRS: setattr(orig_repo, attr, getattr(repo, attr)) changed = True # Remove repos from payload that were removed in the UI ui_repo_names = [r[REPO_OBJ].name for r in self._repoStore] for repo_name in self.payload.addOns: if repo_name not in ui_repo_names: repo = self.payload.getAddOnRepo(repo_name) # TODO: Need an API to do this w/o touching yum (not addRepo) self.payload.data.repo.dataList().remove(repo) changed = True return changed
def cmp_obj_attrs_test(self): """Test cmp_obj_attrs.""" # pylint: disable=attribute-defined-outside-init class O(object): pass a = O() a.b = 1 a.c = 2 a1 = O() a1.b = 1 a1.c = 2 b = O() b.b = 1 b.c = 3 # a class should have it's own attributes self.assertTrue(iutil.cmp_obj_attrs(a, a, ["b", "c"])) self.assertTrue(iutil.cmp_obj_attrs(a1, a1, ["b", "c"])) self.assertTrue(iutil.cmp_obj_attrs(b, b, ["b", "c"])) # a and a1 should have the same attributes self.assertTrue(iutil.cmp_obj_attrs(a, a1, ["b", "c"])) self.assertTrue(iutil.cmp_obj_attrs(a1, a, ["b", "c"])) self.assertTrue(iutil.cmp_obj_attrs(a1, a, ["c", "b"])) # missing attributes are considered a mismatch self.assertFalse(iutil.cmp_obj_attrs(a, a1, ["b", "c", "d"])) # empty attribute list is not a mismatch self.assertTrue(iutil.cmp_obj_attrs(a, b, [])) # attributes of a and b differ self.assertFalse(iutil.cmp_obj_attrs(a, b, ["b", "c"])) self.assertFalse(iutil.cmp_obj_attrs(b, a, ["b", "c"])) self.assertFalse(iutil.cmp_obj_attrs(b, a, ["c", "b"]))