From c85b1d7149f09e64b5ed4f5e45742b6e5a9df38b Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 9 Feb 2012 17:27:13 -0800 Subject: [PATCH] Use IO_* constants where appropriate. --- pym/_emerge/AbstractPollTask.py | 20 +++++++++++++------- pym/_emerge/AsynchronousLock.py | 9 ++++----- pym/_emerge/EbuildIpcDaemon.py | 5 ++--- pym/_emerge/EbuildMetadataPhase.py | 5 ++--- pym/_emerge/PollScheduler.py | 9 ++++++++- pym/_emerge/Scheduler.py | 6 ++++++ pym/portage/dbapi/_MergeProcess.py | 7 +++---- 7 files changed, 38 insertions(+), 23 deletions(-) diff --git a/pym/_emerge/AbstractPollTask.py b/pym/_emerge/AbstractPollTask.py index 922905291..68282efb5 100644 --- a/pym/_emerge/AbstractPollTask.py +++ b/pym/_emerge/AbstractPollTask.py @@ -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() diff --git a/pym/_emerge/AsynchronousLock.py b/pym/_emerge/AsynchronousLock.py index 3cf0acbd5..c07df0bdd 100644 --- a/pym/_emerge/AsynchronousLock.py +++ b/pym/_emerge/AsynchronousLock.py @@ -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: diff --git a/pym/_emerge/EbuildIpcDaemon.py b/pym/_emerge/EbuildIpcDaemon.py index 6a320cb07..5795bfbdc 100644 --- a/pym/_emerge/EbuildIpcDaemon.py +++ b/pym/_emerge/EbuildIpcDaemon.py @@ -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 diff --git a/pym/_emerge/EbuildMetadataPhase.py b/pym/_emerge/EbuildMetadataPhase.py index f8da8667f..a34542d43 100644 --- a/pym/_emerge/EbuildMetadataPhase.py +++ b/pym/_emerge/EbuildMetadataPhase.py @@ -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( diff --git a/pym/_emerge/PollScheduler.py b/pym/_emerge/PollScheduler.py index 3b86fa08e..eafb8a237 100644 --- a/pym/_emerge/PollScheduler.py +++ b/pym/_emerge/PollScheduler.py @@ -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, diff --git a/pym/_emerge/Scheduler.py b/pym/_emerge/Scheduler.py index 12f087119..674a11e49 100644 --- a/pym/_emerge/Scheduler.py +++ b/pym/_emerge/Scheduler.py @@ -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, diff --git a/pym/portage/dbapi/_MergeProcess.py b/pym/portage/dbapi/_MergeProcess.py index da278ea2a..9bb67c9b6 100644 --- a/pym/portage/dbapi/_MergeProcess.py +++ b/pym/portage/dbapi/_MergeProcess.py @@ -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) -- 2.26.2