def start(self, sockets=None, **kwargs): """ Present the PTY of the container inside the current process. This will take over the current process' TTY until the container's PTY is closed. """ pty_stdin, pty_stdout, pty_stderr = sockets or self.sockets() pumps = [] if pty_stdin and self.interactive: pumps.append( io.Pump(io.Stream(self.stdin), pty_stdin, wait_for_output=False)) if pty_stdout: pumps.append( io.Pump(pty_stdout, io.Stream(self.stdout), propagate_close=False)) if pty_stderr: pumps.append( io.Pump(pty_stderr, io.Stream(self.stderr), propagate_close=False)) if not self._container_info()['State']['Running']: self.client.start(self.container, **kwargs) return pumps
def start(self, sockets=None, **kwargs): """ Present the PTY of the container inside the current process. This will take over the current process' TTY until the container's PTY is closed. """ pty_stdin, pty_stdout, pty_stderr = sockets or self.sockets() pumps = [] if pty_stdin and self.interactive: # if stdin isn't a TTY then this is probably an SSH session # so wait for the EOF to happen before considering the Pump closed. pumps.append( io.Pump(io.Stream(self.stdin), pty_stdin, wait_for_output=not sys.stdin.isatty())) if pty_stdout: pumps.append( io.Pump(pty_stdout, io.Stream(self.stdout), propagate_close=False)) if pty_stderr: pumps.append( io.Pump(pty_stderr, io.Stream(self.stderr), propagate_close=False)) if not self._container_info()['State']['Running']: self.client.start(self.container, **kwargs) return pumps
def start(self, **kwargs): """ Present the PTY of the container inside the current process. This will take over the current process' TTY until the container's PTY is closed. """ pty_stdin, pty_stdout, pty_stderr = self.sockets() mappings = [ (pty_stdout, io.Stream(sys.stdout)), (pty_stderr, io.Stream(sys.stderr)), ] if self.interactive: mappings.insert(0, (io.Stream(sys.stdin), pty_stdin)) pumps = [io.Pump(a, b) for (a, b) in mappings if a and b] if not self.container_info()['State']['Running']: self.client.start(self.container, **kwargs) flags = [p.set_blocking(False) for p in pumps] try: with WINCHHandler(self): self._hijack_tty(pumps) finally: if flags: for (pump, flag) in zip(pumps, flags): io.set_blocking(pump, flag)
def start(self, sockets=None, **kwargs): """ start execution """ stream = sockets or self.sockets() pumps = [] if self.interactive: pumps.append(io.Pump(io.Stream(self.stdin), stream, wait_for_output=False)) pumps.append(io.Pump(stream, io.Stream(self.stdout), propagate_close=False)) # FIXME: since exec_start returns a single socket, how do we # distinguish between stdout and stderr? # pumps.append(io.Pump(stream, io.Stream(self.stderr), propagate_close=False)) return pumps
def test_flush_pipes_data_between_streams(self): a = StringIO(u'food') b = StringIO() pump = io.Pump(a, b) pump.flush(3) expect(a.read(1)).to(equal('d')) expect(b.getvalue()).to(equal('foo'))
def test_is_done_when_pump_does_require_output_to_finish(self): a = StringIO(u'123') b = StringIO() pump = io.Pump(a, b, True) expect(pump.is_done()).to(be_false) pump.flush() expect(pump.is_done()).to(be_false) pump.flush() expect(pump.is_done()).to(be_true)
def start(self, **kwargs): """ Present the PTY of the container inside the current process. This will take over the current process' TTY until the container's PTY is closed. """ pty_stdin, pty_stdout, pty_stderr = self.sockets() pumps = [] if pty_stdin and self.interactive: pumps.append( io.Pump(io.Stream(self.stdin), pty_stdin, wait_for_output=False)) if pty_stdout: pumps.append( io.Pump(pty_stdout, io.Stream(self.stdout), propagate_close=False)) if pty_stderr: pumps.append( io.Pump(pty_stderr, io.Stream(self.stderr), propagate_close=False)) if not self.container_info()['State']['Running']: self.client.start(self.container, **kwargs) flags = [p.set_blocking(False) for p in pumps] try: with WINCHHandler(self): self._hijack_tty(pumps) finally: if flags: for (pump, flag) in zip(pumps, flags): io.set_blocking(pump, flag)
def test_repr(self): a = StringIO(u'fo') b = StringIO() pump = io.Pump(a, b) expect(repr(pump)).to(equal("Pump(from=%s, to=%s)" % (a, b)))
def test_flush_returns_length_written(self): a = StringIO(u'fo') b = StringIO() pump = io.Pump(a, b) expect(pump.flush(3)).to(equal(2))
def test_fileno_delegates_to_from_stream(self): pump = io.Pump(sys.stdout, sys.stderr) expect(pump.fileno()).to(equal(sys.stdout.fileno()))
def test_is_done_when_pump_does_not_require_output_to_finish(self): a = StringIO() b = StringIO() pump = io.Pump(a, b, False) expect(pump.is_done()).to(be_true)