diff --git a/tlumon/tlumon b/tlumon/tlumon index 1f64e84..f64abe1 100755 --- a/tlumon/tlumon +++ b/tlumon/tlumon @@ -5,12 +5,14 @@ gi.require_version("Gtk", "3.0") from gi.repository import Gtk from gi.repository import Gio +import os import time import threading import logging import subprocess import psutil import socket +import yaml LOGLEVEL=logging.DEBUG #LOGLEVEL=logging.WARNING @@ -19,8 +21,10 @@ SLEEPTIMER=2 class Main: def __init__(self): + scriptpath = os.path.dirname(os.path.realpath(__file__)) + logging.debug("Executing from %s", scriptpath) 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.windowMain = self.builder.get_object("MainWindow") @@ -42,8 +46,30 @@ class Main: self.icon_ok = Gio.ThemedIcon(name="gtk-yes") self.icon_not_ok = Gio.ThemedIcon(name="gtk-no") - self.lan_nic = "eth0" - self.wan_nic = "wlan0" + yamlpath = scriptpath.replace("tlumon","salt/pillars") + 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_lan").set_text(f"lan ({self.lan_nic})")