예제 #1
0
    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
예제 #2
0
파일: pty.py 프로젝트: willnx/dockerpty
    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
예제 #3
0
    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)
예제 #4
0
파일: pty.py 프로젝트: simble1986/dockerpty
    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
예제 #5
0
파일: test_io.py 프로젝트: rmohr/dockerpty
 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'))
예제 #6
0
    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)
예제 #7
0
파일: pty.py 프로젝트: rafalozan0/sama
    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)
예제 #8
0
파일: test_io.py 프로젝트: rmohr/dockerpty
 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)))
예제 #9
0
파일: test_io.py 프로젝트: rmohr/dockerpty
 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))
예제 #10
0
파일: test_io.py 프로젝트: rmohr/dockerpty
 def test_fileno_delegates_to_from_stream(self):
     pump = io.Pump(sys.stdout, sys.stderr)
     expect(pump.fileno()).to(equal(sys.stdout.fileno()))
예제 #11
0
 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)