From: Zac Medico Date: Sun, 6 Jul 2008 01:24:29 +0000 (-0000) Subject: Split out a reusable CompositeTask._default_exit() method that subclasses X-Git-Tag: v2.2_rc2~188 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0e0963c4576f505888f8d12a818a895e0988044e;p=portage.git Split out a reusable CompositeTask._default_exit() method that subclasses can use as a generic task exit callback. svn path=/main/trunk/; revision=10950 --- diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index a16e532e9..56c909870 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -1536,6 +1536,22 @@ class CompositeTask(AsynchronousTask): if task is not self._current_task: raise AssertionError("Unrecognized task: %s" % (task,)) + def _default_exit(self, task): + """ + Calls _assert_current() on the given task and then sets the + composite returncode attribute if task.returncode != os.EX_OK. + If the task failed then self._current_task will be set to None. + Subclasses can use this as a generic task exit callback. + + @rtype: int + @returns: The task.returncode attribute. + """ + self._assert_current(task) + if task.returncode != os.EX_OK: + self.returncode = task.returncode + self._current_task = None + return task.returncode + class TaskSequence(CompositeTask): """ A collection of tasks that executes sequentially. Each task @@ -1566,15 +1582,9 @@ class TaskSequence(CompositeTask): task.start() def _task_exit_handler(self, task): - - self._assert_current(task) - if self._task_queue and \ - task.returncode == os.EX_OK: + if self._default_exit(task) == os.EX_OK and \ + self._task_queue: self._start_next_task() - return - - self._current_task = None - self.returncode = task.returncode class SubProcess(AsynchronousTask): __slots__ = ("pid",) @@ -1987,10 +1997,7 @@ class EbuildExecuter(CompositeTask): def _clean_phase_exit(self, clean_phase): - self._assert_current(clean_phase) - if clean_phase.returncode != os.EX_OK: - self.returncode = clean_phase.returncode - self._current_task = None + if self._default_exit(clean_phase) != os.EX_OK: return pkg = self.pkg @@ -2015,16 +2022,10 @@ class EbuildExecuter(CompositeTask): pkg=pkg, phase=phase, scheduler=scheduler, settings=settings, tree=tree)) - ebuild_phases.addExitListener(self._ebuild_phases_exit) + ebuild_phases.addExitListener(self._default_exit) self._current_task = ebuild_phases ebuild_phases.start() - def _ebuild_phases_exit(self, ebuild_phases): - - self._assert_current(ebuild_phases) - self.returncode = ebuild_phases.returncode - self._current_task = None - class EbuildPhase(SubProcess): __slots__ = ("fd_pipes", "phase", "pkg",