From f0b74c5b1f7465c96b392c01dee97fcf8b3a1cc9 Mon Sep 17 00:00:00 2001 From: Jeff Fisher Date: Wed, 21 Mar 2012 14:09:13 -0600 Subject: [PATCH 1/3] minor doc update since HOST is used in the help output --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b679f61..c0b0382 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Install The install process is very simple on most distros: - Install python2, python-gtk2, and python-vte. -- Run ./crussh.py hostname [hostname ...] +- Run ./crussh.py HOST [HOST ...] Bugs & TODO ----------- From fde90035af43e90e8b35378d7222d6a3a2bb6059 Mon Sep 17 00:00:00 2001 From: Jeff Fisher Date: Wed, 21 Mar 2012 14:09:46 -0600 Subject: [PATCH 2/3] Removed the ssh argument code that uses --. Added --ssh which can be used to change the ssh executable and pass arugments, it also lets you do things like: ./crussh --ssh telnet "www.google.com 80" "www.bing.com 80" --- crussh.py | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/crussh.py b/crussh.py index 00a1d40..7245e22 100755 --- a/crussh.py +++ b/crussh.py @@ -265,7 +265,7 @@ class CruSSH: # give EntryBox default focus on init self.EntryBox.props.has_focus = True - def __init__(self, hosts, ssh_args=None): + def __init__(self, hosts, ssh_cmd="/usr/bin/ssh"): # load existing config file, if present try: # merge dicts to allow upgrade from old configs @@ -279,10 +279,7 @@ class CruSSH: terminal = vte.Terminal() # TODO: disable only this terminal widget on child exit # v.connect("child-exited", lambda term: gtk.main_quit()) - cmd_str = "/usr/bin/ssh" - if ssh_args is not None: - cmd_str += " " + ssh_args - cmd_str += " " + host + cmd_str = "%s %s" % (ssh_cmd, host) cmd = cmd_str.split(' ') terminal.fork_command(command=cmd[0], argv=cmd) self.Terminals[host] = terminal @@ -299,23 +296,13 @@ if __name__ == "__main__": import argparse ### Parse CLI Args ### - parser = argparse.ArgumentParser( - description="Connect to multiple servers in parallel.", - usage="%(prog)s [OPTIONS] [--] HOST [HOST ...]", - epilog="* NOTE: You can pass options to ssh if you add '--' before your list of hosts") - (args, hosts) = parser.parse_known_args() - - if len(hosts) == 0: - parser.print_usage() - parser.exit(2) - - if "--" in hosts: - offset = hosts.index("--") + 1 - ssh_args = " ".join(hosts[0:offset]) - hosts = hosts[offset:] - else: - ssh_args = None + parser = argparse.ArgumentParser(description="Connect to multiple servers in parallel.") + parser.add_argument('hosts', metavar='HOST', nargs='+', + help="Host(s) to connect to.") + parser.add_argument("--ssh", dest='ssh', default="/usr/bin/ssh", + help="SSH executable and optional arguments (ex: --ssh 'ssh -l root')") + args = parser.parse_args() ### Start Execution ### - crussh = CruSSH(hosts, ssh_args) + crussh = CruSSH(args.hosts, args.ssh) gtk.main() From 7dd4980ace68ae91b7374071473a5eaf990ae84d Mon Sep 17 00:00:00 2001 From: Jeff Fisher Date: Wed, 21 Mar 2012 14:34:33 -0600 Subject: [PATCH 3/3] unit3 likes the idea of both methods so I've added back in the old way with a minor code change --- crussh.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/crussh.py b/crussh.py index 7245e22..d2531d5 100755 --- a/crussh.py +++ b/crussh.py @@ -265,7 +265,7 @@ class CruSSH: # give EntryBox default focus on init self.EntryBox.props.has_focus = True - def __init__(self, hosts, ssh_cmd="/usr/bin/ssh"): + def __init__(self, hosts, ssh_cmd="/usr/bin/ssh", ssh_args=None): # load existing config file, if present try: # merge dicts to allow upgrade from old configs @@ -279,7 +279,10 @@ class CruSSH: terminal = vte.Terminal() # TODO: disable only this terminal widget on child exit # v.connect("child-exited", lambda term: gtk.main_quit()) - cmd_str = "%s %s" % (ssh_cmd, host) + cmd_str = ssh_cmd + if ssh_args is not None: + cmd_str += " " + ssh_args + cmd_str += " " + host cmd = cmd_str.split(' ') terminal.fork_command(command=cmd[0], argv=cmd) self.Terminals[host] = terminal @@ -296,13 +299,26 @@ if __name__ == "__main__": import argparse ### Parse CLI Args ### - parser = argparse.ArgumentParser(description="Connect to multiple servers in parallel.") - parser.add_argument('hosts', metavar='HOST', nargs='+', - help="Host(s) to connect to.") + parser = argparse.ArgumentParser( + description="Connect to multiple hosts in parallel.", + usage="%(prog)s [OPTIONS] [--] HOST [HOST ...]", + epilog="* NOTE: You can pass options to ssh if you add '--' before your list of hosts") parser.add_argument("--ssh", dest='ssh', default="/usr/bin/ssh", - help="SSH executable and optional arguments (ex: --ssh 'ssh -l root')") - args = parser.parse_args() + help="specify the SSH executable to use (default: %(default)s)") + (args, hosts) = parser.parse_known_args() + + if len(hosts) == 0: + parser.print_usage() + parser.exit(2) + + try: + offset = hosts.index("--") + except: + ssh_args = None + else: + ssh_args = " ".join(hosts[0:offset]) + hosts = hosts[offset + 1:] ### Start Execution ### - crussh = CruSSH(args.hosts, args.ssh) + crussh = CruSSH(hosts, args.ssh, ssh_args) gtk.main()