PackageUninstall: use _unmerge_display()
authorZac Medico <zmedico@gentoo.org>
Mon, 23 May 2011 22:12:24 +0000 (15:12 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 23 May 2011 22:12:24 +0000 (15:12 -0700)
This is preparation for asynchronous support.

pym/_emerge/PackageUninstall.py

index 5e8850b180f65d0c06bdc099480625ed3498555c..0e913071398e155136fdb978dfaf11ed02d9ce06 100644 (file)
@@ -1,34 +1,51 @@
-# Copyright 1999-2010 Gentoo Foundation
+# Copyright 1999-2011 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import logging
 import portage
 from portage import os
-from _emerge.AsynchronousTask import AsynchronousTask
-from _emerge.unmerge import unmerge
-from _emerge.UninstallFailure import UninstallFailure
+from _emerge.emergelog import emergelog
+from _emerge.CompositeTask import CompositeTask
+from _emerge.unmerge import _unmerge_display
 
-class PackageUninstall(AsynchronousTask):
+class PackageUninstall(CompositeTask):
 
        __slots__ = ("world_atom", "ldpath_mtimes", "opts",
-                       "pkg", "scheduler", "settings")
+                       "pkg", "settings")
 
        def _start(self):
-               try:
-                       retval = unmerge(self.pkg.root_config, self.opts, "unmerge",
-                               [self.pkg.cpv], self.ldpath_mtimes, clean_world=0,
-                               clean_delay=0, raise_on_error=1, scheduler=self.scheduler,
-                               writemsg_level=self._writemsg_level)
-               except UninstallFailure as e:
-                       self.returncode = e.status
-               else:
-                       self.returncode = os.EX_OK
 
-                       if retval == 1:
-                               self.world_atom(self.pkg)
+               retval, pkgmap = _unmerge_display(self.pkg.root_config,
+                       self.opts, "unmerge", [self.pkg.cpv], clean_delay=0,
+                       writemsg_level=self._writemsg_level)
+
+               if retval != os.EX_OK:
+                       self.returncode = retval
+                       self.wait()
+                       return
+
+               self._writemsg_level(">>> Unmerging %s...\n" % (self.pkg.cpv,),
+                       noiselevel=-1)
+               self._emergelog("=== Unmerging... (%s)" % (self.pkg.cpv,))
+
+               cat, pf = portage.catsplit(self.pkg.cpv)
+               retval = portage.unmerge(cat, pf, settings=self.settings,
+                       vartree=self.pkg.root_config.trees["vartree"],
+                       ldpath_mtimes=self.ldpath_mtimes,
+                       scheduler=self.scheduler)
 
+               if retval != os.EX_OK:
+                       self._emergelog(" !!! unmerge FAILURE: %s" % (self.pkg.cpv,))
+               else:
+                       self._emergelog(" >>> unmerge success: %s" % (self.pkg.cpv,))
+                       self.world_atom(self.pkg)
+
+               self.returncode = retval
                self.wait()
 
+       def _emergelog(self, msg):
+               emergelog("notitles" not in self.settings.features, msg)
+
        def _writemsg_level(self, msg, level=0, noiselevel=0):
 
                log_path = self.settings.get("PORTAGE_LOG_FILE")