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
|
||||
gi.require_version('Vte', '2.91')
|
||||
from gi.repository import Vte as vte
|
||||
import sys
|
||||
import math
|
||||
import json
|
||||
import yaml
|
||||
import os.path
|
||||
from EntryDialog import EntryDialog
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
### Config Dialog ###
|
||||
# Config Dialog #
|
||||
class CruSSHConf:
|
||||
### State Vars ###
|
||||
# State Vars #
|
||||
Config = {}
|
||||
MainWin = gtk.Window()
|
||||
|
||||
### Signal Hooks ###
|
||||
# Signal Hooks #
|
||||
def save_hook(self, discard, save_func):
|
||||
self.MainWin.destroy()
|
||||
if save_func is not None:
|
||||
@ -44,7 +43,7 @@ class CruSSHConf:
|
||||
def maximized_hook(self, checkbutton):
|
||||
self.Config["start-maximized"] = checkbutton.get_active()
|
||||
|
||||
### GUI Objects ###
|
||||
# GUI Objects #
|
||||
def initGUI(self, save_func=None):
|
||||
self.MainWin.set_modal(True)
|
||||
|
||||
@ -115,7 +114,7 @@ class CruSSHConf:
|
||||
self.initGUI(save_func)
|
||||
|
||||
|
||||
### Hosts Mask Dialog ###
|
||||
# Hosts Mask Dialog #
|
||||
class HostsMask:
|
||||
Terminals = {}
|
||||
MainWin = gtk.Window()
|
||||
@ -173,9 +172,9 @@ class HostsMask:
|
||||
self.InitGUI()
|
||||
|
||||
|
||||
### CruSSH! ###
|
||||
# CruSSH! #
|
||||
class CruSSH:
|
||||
### Config Vars ###
|
||||
# Config Vars #
|
||||
# config defaults
|
||||
Config = {
|
||||
"min-width": 80,
|
||||
@ -184,19 +183,19 @@ class CruSSH:
|
||||
"start-maximized": True
|
||||
}
|
||||
|
||||
### State Vars ###
|
||||
# State Vars #
|
||||
Terminals = OrderedDict()
|
||||
TermMinWidth = 1
|
||||
TermMinHeight = 1
|
||||
|
||||
### GUI Objects ###
|
||||
# GUI Objects #
|
||||
MainWin = gtk.Window()
|
||||
ScrollWin = gtk.ScrolledWindow()
|
||||
LayoutTable = gtk.Table()
|
||||
EntryBox = gtk.Entry()
|
||||
Clipboard = gtk.Clipboard()
|
||||
|
||||
### Methods ###
|
||||
# Methods #
|
||||
def reflowTable(self, cols=1, rows=1):
|
||||
# empty table and re-size
|
||||
hosts = list(self.Terminals.keys())
|
||||
@ -348,13 +347,10 @@ class CruSSH:
|
||||
self.Config = new_config
|
||||
self.reflow(force=True)
|
||||
# save to file last, so it doesn't hold up other GUI actions
|
||||
conf_json = json.dumps(self.Config, sort_keys=True, indent=4)
|
||||
try:
|
||||
conf_file = open(os.path.expanduser("~/.crusshrc"), 'w')
|
||||
conf_file.write(conf_json)
|
||||
conf_yaml = yaml.dump(self.Config, sort_keys=True, indent=4)
|
||||
conf_file = open(os.path.expanduser("~/.config/crussh.yml"), 'w')
|
||||
conf_file.write(conf_yaml)
|
||||
conf_file.close()
|
||||
except:
|
||||
pass
|
||||
PrefsItem.connect("activate", lambda discard: CruSSHConf(self.Config, save_func))
|
||||
EditMenu.append(PrefsItem)
|
||||
MainMenuBar.append(EditItem)
|
||||
@ -423,9 +419,10 @@ class CruSSH:
|
||||
# load existing config file, if present
|
||||
try:
|
||||
# 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)
|
||||
except:
|
||||
except (FileNotFoundError, yaml.scanner.ScannerError):
|
||||
pass
|
||||
|
||||
# init all terminals
|
||||
@ -446,7 +443,7 @@ class CruSSH:
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
|
||||
### Parse CLI Args ###
|
||||
# Parse CLI Args #
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Connect to multiple hosts in parallel.",
|
||||
usage="%(prog)s [OPTIONS] [--] HOST [HOST ...]",
|
||||
@ -469,12 +466,13 @@ if __name__ == "__main__":
|
||||
|
||||
try:
|
||||
offset = hosts.index("--")
|
||||
except:
|
||||
ssh_args = hosts[0:offset]
|
||||
except ValueError:
|
||||
offset = -1
|
||||
ssh_args = []
|
||||
else:
|
||||
ssh_args = " ".join(hosts[0:offset])
|
||||
|
||||
hosts = hosts[offset + 1:]
|
||||
|
||||
### Start Execution ###
|
||||
# Start Execution #
|
||||
crussh = CruSSH(hosts, args.ssh, ssh_args)
|
||||
gtk.main()
|
||||
|
Loading…
Reference in New Issue
Block a user