Split out an EbuildIpcDaemon class from FifoIpcDaemon.
authorZac Medico <zmedico@gentoo.org>
Fri, 13 Aug 2010 03:46:53 +0000 (20:46 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 13 Aug 2010 03:46:53 +0000 (20:46 -0700)
pym/_emerge/EbuildIpcDaemon.py [new file with mode: 0644]
pym/_emerge/FifoIpcDaemon.py
pym/portage/tests/ebuild/test_ipc_daemon.py

diff --git a/pym/_emerge/EbuildIpcDaemon.py b/pym/_emerge/EbuildIpcDaemon.py
new file mode 100644 (file)
index 0000000..48f5822
--- /dev/null
@@ -0,0 +1,52 @@
+# Copyright 2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+import array
+import pickle
+from portage import os
+from _emerge.FifoIpcDaemon import FifoIpcDaemon
+from _emerge.PollConstants import PollConstants
+
+class EbuildIpcDaemon(FifoIpcDaemon):
+       """
+    This class serves as an IPC daemon, which ebuild processes can use
+    to communicate with portage's main python process.
+
+    Here are a few possible uses:
+
+    1) Robust subshell/subprocess die support. This allows the ebuild
+       environment to reliably die without having to rely on signal IPC.
+
+    2) Delegation of portageq calls to the main python process, eliminating
+       performance and userpriv permission issues.
+
+    3) Reliable ebuild termination in cases when the ebuild has accidentally
+       left orphan processes running in the backgraound (as in bug 278895).
+       """
+
+       __slots__ = ()
+
+       def _input_handler(self, fd, event):
+
+               if event & PollConstants.POLLIN:
+
+                       buf = array.array('B')
+                       try:
+                               buf.fromfile(self._files.pipe_in, self._bufsize)
+                       except (EOFError, IOError):
+                               pass
+
+                       if buf:
+                               obj = pickle.loads(buf.tostring())
+                               if isinstance(obj, list) and \
+                                       obj and \
+                                       obj[0] == 'exit':
+                                       output_fd = os.open(self.output_fifo, os.O_WRONLY|os.O_NONBLOCK)
+                                       output_file = os.fdopen(output_fd, 'wb')
+                                       pickle.dump('OK', output_file)
+                                       output_file.close()
+                                       self._unregister()
+                                       self.wait()
+
+               self._unregister_if_appropriate(event)
+               return self._registered
index 16bc786ae6af46ac230eed0483ee2453f755aceb..60a5096a5443be08656f0abaa54254aa07793525 100644 (file)
@@ -1,31 +1,12 @@
 # Copyright 2010 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
-import array
-import pickle
 from portage import os
 from _emerge.AbstractPollTask import AbstractPollTask
-from _emerge.PollConstants import PollConstants
 from portage.cache.mappings import slot_dict_class
 
 class FifoIpcDaemon(AbstractPollTask):
 
-       """
-    This class serves as an IPC daemon, which ebuild processes can use
-    to communicate with portage's main python process.
-
-    Here are a few possible uses:
-
-    1) Robust subshell/subprocess die support. This allows the ebuild
-       environment to reliably die without having to rely on signal IPC.
-
-    2) Delegation of portageq calls to the main python process, eliminating
-       performance and userpriv permission issues.
-
-    3) Reliable ebuild termination in cases when the ebuild has accidentally
-       left orphan processes running in the backgraound (as in bug 278895).
-       """
-
        __slots__ = ("input_fifo", "output_fifo",) + \
                ("_files", "_reg_id",)
 
@@ -67,29 +48,7 @@ class FifoIpcDaemon(AbstractPollTask):
                return self.returncode
 
        def _input_handler(self, fd, event):
-
-               if event & PollConstants.POLLIN:
-
-                       buf = array.array('B')
-                       try:
-                               buf.fromfile(self._files.pipe_in, self._bufsize)
-                       except (EOFError, IOError):
-                               pass
-
-                       if buf:
-                               obj = pickle.loads(buf.tostring())
-                               if isinstance(obj, list) and \
-                                       obj and \
-                                       obj[0] == 'exit':
-                                       output_fd = os.open(self.output_fifo, os.O_WRONLY|os.O_NONBLOCK)
-                                       output_file = os.fdopen(output_fd, 'wb')
-                                       pickle.dump('OK', output_file)
-                                       output_file.close()
-                                       self._unregister()
-                                       self.wait()
-
-               self._unregister_if_appropriate(event)
-               return self._registered
+               raise NotImplementedError(self)
 
        def _unregister(self):
                """
index c3d0ae2e44bba0886bada3eadf87823157c0d070..488bd3999050eafc3067e4986f132a55e58b9231 100644 (file)
@@ -9,7 +9,7 @@ from portage.const import PORTAGE_BIN_PATH
 from portage.const import PORTAGE_PYM_PATH
 from portage.const import BASH_BINARY
 from _emerge.SpawnProcess import SpawnProcess
-from _emerge.FifoIpcDaemon import FifoIpcDaemon
+from _emerge.EbuildIpcDaemon import EbuildIpcDaemon
 from _emerge.TaskScheduler import TaskScheduler
 
 class IpcDaemonTestCase(TestCase):
@@ -26,7 +26,7 @@ class IpcDaemonTestCase(TestCase):
                        os.mkfifo(input_fifo)
                        os.mkfifo(output_fifo)
                        task_scheduler = TaskScheduler(max_jobs=2)
-                       daemon = FifoIpcDaemon(input_fifo=input_fifo,
+                       daemon = EbuildIpcDaemon(input_fifo=input_fifo,
                                output_fifo=output_fifo,
                                scheduler=task_scheduler.sched_iface)
                        proc = SpawnProcess(