From c095a3b5d34f410757b893e735a7ffa83653a8e5 Mon Sep 17 00:00:00 2001 From: Seblu Date: Fri, 7 Jan 2011 14:26:52 +0100 Subject: [PATCH] printer getpass no longer use module getpass new function to get term size --- cccli/printer.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/cccli/printer.py b/cccli/printer.py index 4edd905..c13ec49 100644 --- a/cccli/printer.py +++ b/cccli/printer.py @@ -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''' -- GitLab