From fde90035af43e90e8b35378d7222d6a3a2bb6059 Mon Sep 17 00:00:00 2001 From: Jeff Fisher Date: Wed, 21 Mar 2012 14:09:46 -0600 Subject: [PATCH] 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()