Moved some of the ssh arguments code out of CruSSH. Made the program a bit more pythonic in case people want to import CruSSH into another program.
This commit is contained in:
parent
c0f5af19d0
commit
f19d1f50ec
48
crussh.py
48
crussh.py
@ -7,8 +7,6 @@
|
||||
# Requires: python-gtk2 python-vte
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
import getpass
|
||||
import math
|
||||
try:
|
||||
import gtk
|
||||
@ -22,17 +20,6 @@ except:
|
||||
error.run()
|
||||
sys.exit(1)
|
||||
|
||||
### 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)
|
||||
|
||||
### CruSSH! ###
|
||||
class CruSSH:
|
||||
### Config Vars ###
|
||||
@ -136,13 +123,7 @@ class CruSSH:
|
||||
# give EntryBox default focus on init
|
||||
self.EntryBox.props.has_focus = True
|
||||
|
||||
def __init__(self, hosts):
|
||||
ssh_args = None
|
||||
if "--" in hosts:
|
||||
offset = hosts.index("--") + 1
|
||||
ssh_args = " ".join(hosts[0:offset])
|
||||
hosts = hosts[offset:]
|
||||
|
||||
def __init__(self, hosts, ssh_args=None):
|
||||
# init all terminals
|
||||
for host in hosts:
|
||||
terminal = vte.Terminal()
|
||||
@ -166,6 +147,27 @@ class CruSSH:
|
||||
self.initGUI()
|
||||
self.reflow(force=True)
|
||||
|
||||
### Start Execution ###
|
||||
crussh = CruSSH(hosts)
|
||||
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