aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'portage_with_autodep/pym/_emerge/PipeReader.py')
-rw-r--r--portage_with_autodep/pym/_emerge/PipeReader.py60
1 files changed, 38 insertions, 22 deletions
diff --git a/portage_with_autodep/pym/_emerge/PipeReader.py b/portage_with_autodep/pym/_emerge/PipeReader.py
index 375c98f..90febdf 100644
--- a/portage_with_autodep/pym/_emerge/PipeReader.py
+++ b/portage_with_autodep/pym/_emerge/PipeReader.py
@@ -1,11 +1,9 @@
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
from portage import os
from _emerge.AbstractPollTask import AbstractPollTask
-from _emerge.PollConstants import PollConstants
import fcntl
-import array
class PipeReader(AbstractPollTask):
@@ -17,16 +15,22 @@ class PipeReader(AbstractPollTask):
"""
__slots__ = ("input_files",) + \
- ("_read_data", "_reg_ids")
+ ("_read_data", "_reg_ids", "_use_array")
def _start(self):
self._reg_ids = set()
self._read_data = []
- for k, f in self.input_files.items():
+
+ if self._use_array:
+ output_handler = self._array_output_handler
+ else:
+ output_handler = self._output_handler
+
+ for f in self.input_files.values():
fcntl.fcntl(f.fileno(), fcntl.F_SETFL,
fcntl.fcntl(f.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK)
self._reg_ids.add(self.scheduler.register(f.fileno(),
- self._registered_events, self._output_handler))
+ self._registered_events, output_handler))
self._registered = True
def isAlive(self):
@@ -39,11 +43,7 @@ class PipeReader(AbstractPollTask):
def _wait(self):
if self.returncode is not None:
return self.returncode
-
- if self._registered:
- self.scheduler.schedule(self._reg_ids)
- self._unregister()
-
+ self._wait_loop()
self.returncode = os.EX_OK
return self.returncode
@@ -57,26 +57,42 @@ class PipeReader(AbstractPollTask):
def _output_handler(self, fd, event):
- if event & PollConstants.POLLIN:
+ while True:
+ data = self._read_buf(fd, event)
+ if data is None:
+ break
+ if data:
+ self._read_data.append(data)
+ else:
+ self._unregister()
+ self.wait()
+ break
+
+ self._unregister_if_appropriate(event)
+
+ return True
- for f in self.input_files.values():
- if fd == f.fileno():
- break
+ def _array_output_handler(self, fd, event):
- buf = array.array('B')
- try:
- buf.fromfile(f, self._bufsize)
- except (EOFError, IOError):
- pass
+ for f in self.input_files.values():
+ if f.fileno() == fd:
+ break
- if buf:
- self._read_data.append(buf.tostring())
+ while True:
+ data = self._read_array(f, event)
+ if data is None:
+ break
+ if data:
+ self._read_data.append(data)
else:
self._unregister()
self.wait()
+ break
self._unregister_if_appropriate(event)
+ return True
+
def _unregister(self):
"""
Unregister from the scheduler and close open files.