Merged cli args changes from master.
This commit is contained in:
commit
8945722173
51
crussh.py
51
crussh.py
@ -7,7 +7,6 @@
|
||||
# Requires: python-gtk2 python-vte
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
import math
|
||||
import json
|
||||
try:
|
||||
@ -22,19 +21,6 @@ except:
|
||||
error.run()
|
||||
sys.exit(1)
|
||||
|
||||
### 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.add_argument('-l', '--login', dest='login', default=None,
|
||||
help="Login name to use.")
|
||||
parser.add_argument('-p', '--port', dest='port', type=int, default=None,
|
||||
help="Alternate SSH port to use.")
|
||||
parser.add_argument('-s', '--fontsize', dest='fontsize', type=int, default=10,
|
||||
help="Font size to use. (default=10)")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
### Config Dialog ###
|
||||
class CruSSHConf:
|
||||
### State Vars ###
|
||||
@ -244,23 +230,21 @@ class CruSSH:
|
||||
# give EntryBox default focus on init
|
||||
self.EntryBox.props.has_focus = True
|
||||
|
||||
def __init__(self, hosts, login=None, port=None):
|
||||
def __init__(self, hosts, ssh_args=None):
|
||||
# load existing config file, if present
|
||||
try:
|
||||
Config = json.load(open('~/.crusshrc'))
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
|
||||
# init all terminals
|
||||
for host in hosts:
|
||||
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 self.Config["login"] != None:
|
||||
cmd_str += " -l " + args.login
|
||||
if self.Config["port"] != None:
|
||||
cmd_str += " -p " + str(args.port)
|
||||
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)
|
||||
@ -274,6 +258,27 @@ class CruSSH:
|
||||
self.initGUI()
|
||||
self.reflow(force=True)
|
||||
|
||||
### Start Execution ###
|
||||
crussh = CruSSH(args.hosts, args.login, args.port)
|
||||
gtk.main()
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
|
||||
### Parse CLI Args ###
|
||||
parser = argparse.ArgumentParser(description="Connect to multiple servers in parallel.", usage="%(prog)s [OPTIONS] HOST [HOST ...]")
|
||||
parser.add_argument('-s', '--fontsize', dest='fontsize', type=int, default=10,
|
||||
help="Font size to use. (default=10)")
|
||||
|
||||
(args, hosts) = parser.parse_known_args()
|
||||
|
||||
if len(hosts) == 0:
|
||||
parser.print_usage()
|
||||
sys.exit(1)
|
||||
|
||||
if "--" in hosts:
|
||||
offset = hosts.index("--") + 1
|
||||
ssh_args = " ".join(hosts[0:offset])
|
||||
hosts = hosts[offset:]
|
||||
else:
|
||||
ssh_args = None
|
||||
|
||||
### Start Execution ###
|
||||
crussh = CruSSH(hosts, ssh_args)
|
||||
gtk.main()
|
||||
|
Loading…
Reference in New Issue
Block a user