def _paramiko_shell(self): rows, cols = get_terminal_size() try: self.shell = self.client.open_session() self.shell.get_pty(self.termtype, cols, rows) self.shell.invoke_shell() except SSHException, e: self._dbg(1, 'Failed to open shell.') raise LoginFailure('Failed to open shell: ' + str(e))
def _connect_hook(self, hostname, port): assert self.tn is None rows, cols = get_terminal_size() self.tn = telnetlib.Telnet(hostname, port or 23, termsize=(rows, cols), termtype=self.termtype, stderr=self.stderr, receive_callback=self._telnetlib_received) if self.debug >= 5: self.tn.set_debuglevel(1) if self.tn is None: return False return True
def _connect_hook(self, hostname, port): assert self.tn is None rows, cols = get_terminal_size() self.tn = telnetlib.Telnet(hostname, port or 23, termsize = (rows, cols), termtype = self.termtype, stderr = self.stderr, receive_callback = self._telnetlib_received) if self.debug >= 5: self.tn.set_debuglevel(1) if self.tn is None: return False return True
def testGetTerminalSize(self): from Exscript.util.tty import get_terminal_size # This hack really makes the test incomplete because # get_terminal_size() won't be able to check the cterm size, # but it is the only way to test at least partially. os.ctermid = lambda: '/nosuchfileexists' # By deleting PATH we prevent get_terminal_size() from asking # the stty unix program. oldpath = os.environ['PATH'] os.environ['PATH'] = '' # If the LINES and COLUMNS variables are not set, all methods should # now fail, and the default values are returned. os.environ['LINES'] = '' os.environ['COLUMNS'] = '' self.assertEqual(get_terminal_size(), (25, 80)) self.assertEqual(get_terminal_size(10, 10), (10, 10)) # If the LINES and COLUMNS variables are set, they should be used. os.environ['LINES'] = '1000' os.environ['COLUMNS'] = '1000' self.assertEqual(get_terminal_size(), (1000, 1000)) self.assertEqual(get_terminal_size(10, 10), (1000, 1000)) # If the stty program exists, it should be used. os.environ['PATH'] = oldpath try: self.assertNotEqual(get_terminal_size(), (1000, 1000)) self.assertNotEqual(get_terminal_size(10, 10), (1000, 1000)) except OSError: pass # "stty" not found. # Lastly, if stdin/stderr/stdout exist, they should tell us something. os.environ['PATH'] = '' self._unredirect() self.assertNotEqual(get_terminal_size(), (1000, 1000)) self.assertNotEqual(get_terminal_size(10, 10), (1000, 1000)) os.environ['PATH'] = oldpath
def _print_status_bar(self, exclude = None): if self.total == 0: return percent = 100.0 / self.total * self.completed progress = '%d/%d (%d%%)' % (self.completed, self.total, percent) jobs = self.workqueue.get_running_jobs() running = '|'.join([j.name for j in jobs if j.name != exclude]) if not running: self.status_bar_length = 0 return rows, cols = get_terminal_size() text = 'In progress: [%s] %s' % (running, progress) overflow = len(text) - cols if overflow > 0: cont = '...' overflow += len(cont) + 1 strlen = len(running) partlen = (strlen / 2) - (overflow / 2) head = running[:partlen] tail = running[-partlen:] running = head + cont + tail text = 'In progress: [%s] %s' % (running, progress) self._write('status_bar', text) self.status_bar_length = len(text)
def _print_status_bar(self, exclude=None): if self.total == 0: return percent = 100.0 / self.total * self.completed progress = "%d/%d (%d%%)" % (self.completed, self.total, percent) jobs = self.workqueue.get_running_jobs() running = "|".join([j.name for j in jobs if j.name != exclude]) if not running: self.status_bar_length = 0 return rows, cols = get_terminal_size() text = "In progress: [%s] %s" % (running, progress) overflow = len(text) - cols if overflow > 0: cont = "..." overflow += len(cont) + 1 strlen = len(running) partlen = (strlen / 2) - (overflow / 2) head = running[:partlen] tail = running[-partlen:] running = head + cont + tail text = "In progress: [%s] %s" % (running, progress) self._write("status_bar", text) self.status_bar_length = len(text)
def handle_sigwinch(signum, frame): rows, cols = get_terminal_size() self._set_terminal_size(rows, cols)