當前位置: 首頁>>代碼示例>>Python>>正文


Python tty.TIOCGWINSZ屬性代碼示例

本文整理匯總了Python中tty.TIOCGWINSZ屬性的典型用法代碼示例。如果您正苦於以下問題:Python tty.TIOCGWINSZ屬性的具體用法?Python tty.TIOCGWINSZ怎麽用?Python tty.TIOCGWINSZ使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在tty的用法示例。


在下文中一共展示了tty.TIOCGWINSZ屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setKnownConsoleSize

# 需要導入模塊: import tty [as 別名]
# 或者: from tty import TIOCGWINSZ [as 別名]
def setKnownConsoleSize(self, width, height):
        """
        For the duration of this test, patch C{cftp}'s C{fcntl} module to return
        a fixed width and height.

        @param width: the width in characters
        @type width: L{int}
        @param height: the height in characters
        @type height: L{int}
        """
        # Local import to avoid win32 issues.
        import tty
        class FakeFcntl(object):
            def ioctl(self, fd, opt, mutate):
                if opt != tty.TIOCGWINSZ:
                    self.fail("Only window-size queries supported.")
                return struct.pack("4H", height, width, 0, 0)
        self.patch(cftp, "fcntl", FakeFcntl()) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:20,代碼來源:test_cftp.py

示例2: _printProgessBar

# 需要導入模塊: import tty [as 別名]
# 或者: from tty import TIOCGWINSZ [as 別名]
def _printProgessBar(self, f, startTime):
        diff = time.time() - startTime
        total = f.total
        try:
            winSize = struct.unpack('4H', 
                fcntl.ioctl(0, tty.TIOCGWINSZ, '12345679'))
        except IOError:
            winSize = [None, 80]
        speed = total/diff
        if speed:
            timeLeft = (f.size - total) / speed
        else:
            timeLeft = 0
        front = f.name
        back = '%3i%% %s %sps %s ' % ((total/f.size)*100, self._abbrevSize(total),
                self._abbrevSize(total/diff), self._abbrevTime(timeLeft))
        spaces = (winSize[1] - (len(front) + len(back) + 1)) * ' '
        self.transport.write('\r%s%s%s' % (front, spaces, back)) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:20,代碼來源:cftp.py

示例3: _printProgressBar

# 需要導入模塊: import tty [as 別名]
# 或者: from tty import TIOCGWINSZ [as 別名]
def _printProgressBar(self, f, startTime):
        """
        Update a console progress bar on this L{StdioClient}'s transport, based
        on the difference between the start time of the operation and the
        current time according to the reactor, and appropriate to the size of
        the console window.

        @param f: a wrapper around the file which is being written or read
        @type f: L{FileWrapper}

        @param startTime: The time at which the operation being tracked began.
        @type startTime: L{float}
        """
        diff = self.reactor.seconds() - startTime
        total = f.total
        try:
            winSize = struct.unpack('4H',
                fcntl.ioctl(0, tty.TIOCGWINSZ, '12345679'))
        except IOError:
            winSize = [None, 80]
        if diff == 0.0:
            speed = 0.0
        else:
            speed = total / diff
        if speed:
            timeLeft = (f.size - total) / speed
        else:
            timeLeft = 0
        front = f.name
        if f.size:
            percentage = (total / f.size) * 100
        else:
            percentage = 100
        back = '%3i%% %s %sps %s ' % (percentage,
                                      self._abbrevSize(total),
                                      self._abbrevSize(speed),
                                      self._abbrevTime(timeLeft))
        spaces = (winSize[1] - (len(front) + len(back) + 1)) * ' '
        command = '\r%s%s%s' % (front, spaces, back)
        self._writeToTransport(command) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:42,代碼來源:cftp.py

示例4: channelOpen

# 需要導入模塊: import tty [as 別名]
# 或者: from tty import TIOCGWINSZ [as 別名]
def channelOpen(self, foo):
        log.msg('session %s open' % self.id)
        if options['agent']:
            d = self.conn.sendRequest(self, b'auth-agent-req@openssh.com', b'', wantReply=1)
            d.addBoth(lambda x:log.msg(x))
        if options['noshell']: return
        if (options['command'] and options['tty']) or not options['notty']:
            _enterRawMode()
        c = session.SSHSessionClient()
        if options['escape'] and not options['notty']:
            self.escapeMode = 1
            c.dataReceived = self.handleInput
        else:
            c.dataReceived = self.write
        c.connectionLost = lambda x=None,s=self:s.sendEOF()
        self.stdio = stdio.StandardIO(c)
        fd = 0
        if options['subsystem']:
            self.conn.sendRequest(self, b'subsystem', \
                common.NS(options['command']))
        elif options['command']:
            if options['tty']:
                term = os.environ['TERM']
                winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678')
                winSize = struct.unpack('4H', winsz)
                ptyReqData = session.packRequest_pty_req(term, winSize, '')
                self.conn.sendRequest(self, b'pty-req', ptyReqData)
                signal.signal(signal.SIGWINCH, self._windowResized)
            self.conn.sendRequest(self, b'exec', \
                common.NS(options['command']))
        else:
            if not options['notty']:
                term = os.environ['TERM']
                winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678')
                winSize = struct.unpack('4H', winsz)
                ptyReqData = session.packRequest_pty_req(term, winSize, '')
                self.conn.sendRequest(self, b'pty-req', ptyReqData)
                signal.signal(signal.SIGWINCH, self._windowResized)
            self.conn.sendRequest(self, b'shell', b'')
            #if hasattr(conn.transport, 'transport'):
            #    conn.transport.transport.setTcpNoDelay(1) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:43,代碼來源:conch.py

示例5: _windowResized

# 需要導入模塊: import tty [as 別名]
# 或者: from tty import TIOCGWINSZ [as 別名]
def _windowResized(self, *args):
        winsz = fcntl.ioctl(0, tty.TIOCGWINSZ, '12345678')
        winSize = struct.unpack('4H', winsz)
        newSize = winSize[1], winSize[0], winSize[2], winSize[3]
        self.conn.sendRequest(self, b'window-change', struct.pack('!4L', *newSize)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:7,代碼來源:conch.py

示例6: _printProgressBar

# 需要導入模塊: import tty [as 別名]
# 或者: from tty import TIOCGWINSZ [as 別名]
def _printProgressBar(self, f, startTime):
        """
        Update a console progress bar on this L{StdioClient}'s transport, based
        on the difference between the start time of the operation and the
        current time according to the reactor, and appropriate to the size of
        the console window.

        @param f: a wrapper around the file which is being written or read
        @type f: L{FileWrapper}

        @param startTime: The time at which the operation being tracked began.
        @type startTime: C{float}
        """
        diff = self.reactor.seconds() - startTime
        total = f.total
        try:
            winSize = struct.unpack('4H',
                fcntl.ioctl(0, tty.TIOCGWINSZ, '12345679'))
        except IOError:
            winSize = [None, 80]
        if diff == 0.0:
            speed = 0.0
        else:
            speed = total / diff
        if speed:
            timeLeft = (f.size - total) / speed
        else:
            timeLeft = 0
        front = f.name
        back = '%3i%% %s %sps %s ' % ((total / f.size) * 100,
                                      self._abbrevSize(total),
                                      self._abbrevSize(speed),
                                      self._abbrevTime(timeLeft))
        spaces = (winSize[1] - (len(front) + len(back) + 1)) * ' '
        self.transport.write('\r%s%s%s' % (front, spaces, back)) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:37,代碼來源:cftp.py

示例7: channelOpen

# 需要導入模塊: import tty [as 別名]
# 或者: from tty import TIOCGWINSZ [as 別名]
def channelOpen(self, foo):
        log.msg('session %s open' % self.id)
        if options['agent']:
            d = self.conn.sendRequest(self, 'auth-agent-req@openssh.com', '', wantReply=1)
            d.addBoth(lambda x:log.msg(x))
        if options['noshell']: return
        if (options['command'] and options['tty']) or not options['notty']:
            _enterRawMode()
        c = session.SSHSessionClient()
        if options['escape'] and not options['notty']:
            self.escapeMode = 1
            c.dataReceived = self.handleInput
        else:
            c.dataReceived = self.write
        c.connectionLost = lambda x=None,s=self:s.sendEOF()
        self.stdio = stdio.StandardIO(c)
        fd = 0
        if options['subsystem']:
            self.conn.sendRequest(self, 'subsystem', \
                common.NS(options['command']))
        elif options['command']:
            if options['tty']:
                term = os.environ['TERM']
                winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678')
                winSize = struct.unpack('4H', winsz)
                ptyReqData = session.packRequest_pty_req(term, winSize, '')
                self.conn.sendRequest(self, 'pty-req', ptyReqData)
                signal.signal(signal.SIGWINCH, self._windowResized)
            self.conn.sendRequest(self, 'exec', \
                common.NS(options['command']))
        else:
            if not options['notty']:
                term = os.environ['TERM']
                winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678')
                winSize = struct.unpack('4H', winsz)
                ptyReqData = session.packRequest_pty_req(term, winSize, '')
                self.conn.sendRequest(self, 'pty-req', ptyReqData)
                signal.signal(signal.SIGWINCH, self._windowResized)
            self.conn.sendRequest(self, 'shell', '')
            #if hasattr(conn.transport, 'transport'):
            #    conn.transport.transport.setTcpNoDelay(1) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:43,代碼來源:conch.py

示例8: _windowResized

# 需要導入模塊: import tty [as 別名]
# 或者: from tty import TIOCGWINSZ [as 別名]
def _windowResized(self, *args):
        winsz = fcntl.ioctl(0, tty.TIOCGWINSZ, '12345678')
        winSize = struct.unpack('4H', winsz)
        newSize = winSize[1], winSize[0], winSize[2], winSize[3]
        self.conn.sendRequest(self, 'window-change', struct.pack('!4L', *newSize)) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:7,代碼來源:conch.py

示例9: getTerminalSize

# 需要導入模塊: import tty [as 別名]
# 或者: from tty import TIOCGWINSZ [as 別名]
def getTerminalSize(terminalFD):
    """
    Get the height and width of the terminal, in characters.

    @param terminalFD: The file descriptor of the terminal to inspect.
    @type terminalFD: L{int}
    """
    winsz = fcntl.ioctl(terminalFD, tty.TIOCGWINSZ, b'12345678')
    winSize = struct.unpack(
        b'4H', winsz
    )
    ws_row, ws_col, ws_xpixel, ws_ypixel = winSize
    return ws_row, ws_col 
開發者ID:twisted,項目名稱:imaginary,代碼行數:15,代碼來源:__main__.py

示例10: channelOpen

# 需要導入模塊: import tty [as 別名]
# 或者: from tty import TIOCGWINSZ [as 別名]
def channelOpen(self, foo):
        log.msg('session {} open'.format(self.id))
        if options['agent']:
            d = self.conn.sendRequest(self, b'auth-agent-req@openssh.com',
                                      b'', wantReply=1)
            d.addBoth(lambda x: log.msg(x))
        if options['noshell']:
            return
        if (options['command'] and options['tty']) or not options['notty']:
            _enterRawMode()
        c = session.SSHSessionClient()
        if options['escape'] and not options['notty']:
            self.escapeMode = 1
            c.dataReceived = self.handleInput
        else:
            c.dataReceived = self.write
        c.connectionLost = lambda x: self.sendEOF()
        self.stdio = stdio.StandardIO(c)
        fd = 0
        if options['subsystem']:
            self.conn.sendRequest(self, b'subsystem',
                                  common.NS(options['command']))
        elif options['command']:
            if options['tty']:
                term = os.environ['TERM']
                winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678')
                winSize = struct.unpack('4H', winsz)
                ptyReqData = session.packRequest_pty_req(term, winSize, '')
                self.conn.sendRequest(self, b'pty-req', ptyReqData)
                signal.signal(signal.SIGWINCH, self._windowResized)
            self.conn.sendRequest(self, b'exec', common.NS(options['command']))
        else:
            if not options['notty']:
                term = os.environ['TERM']
                winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678')
                winSize = struct.unpack('4H', winsz)
                ptyReqData = session.packRequest_pty_req(term, winSize, '')
                self.conn.sendRequest(self, b'pty-req', ptyReqData)
                signal.signal(signal.SIGWINCH, self._windowResized)
            self.conn.sendRequest(self, b'shell', b'')
            #if hasattr(conn.transport, 'transport'):
            #    conn.transport.transport.setTcpNoDelay(1) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:44,代碼來源:conch.py


注:本文中的tty.TIOCGWINSZ屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。