Ejemplo n.º 1
0
 def ungrab_pm(self, *ignored, **kwignored):
     if self.cachedir:
         with lockfile(j(self.cachedir, "ifz-lockfile")):
             while self.cachemounts:
                 while ismount(self.cachemounts[-1]):
                     logger.debug("Unmounting %s", self.cachemounts[-1])
                     umount(self.cachemounts[-1])
                 os.rmdir(self.cachemounts[-1])
                 self.cachemounts.pop()
     if self.pkgmgr_config:
         self.pkgmgr_config.close()
         self.pkgmgr_config = None
Ejemplo n.º 2
0
 def ungrab_pm(self, *ignored, **kwignored):
     if self.cachedir:
         with lockfile(j(self.cachedir, "ifz-lockfile")):
             while self.cachemounts:
                 while ismount(self.cachemounts[-1]):
                     logger.debug("Unmounting %s", self.cachemounts[-1])
                     umount(self.cachemounts[-1])
                 os.rmdir(self.cachemounts[-1])
                 self.cachemounts.pop()
     if self.pkgmgr_config:
         self.pkgmgr_config.close()
         self.pkgmgr_config = None
Ejemplo n.º 3
0
    def grab_pm(self, method):
        if self.cachemounts or self.pkgmgr_config:
            assert 0, "programming error, invalid state, cannot enter without exiting first"

        if method == "in_chroot":
            dirforconfig = self.chroot
            if os.path.isfile(j(self.chroot, "etc", "dnf", "dnf.conf")):
                sourceconf = j(self.chroot, "etc", "dnf", "dnf.conf")
                pkgmgr = "dnf"
            elif os.path.isfile(j(self.chroot, "etc", "yum.conf")):
                sourceconf = j(self.chroot, "etc", "yum.conf")
                pkgmgr = "yum"
            else:
                raise Exception("Cannot use in_chroot method without a working yum or DNF inside the chroot")
            ver = self.releasever
        elif method == "out_of_chroot":
            dirforconfig = os.getenv("TMPDIR") or "/tmp"
            if os.path.exists("/etc/dnf/dnf.conf"):
                sourceconf = "/etc/dnf/dnf.conf"
                pkgmgr = "dnf"
            elif os.path.exists("/etc/yum.conf"):
                sourceconf = "/etc/yum.conf"
                pkgmgr = "yum"
            else:
                raise Exception("Cannot use out_of_chroot method without a working yum or DNF installed on your system")
            ver = self.myreleasever
        else:
            assert 0, "method unknown: %r" % method

        parms = dict(
            source=sourceconf,
            directory=dirforconfig,
            logfile="/dev/null",
            debuglevel=2,
            reposdir="/nonexistent",
            include=None,
            keepcache=1 if pkgmgr == "yum" else True,
        )

        # /yumcache
        if self.cachedir:
            makedirs([self.cachedir])
            with lockfile(j(self.cachedir, "ifz-lockfile")):
                # /yumcache/(dnf|yum)/(ver)/(lib|cache)
                persistdir = j(self.cachedir, pkgmgr, str(ver), "lib")
                cachedir   = j(self.cachedir, pkgmgr, str(ver), "cache")
                makedirs([persistdir, cachedir])
                # /yumcache/(dnf|yum)/(ver)/lock
                # /chroot/var/(lib|cache)/(dnf|yum)
                persistin, cachein = makedirs([
                    j(self.chroot, "tmp-%s-%s" % (pkgmgr, x))
                    for x in ["lib", "cache"]
                ])
                maybemounted = [persistin, cachein]
                while maybemounted:
                    while ismount(maybemounted[-1]):
                        logger.debug("Preemptively unmounting %s", maybemounted[-1])
                        umount(maybemounted[-1])
                    maybemounted.pop()
                for x, y in ([persistdir, persistin], [cachedir, cachein]):
                    logger.debug("Mounting %s to %s", x, y)
                    self.cachemounts.append(bindmount(x, y))
            # /var/(lib|cache)/(dnf|yum)
            parms["persistdir"] = persistin[len(self.chroot):]
            parms["cachedir"] = cachein[len(self.chroot):]
            lock = lockfile(j(self.cachedir, pkgmgr, str(ver), "lock"))
        else:
            lock = dummylock()

        self.pkgmgr_config = make_temp_yum_config(**parms)
        return pkgmgr, self.pkgmgr_config, lock
Ejemplo n.º 4
0
    def grab_pm(self, method):
        if self.cachemounts or self.pkgmgr_config:
            assert 0, "programming error, invalid state, cannot enter without exiting first"

        if method == "in_chroot":
            dirforconfig = self.chroot
            if os.path.isfile(j(self.chroot, "etc", "dnf", "dnf.conf")):
                sourceconf = j(self.chroot, "etc", "dnf", "dnf.conf")
                pkgmgr = "dnf"
            elif os.path.isfile(j(self.chroot, "etc", "yum.conf")):
                sourceconf = j(self.chroot, "etc", "yum.conf")
                pkgmgr = "yum"
            else:
                raise Exception("Cannot use in_chroot method without a working yum or DNF inside the chroot")
            ver = self.releasever
        elif method == "out_of_chroot":
            dirforconfig = os.getenv("TMPDIR") or "/tmp"
            if os.path.exists("/etc/dnf/dnf.conf"):
                sourceconf = "/etc/dnf/dnf.conf"
                pkgmgr = "dnf"
            elif os.path.exists("/etc/yum.conf"):
                sourceconf = "/etc/yum.conf"
                pkgmgr = "yum"
            else:
                raise Exception("Cannot use out_of_chroot method without a working yum or DNF installed on your system")
            ver = self.myreleasever
        else:
            assert 0, "method unknown: %r" % method

        parms = dict(
            source=sourceconf,
            directory=dirforconfig,
            logfile="/dev/null",
            debuglevel=2,
            reposdir="/nonexistent",
            include=None,
            keepcache=1 if pkgmgr == "yum" else True,
        )

        # /yumcache
        if self.cachedir:
            makedirs([self.cachedir])
            with lockfile(j(self.cachedir, "ifz-lockfile")):
                # /yumcache/(dnf|yum)/(ver)/(lib|cache)
                persistdir = j(self.cachedir, pkgmgr, str(ver), "lib")
                cachedir   = j(self.cachedir, pkgmgr, str(ver), "cache")
                makedirs([persistdir, cachedir])
                # /yumcache/(dnf|yum)/(ver)/lock
                lock = lockfile(j(self.cachedir, pkgmgr, str(ver), "lock"))
                # /chroot/var/(lib|cache)/(dnf|yum)
                persistin, cachein = makedirs([
                    j(self.chroot, "tmp-%s-%s" % (pkgmgr, x))
                    for x in ["lib", "cache"]
                ])
                maybemounted = [persistin, cachein]
                while maybemounted:
                    while ismount(maybemounted[-1]):
                        logger.debug("Preemptively unmounting %s", maybemounted[-1])
                        umount(maybemounted[-1])
                    maybemounted.pop()
                for x, y in ([persistdir, persistin], [cachedir, cachein]):
                    logger.debug("Mounting %s to %s", x, y)
                    self.cachemounts.append(bindmount(x, y))
            # /var/(lib|cache)/(dnf|yum)
            parms["persistdir"] = persistin[len(self.chroot):]
            parms["cachedir"] = cachein[len(self.chroot):]
        else:
            lock = dummylock()

        self.pkgmgr_config = make_temp_yum_config(**parms)
        return pkgmgr, self.pkgmgr_config, lock