-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh-session-manager.py
executable file
·67 lines (52 loc) · 2.26 KB
/
ssh-session-manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python3
from pathlib import Path
import os
import subprocess
import gi
import xml.etree.ElementTree as Et
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class Handler:
def onDestroy(self, *args):
Gtk.main_quit()
def onButtonClicked(self, button):
print("Hello World!")
def on_tree_selection_changed(self, selection):
model, treeiter = selection.get_selected()
if treeiter is not None:
server_view = builder.get_object("server_tree_view")
if server_view.row_expanded(selection.get_selected_rows()[1][0]):
server_view.collapse_row(selection.get_selected_rows()[1][0])
else:
server_view.expand_row(selection.get_selected_rows()[1][0], False)
print("You selected", model[treeiter][0])
def on_row_activated(self, view, path, column):
model = view.get_model()
treeiter = model.get_iter(path)
if treeiter is not None:
print("You db click on", model[treeiter][0])
subprocess.Popen(['/usr/bin/gnome-terminal',
'--title', get_path_unix_style(model, treeiter),
'--', 'ssh', '{}@{}'.format(model[treeiter][2], model[treeiter][1])])
def add_to_store(store, parent, node):
store_node = store.append(parent, [node.get('Name'), node.get('Hostname'), node.get('Username')])
if len(list(node)) != 0:
for subnodes in list(node):
add_to_store(store, store_node, subnodes)
def get_path_unix_style(model, node):
parent = model.iter_parent(node)
if parent is None:
return model[node][0]
else:
return '{}/{}'.format(get_path_unix_style(model, parent),model[node][0])
builder = Gtk.Builder()
builder.add_from_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), "ssh-session-manager.glade"))
#: :type: Gtk.TreeStore
server_store = builder.get_object("server_store")
if os.path.isfile(os.path.join(str(Path.home()), 'progs/mremoteng/confCons.xml')):
tree = Et.parse(os.path.join(str(Path.home()), 'progs/mremoteng/confCons.xml'))
add_to_store(server_store, None, tree.getroot())
builder.connect_signals(Handler())
window = builder.get_object("main_window")
window.show_all()
Gtk.main()