finally fixed crussh up
This commit is contained in:
parent
a84fa83cf2
commit
07b0d31543
76
crussh.py
76
crussh.py
@ -12,21 +12,20 @@ from gi.repository import GLib as glib
|
|||||||
from gi.repository.Pango import FontDescription
|
from gi.repository.Pango import FontDescription
|
||||||
gi.require_version('Vte', '2.91')
|
gi.require_version('Vte', '2.91')
|
||||||
from gi.repository import Vte as vte
|
from gi.repository import Vte as vte
|
||||||
import sys
|
|
||||||
import math
|
import math
|
||||||
import json
|
import yaml
|
||||||
import os.path
|
import os.path
|
||||||
from EntryDialog import EntryDialog
|
from EntryDialog import EntryDialog
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
|
||||||
### Config Dialog ###
|
# Config Dialog #
|
||||||
class CruSSHConf:
|
class CruSSHConf:
|
||||||
### State Vars ###
|
# State Vars #
|
||||||
Config = {}
|
Config = {}
|
||||||
MainWin = gtk.Window()
|
MainWin = gtk.Window()
|
||||||
|
|
||||||
### Signal Hooks ###
|
# Signal Hooks #
|
||||||
def save_hook(self, discard, save_func):
|
def save_hook(self, discard, save_func):
|
||||||
self.MainWin.destroy()
|
self.MainWin.destroy()
|
||||||
if save_func is not None:
|
if save_func is not None:
|
||||||
@ -44,7 +43,7 @@ class CruSSHConf:
|
|||||||
def maximized_hook(self, checkbutton):
|
def maximized_hook(self, checkbutton):
|
||||||
self.Config["start-maximized"] = checkbutton.get_active()
|
self.Config["start-maximized"] = checkbutton.get_active()
|
||||||
|
|
||||||
### GUI Objects ###
|
# GUI Objects #
|
||||||
def initGUI(self, save_func=None):
|
def initGUI(self, save_func=None):
|
||||||
self.MainWin.set_modal(True)
|
self.MainWin.set_modal(True)
|
||||||
|
|
||||||
@ -115,7 +114,7 @@ class CruSSHConf:
|
|||||||
self.initGUI(save_func)
|
self.initGUI(save_func)
|
||||||
|
|
||||||
|
|
||||||
### Hosts Mask Dialog ###
|
# Hosts Mask Dialog #
|
||||||
class HostsMask:
|
class HostsMask:
|
||||||
Terminals = {}
|
Terminals = {}
|
||||||
MainWin = gtk.Window()
|
MainWin = gtk.Window()
|
||||||
@ -151,7 +150,7 @@ class HostsMask:
|
|||||||
HostCheckbox = gtk.CheckButton()
|
HostCheckbox = gtk.CheckButton()
|
||||||
HostCheckbox.set_active(self.Terminals[host].copy_input)
|
HostCheckbox.set_active(self.Terminals[host].copy_input)
|
||||||
HostCheckbox.connect("toggled", self.toggle_func, host)
|
HostCheckbox.connect("toggled", self.toggle_func, host)
|
||||||
HostTable.attach(HostCheckbox, 1, 2, 0, 1,gtk.AttachOptions.EXPAND, gtk.AttachOptions.EXPAND, 0, 0)
|
HostTable.attach(HostCheckbox, 1, 2, 0, 1, gtk.AttachOptions.EXPAND, gtk.AttachOptions.EXPAND, 0, 0)
|
||||||
row = i / cols
|
row = i / cols
|
||||||
col = i % cols
|
col = i % cols
|
||||||
HostsConfTable.attach(HostTable, col, col+1, row, row+1, gtk.AttachOptions.EXPAND, gtk.AttachOptions.EXPAND, 0, 0)
|
HostsConfTable.attach(HostTable, col, col+1, row, row+1, gtk.AttachOptions.EXPAND, gtk.AttachOptions.EXPAND, 0, 0)
|
||||||
@ -173,9 +172,9 @@ class HostsMask:
|
|||||||
self.InitGUI()
|
self.InitGUI()
|
||||||
|
|
||||||
|
|
||||||
### CruSSH! ###
|
# CruSSH! #
|
||||||
class CruSSH:
|
class CruSSH:
|
||||||
### Config Vars ###
|
# Config Vars #
|
||||||
# config defaults
|
# config defaults
|
||||||
Config = {
|
Config = {
|
||||||
"min-width": 80,
|
"min-width": 80,
|
||||||
@ -184,19 +183,19 @@ class CruSSH:
|
|||||||
"start-maximized": True
|
"start-maximized": True
|
||||||
}
|
}
|
||||||
|
|
||||||
### State Vars ###
|
# State Vars #
|
||||||
Terminals = OrderedDict()
|
Terminals = OrderedDict()
|
||||||
TermMinWidth = 1
|
TermMinWidth = 1
|
||||||
TermMinHeight = 1
|
TermMinHeight = 1
|
||||||
|
|
||||||
### GUI Objects ###
|
# GUI Objects #
|
||||||
MainWin = gtk.Window()
|
MainWin = gtk.Window()
|
||||||
ScrollWin = gtk.ScrolledWindow()
|
ScrollWin = gtk.ScrolledWindow()
|
||||||
LayoutTable = gtk.Table()
|
LayoutTable = gtk.Table()
|
||||||
EntryBox = gtk.Entry()
|
EntryBox = gtk.Entry()
|
||||||
Clipboard = gtk.Clipboard()
|
Clipboard = gtk.Clipboard()
|
||||||
|
|
||||||
### Methods ###
|
# Methods #
|
||||||
def reflowTable(self, cols=1, rows=1):
|
def reflowTable(self, cols=1, rows=1):
|
||||||
# empty table and re-size
|
# empty table and re-size
|
||||||
hosts = list(self.Terminals.keys())
|
hosts = list(self.Terminals.keys())
|
||||||
@ -245,15 +244,15 @@ class CruSSH:
|
|||||||
|
|
||||||
# check for paste key shortcut (ctl-shift-v)
|
# check for paste key shortcut (ctl-shift-v)
|
||||||
if (event.type == gdk.EventType.KEY_PRESS) \
|
if (event.type == gdk.EventType.KEY_PRESS) \
|
||||||
and (event.state & gdk.ModifierType.CONTROL_MASK == gdk.ModifierType.CONTROL_MASK) \
|
and (event.state & gdk.ModifierType.CONTROL_MASK == gdk.ModifierType.CONTROL_MASK) \
|
||||||
and (event.state & gdk.ModifierType.SHIFT_MASK == gdk.ModifierType.SHIFT_MASK) \
|
and (event.state & gdk.ModifierType.SHIFT_MASK == gdk.ModifierType.SHIFT_MASK) \
|
||||||
and (event.keyval == gdk.keyval_from_name('V')):
|
and (event.keyval == gdk.keyval_from_name('V')):
|
||||||
widget.paste_clipboard()
|
widget.paste_clipboard()
|
||||||
return True
|
return True
|
||||||
elif (event.type == gdk.EventType.KEY_PRESS) \
|
elif (event.type == gdk.EventType.KEY_PRESS) \
|
||||||
and (event.state & gdk.ModifierType.CONTROL_MASK == gdk.ModifierType.CONTROL_MASK) \
|
and (event.state & gdk.ModifierType.CONTROL_MASK == gdk.ModifierType.CONTROL_MASK) \
|
||||||
and (event.state & gdk.ModifierType.SHIFT_MASK == gdk.ModifierType.SHIFT_MASK) \
|
and (event.state & gdk.ModifierType.SHIFT_MASK == gdk.ModifierType.SHIFT_MASK) \
|
||||||
and (event.keyval == gdk.keyval_from_name('C')):
|
and (event.keyval == gdk.keyval_from_name('C')):
|
||||||
widget.copy_clipboard()
|
widget.copy_clipboard()
|
||||||
return True
|
return True
|
||||||
terminal = vte.Terminal()
|
terminal = vte.Terminal()
|
||||||
@ -348,13 +347,10 @@ class CruSSH:
|
|||||||
self.Config = new_config
|
self.Config = new_config
|
||||||
self.reflow(force=True)
|
self.reflow(force=True)
|
||||||
# save to file last, so it doesn't hold up other GUI actions
|
# save to file last, so it doesn't hold up other GUI actions
|
||||||
conf_json = json.dumps(self.Config, sort_keys=True, indent=4)
|
conf_yaml = yaml.dump(self.Config, sort_keys=True, indent=4)
|
||||||
try:
|
conf_file = open(os.path.expanduser("~/.config/crussh.yml"), 'w')
|
||||||
conf_file = open(os.path.expanduser("~/.crusshrc"), 'w')
|
conf_file.write(conf_yaml)
|
||||||
conf_file.write(conf_json)
|
conf_file.close()
|
||||||
conf_file.close()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
PrefsItem.connect("activate", lambda discard: CruSSHConf(self.Config, save_func))
|
PrefsItem.connect("activate", lambda discard: CruSSHConf(self.Config, save_func))
|
||||||
EditMenu.append(PrefsItem)
|
EditMenu.append(PrefsItem)
|
||||||
MainMenuBar.append(EditItem)
|
MainMenuBar.append(EditItem)
|
||||||
@ -389,8 +385,8 @@ class CruSSH:
|
|||||||
if (event.type == gdk.EventType.KEY_PRESS) \
|
if (event.type == gdk.EventType.KEY_PRESS) \
|
||||||
and (event.state & gdk.ModifierType.CONTROL_MASK == gdk.ModifierType.CONTROL_MASK) \
|
and (event.state & gdk.ModifierType.CONTROL_MASK == gdk.ModifierType.CONTROL_MASK) \
|
||||||
and (event.state & gdk.ModifierType.SHIFT_MASK == gdk.ModifierType.SHIFT_MASK) \
|
and (event.state & gdk.ModifierType.SHIFT_MASK == gdk.ModifierType.SHIFT_MASK) \
|
||||||
and (event.get_keyval == gdk.keyval_from_name('V')):
|
and (event.get_keyval == gdk.keyval_from_name('V')):
|
||||||
feed_paste(widget)
|
feed_paste(widget)
|
||||||
else:
|
else:
|
||||||
# propagate to every terminal
|
# propagate to every terminal
|
||||||
for host in self.Terminals:
|
for host in self.Terminals:
|
||||||
@ -423,9 +419,10 @@ class CruSSH:
|
|||||||
# load existing config file, if present
|
# load existing config file, if present
|
||||||
try:
|
try:
|
||||||
# merge dicts to allow upgrade from old configs
|
# merge dicts to allow upgrade from old configs
|
||||||
new_config = json.load(open(os.path.expanduser('~/.crusshrc')))
|
new_config = yaml.safe_load(open(os.path.expanduser('~/.config/crussh.yml')))
|
||||||
self.Config.update(new_config)
|
if new_config is not None:
|
||||||
except:
|
self.Config.update(new_config)
|
||||||
|
except (FileNotFoundError, yaml.scanner.ScannerError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# init all terminals
|
# init all terminals
|
||||||
@ -446,15 +443,15 @@ class CruSSH:
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
### Parse CLI Args ###
|
# Parse CLI Args #
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Connect to multiple hosts in parallel.",
|
description="Connect to multiple hosts in parallel.",
|
||||||
usage="%(prog)s [OPTIONS] [--] HOST [HOST ...]",
|
usage="%(prog)s [OPTIONS] [--] HOST [HOST ...]",
|
||||||
epilog="* NOTE: options before '--' will be passed directly to the SSH client.")
|
epilog="* NOTE: options before '--' will be passed directly to the SSH client.")
|
||||||
parser.add_argument("--ssh", "-s", dest='ssh', default="/usr/bin/ssh",
|
parser.add_argument("--ssh", "-s", dest='ssh', default="/usr/bin/ssh",
|
||||||
help="specify the SSH executable to use (default: %(default)s)")
|
help="specify the SSH executable to use (default: %(default)s)")
|
||||||
parser.add_argument("--hosts-file", "-f", dest='hosts_file', default="",
|
parser.add_argument("--hosts-file", "-f", dest='hosts_file', default="",
|
||||||
help="A file containing a list of hosts to connect to.")
|
help="A file containing a list of hosts to connect to.")
|
||||||
(args, hosts) = parser.parse_known_args()
|
(args, hosts) = parser.parse_known_args()
|
||||||
|
|
||||||
# load hosts from file, if available
|
# load hosts from file, if available
|
||||||
@ -469,12 +466,13 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
offset = hosts.index("--")
|
offset = hosts.index("--")
|
||||||
except:
|
ssh_args = hosts[0:offset]
|
||||||
|
except ValueError:
|
||||||
|
offset = -1
|
||||||
ssh_args = []
|
ssh_args = []
|
||||||
else:
|
|
||||||
ssh_args = " ".join(hosts[0:offset])
|
|
||||||
hosts = hosts[offset + 1:]
|
|
||||||
|
|
||||||
### Start Execution ###
|
hosts = hosts[offset + 1:]
|
||||||
|
|
||||||
|
# Start Execution #
|
||||||
crussh = CruSSH(hosts, args.ssh, ssh_args)
|
crussh = CruSSH(hosts, args.ssh, ssh_args)
|
||||||
gtk.main()
|
gtk.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user