Loading cccli/printer.py +22 −2 Original line number Diff line number Diff line Loading @@ -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 * Loading Loading @@ -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''' Loading @@ -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''' Loading Loading
cccli/printer.py +22 −2 Original line number Diff line number Diff line Loading @@ -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 * Loading Loading @@ -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''' Loading @@ -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''' Loading