finally fixed crussh up
This commit is contained in:
parent
a84fa83cf2
commit
07b0d31543
48
crussh.py
48
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()
|
||||||
@ -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())
|
||||||
@ -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)
|
||||||
@ -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')))
|
||||||
|
if new_config is not None:
|
||||||
self.Config.update(new_config)
|
self.Config.update(new_config)
|
||||||
except:
|
except (FileNotFoundError, yaml.scanner.ScannerError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# init all terminals
|
# init all terminals
|
||||||
@ -446,7 +443,7 @@ 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 ...]",
|
||||||
@ -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:]
|
hosts = hosts[offset + 1:]
|
||||||
|
|
||||||
### Start Execution ###
|
# 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