Commit c095a3b5 authored by Seblu's avatar Seblu
Browse files

printer getpass no longer use module getpass

new function to get term size
parent e513b4db
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -7,7 +7,9 @@ CloudControl CLI Printer module

import sys
import os
import getpass
import termios
import fcntl
import struct

import cccli
from cccli.exception import *
@@ -118,7 +120,16 @@ class Printer(object):
        '''Ask for a password. No echo. Not in history'''
        if self.readline is None:
            raise cliError("Unable to ask a password in non-interactive mode")
        return getpass.getpass(prompt)
        fd = sys.stdin.fileno()
        old = termios.tcgetattr(fd)
        new = termios.tcgetattr(fd)
        new[3] = new[3] & ~termios.ECHO
        try:
            termios.tcsetattr(fd, termios.TCSADRAIN, new)
            passwd = raw_input(prompt)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old)
        return passwd

    def ask(self, prompt):
        '''Used to ask a question. Default answer not saved to history'''
@@ -132,6 +143,15 @@ class Printer(object):
            self.history.load(h)
        return r

    def get_term_size(self):
        '''Return terminal size'''
        if self.readline is None:
            raise cliError("Unable to get term size in non-interactive mode")
        req = struct.pack("HHHH", 0, 0, 0, 0)
        resp = fcntl.ioctl(sys.stdin.fileno(), termios.TIOCGWINSZ, req)
        rows, cols, px_x, px_y = struct.unpack("HHHH", resp)
        return rows, cols


class History(object):
    '''History class'''