From eb1f340da30ea143b057894171a7e122f0ad3b00 Mon Sep 17 00:00:00 2001 From: Guillaume Chazarain Date: Mon, 19 May 2008 00:28:18 +0200 Subject: [PATCH] Added the :print_read_buffer control command to see what gsh just read --- NEWS | 1 + gsh.1 | 4 +++- gsh/control_commands.py | 19 +++++++++++++++++++ gsh/remote_dispatcher.py | 7 +++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index fc1bb1d..ef51ddc 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ o Added the :hide_password control command, to use with su(1) for example o Added the :reset_prompt control command, for use when launching a shell o Added the :replicate control command to do some file transfer between shells o Added the :export_rank control command to uniquely identify each shell +o Added the :print_read_buffer control command to see what gsh just read o Common SSH key problems are detected and some help is printed o New completion from the local filesystem diff --git a/gsh.1 b/gsh.1 index b3167d7..050818e 100644 --- a/gsh.1 +++ b/gsh.1 @@ -42,7 +42,6 @@ Abort if some shell fails to initialize [ignore]. By default, \fIgsh\fR just log Print debugging information. Use this option to see exactly what is transferred between \fIgsh\fR and the remote shells. This option can be dynamically toggled using the set_debug command in the control shell. .SH "CONTROL COMMANDS" Control commands are special purpose commands prefixed by a colon and directed at \fIgsh\fR itself instead of the remote shells. These commands are: - \" BEGIN AUTO-GENERATED CONTROL COMMANDS DOCUMENTATION .TP \fB:add NAMES...\fR @@ -72,6 +71,9 @@ List remote shells and their states. The special characters * ? and [] work as e \fB:log_output [PATH]\fR Duplicate every console output into the given local file. If PATH is not given, restore the default behaviour of not logging the output. .TP +\fB:print_read_buffer [SHELLS...]\fR +Print the data read by remote shells. The special characters * ? and [] work as expected. +.TP \fB:purge [SHELLS...]\fR Delete disabled remote shells. This helps to have a shorter list. The special characters * ? and [] work as expected. .TP diff --git a/gsh/control_commands.py b/gsh/control_commands.py index 014f180..cce082d 100644 --- a/gsh/control_commands.py +++ b/gsh/control_commands.py @@ -342,6 +342,25 @@ def do_log_output(command): remote_dispatcher.options.log_file = None console_output('Logging disabled\n') +def complete_print_read_buffer(line, text): + return complete_shells(line, text, lambda i: i.read_buffer or + i.read_in_state_not_started) + +def do_print_read_buffer(command): + """ + Usage: :print_read_buffer [SHELLS...] + Print the data read by remote shells. + The special characters * ? and [] work as expected. + """ + for i in selected_shells(command): + if i.read_buffer: + i.print_lines(i.read_buffer) + i.read_buffer = '' + + if i.read_in_state_not_started: + i.print_lines(i.read_in_state_not_started) + i.read_in_state_not_started = '' + def main(): """ Output a help text of each control command suitable for the man page diff --git a/gsh/remote_dispatcher.py b/gsh/remote_dispatcher.py index c882532..acb765f 100644 --- a/gsh/remote_dispatcher.py +++ b/gsh/remote_dispatcher.py @@ -72,6 +72,7 @@ class remote_dispatcher(buffered_dispatcher): self.change_name(hostname) self.init_string = self.configure_tty() + self.set_prompt() self.init_string_sent = False + self.read_in_state_not_started = '' self.command = options.command def launch_ssh(self, name): @@ -98,6 +99,8 @@ class remote_dispatcher(buffered_dispatcher): if state is not self.state: if self.debug: self.print_debug('state => %s' % (STATE_NAMES[state])) + if self.state == STATE_NOT_STARTED: + self.read_in_state_not_started = '' self.state = state def disconnect(self): @@ -111,6 +114,9 @@ class remote_dispatcher(buffered_dispatcher): self.write_buffer = '' self.active = False self.set_enabled(False) + if self.read_in_state_not_started: + self.print_lines(self.read_in_state_not_started) + self.read_in_state_not_started = '' if options.abort_error and self.state is STATE_NOT_STARTED: raise asyncore.ExitNow(1) @@ -216,6 +222,7 @@ class remote_dispatcher(buffered_dispatcher): elif self.state in (STATE_IDLE, STATE_RUNNING): self.print_lines(line) elif self.state is STATE_NOT_STARTED: + self.read_in_state_not_started += line if 'The authenticity of host' in line: msg = line.strip('\n') + ' Closing connection.' self.disconnect() -- 2.11.4.GIT