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
|
# Requires: python-gtk2 python-vte
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
|
||||||
import math
|
import math
|
||||||
import json
|
import json
|
||||||
try:
|
try:
|
||||||
@ -22,19 +21,6 @@ except:
|
|||||||
error.run()
|
error.run()
|
||||||
sys.exit(1)
|
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 ###
|
### Config Dialog ###
|
||||||
class CruSSHConf:
|
class CruSSHConf:
|
||||||
### State Vars ###
|
### State Vars ###
|
||||||
@ -244,23 +230,21 @@ class CruSSH:
|
|||||||
# give EntryBox default focus on init
|
# give EntryBox default focus on init
|
||||||
self.EntryBox.props.has_focus = True
|
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
|
# load existing config file, if present
|
||||||
try:
|
try:
|
||||||
Config = json.load(open('~/.crusshrc'))
|
Config = json.load(open('~/.crusshrc'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# init all terminals
|
# init all terminals
|
||||||
for host in hosts:
|
for host in hosts:
|
||||||
terminal = vte.Terminal()
|
terminal = vte.Terminal()
|
||||||
# TODO: disable only this terminal widget on child exit
|
# TODO: disable only this terminal widget on child exit
|
||||||
# v.connect("child-exited", lambda term: gtk.main_quit())
|
# v.connect("child-exited", lambda term: gtk.main_quit())
|
||||||
cmd_str = "/usr/bin/ssh"
|
cmd_str = "/usr/bin/ssh"
|
||||||
if self.Config["login"] != None:
|
if ssh_args is not None:
|
||||||
cmd_str += " -l " + args.login
|
cmd_str += " " + ssh_args
|
||||||
if self.Config["port"] != None:
|
|
||||||
cmd_str += " -p " + str(args.port)
|
|
||||||
cmd_str += " " + host
|
cmd_str += " " + host
|
||||||
cmd = cmd_str.split(' ')
|
cmd = cmd_str.split(' ')
|
||||||
terminal.fork_command(command=cmd[0], argv=cmd)
|
terminal.fork_command(command=cmd[0], argv=cmd)
|
||||||
@ -274,6 +258,27 @@ class CruSSH:
|
|||||||
self.initGUI()
|
self.initGUI()
|
||||||
self.reflow(force=True)
|
self.reflow(force=True)
|
||||||
|
|
||||||
### Start Execution ###
|
if __name__ == "__main__":
|
||||||
crussh = CruSSH(args.hosts, args.login, args.port)
|
import argparse
|
||||||
gtk.main()
|
|
||||||
|
### 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