[PATCH 2/8] Move addDriverRepo into PackagePayload class

Brian C. Lane bcl at redhat.com
Thu Jul 10 00:06:07 UTC 2014


This is a common routine that will need to be used by all payload
classes to make sure the drivers are added to the installed system.
---
 pyanaconda/packaging/__init__.py   | 59 +++++++++++++++++++++++++++++++++-----
 pyanaconda/packaging/dnfpayload.py |  1 +
 pyanaconda/packaging/yumpayload.py | 50 +-------------------------------
 3 files changed, 54 insertions(+), 56 deletions(-)

diff --git a/pyanaconda/packaging/__init__.py b/pyanaconda/packaging/__init__.py
index ac2aeb2..a66ded3 100644
--- a/pyanaconda/packaging/__init__.py
+++ b/pyanaconda/packaging/__init__.py
@@ -34,6 +34,7 @@ from urlgrabber.grabber import URLGrabError
 import ConfigParser
 import shutil
 import time
+from glob import glob
 
 if __name__ == "__main__":
     from pyanaconda import anaconda_log
@@ -337,7 +338,6 @@ class Payload(object):
         self.data.packages.excludedList.append(pkgid)
 
     def _updateKernelVersionList(self):
-        import glob
         try:
             import yum
         except ImportError:
@@ -345,8 +345,8 @@ class Payload(object):
         else:
             cmpfunc = yum.rpmUtils.miscutils.compareVerOnly
 
-        files = glob.glob(iutil.getSysroot() + "/boot/vmlinuz-*")
-        files.extend(glob.glob(iutil.getSysroot() + "/boot/efi/EFI/%s/vmlinuz-*" % self.instclass.efi_dir))
+        files = glob(iutil.getSysroot() + "/boot/vmlinuz-*")
+        files.extend(glob(iutil.getSysroot() + "/boot/efi/EFI/%s/vmlinuz-*" % self.instclass.efi_dir))
 
         versions = sorted((f.split("/")[-1][8:] for f in files if os.path.isfile(f)), cmp=cmpfunc)
         log.debug("kernel versions: %s", versions)
@@ -547,18 +547,16 @@ class Payload(object):
                 f.write("blacklist %s\n" % module)
 
     def _copyDriverDiskFiles(self):
-        import glob
-
         # Multiple driver disks may be loaded, so we need to glob for all
         # the firmware files in the common DD firmware directory
-        for f in glob.glob(DD_FIRMWARE+"/*"):
+        for f in glob(DD_FIRMWARE+"/*"):
             try:
                 shutil.copyfile(f, "%s/lib/firmware/" % iutil.getSysroot())
             except IOError as e:
                 log.error("Could not copy firmware file %s: %s", f, e.strerror)
 
         #copy RPMS
-        for d in glob.glob(DD_RPMS):
+        for d in glob(DD_RPMS):
             shutil.copytree(d, iutil.getSysroot() + "/root/" + os.path.basename(d))
 
         #copy modules and firmware into root's home directory
@@ -970,6 +968,53 @@ class PackagePayload(Payload):
         """A list of repo identifiers, not objects themselves."""
         raise NotImplementedError()
 
+    def addDriverRepos(self):
+        """ Add driver repositories and packages
+        """
+        # Drivers are loaded by anaconda-dracut, their repos are copied
+        # into /run/install/DD-X where X is a number starting at 1. The list of
+        # packages that were selected is in /run/install/dd_packages
+
+        # Add repositories
+        dir_num = 0
+        while True:
+            dir_num += 1
+            repo = "/run/install/DD-%d/" % dir_num
+            if not os.path.isdir(repo):
+                break
+
+            # Drivers are under /<arch>/ or /DD-net/
+            if os.path.isdir(repo+"DD-net"):
+                repo += "DD-net"
+            elif os.path.isdir(repo+blivet.arch.getArch()):
+                repo += blivet.arch.getArch()
+            else:
+                log.debug("No driver repo in %s", repo)
+                continue
+
+            # Run createrepo if there are rpms and no repodata
+            if not os.path.isdir(repo+"/repodata"):
+                rpms = glob(repo+"/*rpm")
+                if not rpms:
+                    continue
+                log.info("Running createrepo on %s", repo)
+                iutil.execWithRedirect("createrepo_c", [repo])
+
+            ks_repo = self.data.RepoData(name="DD-%d" % dir_num,
+                                         baseurl="file://"+repo,
+                                         enabled=True)
+            self.addRepo(ks_repo)
+
+        # Add packages
+        if not os.path.exists("/run/install/dd_packages"):
+            return
+        with open("/run/install/dd_packages", "r") as f:
+            for line in f:
+                package = line.strip()
+                if package not in self._requiredPackages:
+                    self._requiredPackages.append(package)
+        log.debug("required packages = %s", self._requiredPackages)
+
     ###
     ### METHODS FOR WORKING WITH ENVIRONMENTS
     ###
diff --git a/pyanaconda/packaging/dnfpayload.py b/pyanaconda/packaging/dnfpayload.py
index aaf59cb..3825be1 100644
--- a/pyanaconda/packaging/dnfpayload.py
+++ b/pyanaconda/packaging/dnfpayload.py
@@ -554,6 +554,7 @@ class DNFPayload(packaging.PackagePayload):
         super(DNFPayload, self).preInstall()
         self.requiredPackages = packages
         self.requiredGroups = groups
+        self.addDriverRepos()
 
     def release(self):
         pass
diff --git a/pyanaconda/packaging/yumpayload.py b/pyanaconda/packaging/yumpayload.py
index 8080e71..6dca7f6 100644
--- a/pyanaconda/packaging/yumpayload.py
+++ b/pyanaconda/packaging/yumpayload.py
@@ -40,7 +40,6 @@ import os
 import shutil
 import sys
 import time
-from glob import glob
 from pyanaconda.iutil import execReadlines
 from functools import wraps
 
@@ -1256,53 +1255,6 @@ reposdir=%s
         self._select_kernel_package()
         self.selectRequiredPackages()
 
-    def _addDriverRepos(self):
-        """ Add driver repositories and packages
-        """
-        # Drivers are loaded by anaconda-dracut, their repos are copied
-        # into /run/install/DD-X where X is a number starting at 1. The list of
-        # packages that were selected is in /run/install/dd_packages
-
-        # Add repositories
-        dir_num = 0
-        while True:
-            dir_num += 1
-            repo = "/run/install/DD-%d/" % dir_num
-            if not os.path.isdir(repo):
-                break
-
-            # Drivers are under /<arch>/ or /DD-net/
-            if os.path.isdir(repo+"DD-net"):
-                repo += "DD-net"
-            elif os.path.isdir(repo+blivet.arch.getArch()):
-                repo += blivet.arch.getArch()
-            else:
-                log.debug("No driver repo in %s", repo)
-                continue
-
-            # Run createrepo if there are rpms and no repodata
-            if not os.path.isdir(repo+"/repodata"):
-                rpms = glob(repo+"/*rpm")
-                if not rpms:
-                    continue
-                log.info("Running createrepo on %s", repo)
-                iutil.execWithRedirect("createrepo_c", [repo])
-
-            ks_repo = self.data.RepoData(name="DD-%d" % dir_num,
-                                         baseurl="file://"+repo,
-                                         enabled=True)
-            self.addRepo(ks_repo)
-
-        # Add packages
-        if not os.path.exists("/run/install/dd_packages"):
-            return
-        with open("/run/install/dd_packages", "r") as f:
-            for line in f:
-                package = line.strip()
-                if package not in self._requiredPackages:
-                    self._requiredPackages.append(package)
-        log.debug("required packages = %s", self._requiredPackages)
-
     def checkSoftwareSelection(self):
         log.info("checking software selection")
         self.txID = time.time()
@@ -1386,7 +1338,7 @@ reposdir=%s
         self.requiredPackages = packages
         self.requiredGroups = groups
 
-        self._addDriverRepos()
+        self.addDriverRepos()
 
         if self.install_device:
             self._setupMedia(self.install_device)
-- 
1.9.3



More information about the anaconda-patches mailing list