diff options
author | Zac Medico <zmedico@gentoo.org> | 2008-07-05 13:19:01 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2008-07-05 13:19:01 +0000 |
commit | d4d390c3675598095fe5a5c7390541c7d6387754 (patch) | |
tree | 8ee0a80284eb669ce11d6aaa5767c37d93b61b86 /pym/_emerge/__init__.py | |
parent | db0392e27195692d08d22a0c1caf941800f8d4df (diff) | |
download | portage-d4d390c3675598095fe5a5c7390541c7d6387754.tar.gz portage-d4d390c3675598095fe5a5c7390541c7d6387754.tar.bz2 portage-d4d390c3675598095fe5a5c7390541c7d6387754.zip |
Split out common code from CompositeTask and EbuildExecuter into a new
CompositeTask class and rename the old CompositeTask class to TaskSequence.
svn path=/main/trunk/; revision=10943
Diffstat (limited to 'pym/_emerge/__init__.py')
-rw-r--r-- | pym/_emerge/__init__.py | 71 |
1 files changed, 29 insertions, 42 deletions
diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index 622274185..33d7ea075 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -1499,29 +1499,13 @@ class AsynchronousTask(SlotObject): self._exit_listeners = None class CompositeTask(AsynchronousTask): - """ - A collection of tasks that executes sequentially. Each task - must have a _set_returncode() method that can be wrapped as - a means to trigger movement from one task to the next. - """ - - __slots__ = ("scheduler",) + ("_current_task", "_task_queue") - def __init__(self, **kwargs): - AsynchronousTask.__init__(self, **kwargs) - self._task_queue = deque() - - def add(self, task): - self._task_queue.append(task) - - def start(self): - self._start_next_task() + __slots__ = ("scheduler",) + ("_current_task",) def isAlive(self): return self._current_task is not None def cancel(self): - self._task_queue.clear() self.cancelled = True if self._current_task is not None: self._current_task.cancel() @@ -1532,12 +1516,36 @@ class CompositeTask(AsynchronousTask): task = self._current_task if task is None: break - self.scheduler.schedule(task.reg_id) + if hasattr(task, "reg_id"): + self.scheduler.schedule(task.reg_id) task.wait() self._wait_hook() return self.returncode +class TaskSequence(CompositeTask): + """ + A collection of tasks that executes sequentially. Each task + must have a _set_returncode() method that can be wrapped as + a means to trigger movement from one task to the next. + """ + + __slots__ = ("_task_queue",) + + def __init__(self, **kwargs): + AsynchronousTask.__init__(self, **kwargs) + self._task_queue = deque() + + def add(self, task): + self._task_queue.append(task) + + def start(self): + self._start_next_task() + + def cancel(self): + self._task_queue.clear() + CompositeTask.cancel(self) + def _start_next_task(self): self._current_task = self._task_queue.popleft() task = self._current_task @@ -1945,9 +1953,9 @@ class EbuildBuild(EbuildBuildDir): self.unlock() return os.EX_OK -class EbuildExecuter(AsynchronousTask): +class EbuildExecuter(CompositeTask): - __slots__ = ("pkg", "scheduler", "settings") + ("_current_task",) + __slots__ = ("pkg", "scheduler", "settings") _phases = ("setup", "unpack", "compile", "test", "install") @@ -1986,7 +1994,7 @@ class EbuildExecuter(AsynchronousTask): 2 : sys.stderr.fileno(), } - ebuild_phases = CompositeTask(scheduler=scheduler) + ebuild_phases = TaskSequence(scheduler=scheduler) for phase in self._phases: ebuild_phases.add(EbuildPhase(fd_pipes=fd_pipes, @@ -2001,27 +2009,6 @@ class EbuildExecuter(AsynchronousTask): self.returncode = ebuild_phases.returncode self._current_task = None - def isAlive(self): - return self._current_task is not None - - def cancel(self): - self.cancelled = True - if self._current_task is not None: - self._current_task.cancel() - - def wait(self): - - while True: - task = self._current_task - if task is None: - break - if hasattr(task, "reg_id"): - self.scheduler.schedule(task.reg_id) - task.wait() - - self._wait_hook() - return self.returncode - class EbuildPhase(SubProcess): __slots__ = ("fd_pipes", "phase", "pkg", |