Use IO_* constants where appropriate.
authorZac Medico <zmedico@gentoo.org>
Fri, 10 Feb 2012 01:27:13 +0000 (17:27 -0800)
committerZac Medico <zmedico@gentoo.org>
Fri, 10 Feb 2012 01:27:13 +0000 (17:27 -0800)
pym/_emerge/AbstractPollTask.py
pym/_emerge/AsynchronousLock.py
pym/_emerge/EbuildIpcDaemon.py
pym/_emerge/EbuildMetadataPhase.py
pym/_emerge/PollScheduler.py
pym/_emerge/Scheduler.py
pym/portage/dbapi/_MergeProcess.py

index 922905291d851a33bd23982b9b424a9a2410fc2b..68282efb5b1855287c99fa5eb08441f78131c71e 100644 (file)
@@ -8,16 +8,22 @@ import os
 
 from portage.util import writemsg_level
 from _emerge.AsynchronousTask import AsynchronousTask
-from _emerge.PollConstants import PollConstants
+
 class AbstractPollTask(AsynchronousTask):
 
        __slots__ = ("scheduler",) + \
                ("_registered",)
 
        _bufsize = 4096
-       _exceptional_events = PollConstants.POLLERR | PollConstants.POLLNVAL
-       _registered_events = PollConstants.POLLIN | PollConstants.POLLHUP | \
-               _exceptional_events
+
+       @property
+       def _exceptional_events(self):
+               return self.scheduler.IO_ERR | self.scheduler.IO_NVAL
+
+       @property
+       def _registered_events(self):
+               return self.scheduler.IO_IN | self.scheduler.IO_HUP | \
+                       self._exceptional_events
 
        def isAlive(self):
                return bool(self._registered)
@@ -39,7 +45,7 @@ class AbstractPollTask(AsynchronousTask):
                | 0      | None
                """
                buf = None
-               if event & PollConstants.POLLIN:
+               if event & self.scheduler.IO_IN:
                        buf = array.array('B')
                        try:
                                buf.fromfile(f, self._bufsize)
@@ -85,7 +91,7 @@ class AbstractPollTask(AsynchronousTask):
                # bugs in all known versions of Python (including Python 2.7
                # and Python 3.2).
                buf = None
-               if event & PollConstants.POLLIN:
+               if event & self.scheduler.IO_IN:
                        try:
                                buf = os.read(fd, self._bufsize)
                        except OSError as e:
@@ -117,7 +123,7 @@ class AbstractPollTask(AsynchronousTask):
                                self._log_poll_exception(event)
                                self._unregister()
                                self.cancel()
-                       elif event & PollConstants.POLLHUP:
+                       elif event & self.scheduler.IO_HUP:
                                self._unregister()
                                self.wait()
 
index 3cf0acbd54df76bafbb449bf3bbfaf9244709007..c07df0bddbde1ec217caa0becd929d92268b5835 100644 (file)
@@ -20,7 +20,6 @@ from portage.locks import lockfile, unlockfile
 from portage.util import writemsg_level
 from _emerge.AbstractPollTask import AbstractPollTask
 from _emerge.AsynchronousTask import AsynchronousTask
-from _emerge.PollConstants import PollConstants
 from _emerge.SpawnProcess import SpawnProcess
 
 class AsynchronousLock(AsynchronousTask):
@@ -118,7 +117,7 @@ class _LockThread(AbstractPollTask):
                        fcntl.fcntl(f, fcntl.F_SETFL,
                                fcntl.fcntl(f, fcntl.F_GETFL) | os.O_NONBLOCK)
                self._reg_id = self.scheduler.register(self._files['pipe_read'],
-                       PollConstants.POLLIN, self._output_handler)
+                       self.scheduler.IO_IN, self._output_handler)
                self._registered = True
                threading_mod = threading
                if self._force_dummy:
@@ -132,7 +131,7 @@ class _LockThread(AbstractPollTask):
 
        def _output_handler(self, f, event):
                buf = None
-               if event & PollConstants.POLLIN:
+               if event & self.scheduler.IO_IN:
                        try:
                                buf = os.read(self._files['pipe_read'], self._bufsize)
                        except OSError as e:
@@ -200,7 +199,7 @@ class _LockProcess(AbstractPollTask):
                fcntl.fcntl(in_pr, fcntl.F_SETFL,
                        fcntl.fcntl(in_pr, fcntl.F_GETFL) | os.O_NONBLOCK)
                self._reg_id = self.scheduler.register(in_pr,
-                       PollConstants.POLLIN, self._output_handler)
+                       self.scheduler.IO_IN, self._output_handler)
                self._registered = True
                self._proc = SpawnProcess(
                        args=[portage._python_interpreter,
@@ -268,7 +267,7 @@ class _LockProcess(AbstractPollTask):
 
        def _output_handler(self, f, event):
                buf = None
-               if event & PollConstants.POLLIN:
+               if event & self.scheduler.IO_IN:
                        try:
                                buf = os.read(self._files['pipe_in'], self._bufsize)
                        except OSError as e:
index 6a320cb07197375abe770f8731b6c2a4ef1d18c4..5795bfbdcd115a4ad1c961fbad40cbc6fcd6c32f 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2010-2011 Gentoo Foundation
+# Copyright 2010-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import errno
@@ -8,7 +8,6 @@ from portage import os
 from portage.localization import _
 from portage.util import writemsg_level
 from _emerge.FifoIpcDaemon import FifoIpcDaemon
-from _emerge.PollConstants import PollConstants
 
 class EbuildIpcDaemon(FifoIpcDaemon):
        """
@@ -34,7 +33,7 @@ class EbuildIpcDaemon(FifoIpcDaemon):
        def _input_handler(self, fd, event):
                # Read the whole pickle in a single atomic read() call.
                data = None
-               if event & PollConstants.POLLIN:
+               if event & self.scheduler.IO_IN:
                        # For maximum portability, use os.read() here since
                        # array.fromfile() and file.read() are both known to
                        # erroneously return an empty string from this
index f8da8667f30828fe0b69bd0815b7abbae6f6697f..a34542d4374252716a8e7da307b568ed99044a39 100644 (file)
@@ -1,8 +1,7 @@
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from _emerge.SubProcess import SubProcess
-from _emerge.PollConstants import PollConstants
 import sys
 from portage.cache.mappings import slot_dict_class
 import portage
@@ -111,7 +110,7 @@ class EbuildMetadataPhase(SubProcess):
 
        def _output_handler(self, fd, event):
 
-               if event & PollConstants.POLLIN:
+               if event & self.scheduler.IO_IN:
                        while True:
                                try:
                                        self._raw_metadata.append(
index 3b86fa08e572940b022690006b186e11eafd3eaf..eafb8a23780e5ccba9a08244e8ee318dc6223613 100644 (file)
@@ -20,7 +20,8 @@ from _emerge.getloadavg import getloadavg
 class PollScheduler(object):
 
        class _sched_iface_class(SlotObject):
-               __slots__ = ("idle_add", "io_add_watch", "iteration",
+               __slots__ = ("IO_ERR", "IO_HUP", "IO_IN", "IO_NVAL", "IO_OUT",
+                       "IO_PRI", "idle_add", "io_add_watch", "iteration",
                        "output", "register", "run",
                        "source_remove", "timeout_add", "unregister")
 
@@ -34,6 +35,12 @@ class PollScheduler(object):
                self._background = False
                self._event_loop = global_event_loop()
                self.sched_iface = self._sched_iface_class(
+                       IO_ERR=self._event_loop.IO_ERR,
+                       IO_HUP=self._event_loop.IO_HUP,
+                       IO_IN=self._event_loop.IO_IN,
+                       IO_NVAL=self._event_loop.IO_NVAL,
+                       IO_OUT=self._event_loop.IO_OUT,
+                       IO_PRI=self._event_loop.IO_PRI,
                        idle_add=self._event_loop.idle_add,
                        io_add_watch=self._event_loop.io_add_watch,
                        iteration=self._event_loop.iteration,
index 12f087119e147c445f80ab992b6eaafcec17dd37..674a11e49eea29da0123fd64c734282337fba352 100644 (file)
@@ -217,6 +217,12 @@ class Scheduler(PollScheduler):
                fetch_iface = self._fetch_iface_class(log_file=self._fetch_log,
                        schedule=self._schedule_fetch)
                self._sched_iface = self._iface_class(
+                       IO_ERR=self._event_loop.IO_ERR,
+                       IO_HUP=self._event_loop.IO_HUP,
+                       IO_IN=self._event_loop.IO_IN,
+                       IO_NVAL=self._event_loop.IO_NVAL,
+                       IO_OUT=self._event_loop.IO_OUT,
+                       IO_PRI=self._event_loop.IO_PRI,
                        fetch=fetch_iface, output=self._task_output,
                        idle_add=self._event_loop.idle_add,
                        io_add_watch=self._event_loop.io_add_watch,
index da278ea2ab62e6f1696d868e63f75cf9f90a85a9..9bb67c9b60c77f823c8de4877cbd3db299b622ce 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2010-2011 Gentoo Foundation
+# Copyright 2010-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import io
@@ -10,7 +10,6 @@ import fcntl
 import portage
 from portage import os, _unicode_decode
 import portage.elog.messages
-from _emerge.PollConstants import PollConstants
 from _emerge.SpawnProcess import SpawnProcess
 
 class MergeProcess(SpawnProcess):
@@ -63,7 +62,7 @@ class MergeProcess(SpawnProcess):
 
        def _elog_output_handler(self, fd, event):
                output = None
-               if event & PollConstants.POLLIN:
+               if event & self.scheduler.IO_IN:
                        try:
                                output = os.read(fd, self._bufsize)
                        except OSError as e:
@@ -83,7 +82,7 @@ class MergeProcess(SpawnProcess):
                                        reporter = getattr(portage.elog.messages, funcname)
                                        reporter(msg, phase=phase, key=key, out=out)
 
-               if event & PollConstants.POLLHUP:
+               if event & self.scheduler.IO_HUP:
                        self.scheduler.unregister(self._elog_reg_id)
                        self._elog_reg_id = None
                        os.close(self._elog_reader_fd)