Convert EbuildBinpkg to inherit from MiscFunctionsProcess instead
authorZac Medico <zmedico@gentoo.org>
Mon, 16 Aug 2010 11:57:08 +0000 (04:57 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 16 Aug 2010 11:57:08 +0000 (04:57 -0700)
of EbuildProcess. This bypasses the complex doebuild() function,
and uses the _spawn_actionmap() function that's been split out.

pym/_emerge/EbuildBinpkg.py
pym/_emerge/MiscFunctionsProcess.py

index 103f2b5f1f32234fa8bc00d51ddaff8f8c21c00a..0ec2871af2f6e4da2051a5dfc1e80d4a41c57397 100644 (file)
@@ -1,46 +1,53 @@
-# Copyright 1999-2009 Gentoo Foundation
+# Copyright 1999-2010 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
-from _emerge.EbuildProcess import EbuildProcess
+from _emerge.MiscFunctionsProcess import MiscFunctionsProcess
 from portage import os
+from portage.exception import PermissionDenied
+from portage.package.ebuild.doebuild import _spawn_actionmap
+from portage.package.ebuild.doebuild import spawn as doebuild_spawn
+from portage.util import ensure_dirs
 
-class EbuildBinpkg(EbuildProcess):
+class EbuildBinpkg(MiscFunctionsProcess):
        """
        This assumes that src_install() has successfully completed.
        """
        __slots__ = ("_binpkg_tmpfile",)
 
+       def __init__(self, **kwargs):
+               MiscFunctionsProcess.__init__(self, phase="package", **kwargs)
+
        def _start(self):
-               self.phase = "package"
-               self.tree = "porttree"
                pkg = self.pkg
                root_config = pkg.root_config
-               portdb = root_config.trees["porttree"].dbapi
                bintree = root_config.trees["bintree"]
-               ebuild_path = portdb.findname(pkg.cpv)
-               if ebuild_path is None:
-                       raise AssertionError("ebuild not found for '%s'" % pkg.cpv)
-               settings = self.settings
-               debug = settings.get("PORTAGE_DEBUG") == "1"
-
                bintree.prevent_collision(pkg.cpv)
                binpkg_tmpfile = os.path.join(bintree.pkgdir,
                        pkg.cpv + ".tbz2." + str(os.getpid()))
-               self._binpkg_tmpfile = binpkg_tmpfile
-               settings["PORTAGE_BINPKG_TMPFILE"] = binpkg_tmpfile
-               settings.backup_changes("PORTAGE_BINPKG_TMPFILE")
+               parent_dir = os.path.dirname(binpkg_tmpfile)
+               ensure_dirs(parent_dir)
+               if not os.access(parent_dir, os.W_OK):
+                       raise PermissionDenied(
+                               "access('%s', os.W_OK)" % parent_dir)
 
+               self._binpkg_tmpfile = binpkg_tmpfile
+               self.logfile = self.settings.get("PORTAGE_LOG_FILE")
+               self.commands = ["dyn_" + self.phase]
+               MiscFunctionsProcess._start(self)
+
+       def _spawn(self, args, **kwargs):
+               self.settings["EBUILD_PHASE"] = self.phase
+               self.settings["PORTAGE_BINPKG_TMPFILE"] = self._binpkg_tmpfile
+               kwargs.update(_spawn_actionmap(self.settings)[self.phase]["args"])
                try:
-                       EbuildProcess._start(self)
+                       return doebuild_spawn(" ".join(args), self.settings, **kwargs)
                finally:
-                       settings.pop("PORTAGE_BINPKG_TMPFILE", None)
+                       self.settings.pop("EBUILD_PHASE", None)
+                       self.settings.pop("PORTAGE_BINPKG_TMPFILE", None)
 
        def _set_returncode(self, wait_retval):
-               EbuildProcess._set_returncode(self, wait_retval)
-
-               pkg = self.pkg
-               bintree = pkg.root_config.trees["bintree"]
-               binpkg_tmpfile = self._binpkg_tmpfile
+               MiscFunctionsProcess._set_returncode(self, wait_retval)
                if self.returncode == os.EX_OK:
-                       bintree.inject(pkg.cpv, filename=binpkg_tmpfile)
-
+                       pkg = self.pkg
+                       bintree = pkg.root_config.trees["bintree"]
+                       bintree.inject(pkg.cpv, filename=self._binpkg_tmpfile)
index eaf8c2235b12d378fd2aef5fb6c5de30665178bf..04445a89d825aa7452ce77b1f22dab00f7357a8a 100644 (file)
@@ -15,7 +15,6 @@ class MiscFunctionsProcess(AbstractEbuildProcess):
 
        def _start(self):
                settings = self.settings
-               settings.pop("EBUILD_PHASE", None)
                portage_bin_path = settings["PORTAGE_BIN_PATH"]
                misc_sh_binary = os.path.join(portage_bin_path,
                        os.path.basename(portage.const.MISC_SH_BINARY))
@@ -26,7 +25,5 @@ class MiscFunctionsProcess(AbstractEbuildProcess):
                AbstractEbuildProcess._start(self)
 
        def _spawn(self, args, **kwargs):
-               settings = self.settings
-               debug = settings.get("PORTAGE_DEBUG") == "1"
-               return spawn(" ".join(args), settings,
-                       debug=debug, **kwargs)
+               self.settings.pop("EBUILD_PHASE", None)
+               return spawn(" ".join(args), self.settings, **kwargs)