[master 02/10] Modify repo interface in packaging

Brian C. Lane bcl at redhat.com
Tue Mar 12 00:13:29 UTC 2013


From: "Brian C. Lane" <bcl at redhat.com>

repo information is stored in 2 places, the kickstart data object, and
in the yum object (when using yumpayload). This changes the interface so
that AddOn methods reference the kickstart data and repo methods
reference the packaging data.

getRepo is now getAddOnRepo and a new getRepo has been added to
yumpayload that can be used to query the yum object.
---
 pyanaconda/packaging/__init__.py        | 10 +++++++++-
 pyanaconda/packaging/yumpayload.py      | 22 ++++++++++++++++------
 tests/pyanaconda_test/packaging_test.py |  4 ++--
 3 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/pyanaconda/packaging/__init__.py b/pyanaconda/packaging/__init__.py
index cba0f79..6fe79d2 100644
--- a/pyanaconda/packaging/__init__.py
+++ b/pyanaconda/packaging/__init__.py
@@ -139,7 +139,7 @@ class Payload(object):
     @property
     def addOns(self):
         """ A list of addon repo identifiers. """
-        return []
+        return [r.name for r in self.data.repo.dataList()]
 
     @property
     def baseRepo(self):
@@ -147,6 +147,14 @@ class Payload(object):
         return None
 
     def getRepo(self, repo_id):
+        """ Return the package repo object. """
+        raise NotImplementedError()
+
+    def isRepoEnabled(self, repo_id):
+        """ Return True if repo is enabled. """
+        raise NotImplementedError()
+
+    def getAddOnRepo(self, repo_id):
         """ Return a ksdata Repo instance matching the specified repo id. """
         repo = None
         for r in self.data.repo.dataList():
diff --git a/pyanaconda/packaging/yumpayload.py b/pyanaconda/packaging/yumpayload.py
index fe132f7..be0e730 100644
--- a/pyanaconda/packaging/yumpayload.py
+++ b/pyanaconda/packaging/yumpayload.py
@@ -297,7 +297,7 @@ reposdir=%s
 
         for repo in self._yum.repos.listEnabled():
             cfg_path = "%s/%s.repo" % (self._repos_dir, repo.id)
-            ks_repo = self.getRepo(repo.id)
+            ks_repo = self.getAddOnRepo(repo.id)
             with open(cfg_path, "w") as f:
                 f.write("[%s]\n" % repo.id)
                 f.write("name=Install - %s\n" % repo.id)
@@ -398,10 +398,6 @@ reposdir=%s
         return _repos
 
     @property
-    def addOns(self):
-        return [r.name for r in self.data.repo.dataList()]
-
-    @property
     def baseRepo(self):
         repo_names = [BASE_REPO_NAME] + default_repos
         base_repo_name = None
@@ -414,6 +410,20 @@ reposdir=%s
 
         return base_repo_name
 
+    def getRepo(self, repo_id):
+        """ Return the yum repo object. """
+        with _yum_lock:
+            repo = self._yum.repos.getRepo(repo_id)
+
+        return repo
+
+    def isRepoEnabled(self, repo_id):
+        """ Return True if repo is enabled. """
+        try:
+            return self.getRepo(repo_id).enabled
+        except Exception:
+            return False
+
     def updateBaseRepo(self, fallback=True, root=None, checkmount=True):
         """ Update the base repo based on self.data.method.
 
@@ -855,7 +865,7 @@ reposdir=%s
         mountpoint = None
         with _yum_lock:
             yum_repo = self._yum.repos.getRepo(repo_id)
-            ks_repo = self.getRepo(repo_id)
+            ks_repo = self.getAddOnRepo(repo_id)
             if yum_repo and ks_repo and ks_repo.baseurl.startswith("nfs:"):
                 mountpoint = yum_repo.baseurl[0][7:]    # strip leading "file://"
 
diff --git a/tests/pyanaconda_test/packaging_test.py b/tests/pyanaconda_test/packaging_test.py
index eb669b6..99bc871 100644
--- a/tests/pyanaconda_test/packaging_test.py
+++ b/tests/pyanaconda_test/packaging_test.py
@@ -41,13 +41,13 @@ class PackagingTest(mock.TestCase):
 
         # verify the repo was added
         self.assertEqual(self.payload.data.repo.dataList(), [repo])
-        self.assertEqual(self.payload.getRepo(repo_name), repo)
+        self.assertEqual(self.payload.getAddOnRepo(repo_name), repo)
 
         # remove the repo
         self.payload.removeRepo(repo_name)
 
         # verify the repo was removed
-        self.assertEqual(self.payload.getRepo(repo_name), None)
+        self.assertEqual(self.payload.getAddOnRepo(repo_name), None)
 
     def payload_group_test(self):
         import pykickstart.constants
-- 
1.8.1.2



More information about the anaconda-patches mailing list