This commit is contained in:
Jonas Forsberg 2021-09-23 09:08:49 +02:00
parent 668052686a
commit 4ebdece57c

View File

@ -5,12 +5,14 @@ gi.require_version("Gtk", "3.0")
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import Gio from gi.repository import Gio
import os
import time import time
import threading import threading
import logging import logging
import subprocess import subprocess
import psutil import psutil
import socket import socket
import yaml
LOGLEVEL=logging.DEBUG LOGLEVEL=logging.DEBUG
#LOGLEVEL=logging.WARNING #LOGLEVEL=logging.WARNING
@ -19,8 +21,10 @@ SLEEPTIMER=2
class Main: class Main:
def __init__(self): def __init__(self):
scriptpath = os.path.dirname(os.path.realpath(__file__))
logging.debug("Executing from %s", scriptpath)
self.builder = Gtk.Builder() self.builder = Gtk.Builder()
self.builder.add_from_file("main.glade") self.builder.add_from_file(f"{scriptpath}/main.glade")
self.builder.connect_signals(self) self.builder.connect_signals(self)
self.windowMain = self.builder.get_object("MainWindow") self.windowMain = self.builder.get_object("MainWindow")
@ -42,8 +46,30 @@ class Main:
self.icon_ok = Gio.ThemedIcon(name="gtk-yes") self.icon_ok = Gio.ThemedIcon(name="gtk-yes")
self.icon_not_ok = Gio.ThemedIcon(name="gtk-no") self.icon_not_ok = Gio.ThemedIcon(name="gtk-no")
self.lan_nic = "eth0" yamlpath = scriptpath.replace("tlumon","salt/pillars")
self.wan_nic = "wlan0" try:
with open(f"{yamlpath}/network.sls", "r") as f:
logging.debug("Reading global config %s", f"{yamlpath}/network.sls")
config = yaml.safe_load(f)
except FileNotFoundError as e:
logging.error("Couldn't read global config: %s", e)
try:
with open(f"{yamlpath}/local.sls", "r") as f:
localconfig = taml_safe_load(f)
except FileNotFoundError as e:
logging.debug("Couldn't read local config: %s", e)
localconfig = {}
print(config)
try:
self.lan_nic = localconfig["network"]["interface"]["internal"]
except KeyError:
self.lan_nic = config["network"]["interface"]["internal"]
try:
self.wan_nic = localconfig["network"]["interface"]["external"]
except KeyError:
self.wan_nic = config["network"]["interface"]["external"]
self.builder.get_object("lbl_wan").set_text(f"wan ({self.wan_nic})") self.builder.get_object("lbl_wan").set_text(f"wan ({self.wan_nic})")
self.builder.get_object("lbl_lan").set_text(f"lan ({self.lan_nic})") self.builder.get_object("lbl_lan").set_text(f"lan ({self.lan_nic})")