From 4dad4abbe06b061eb85457aa83a4cf3d836de58a Mon Sep 17 00:00:00 2001 From: "Eshan Roy (Eshanized)" Date: Tue, 23 Apr 2024 13:16:28 +0530 Subject: [PATCH] =?UTF-8?q?=E2=8F=B3=20@eshanized=20updated=20the=20reposi?= =?UTF-8?q?tory!!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blackbox/Functions.py | 1 + blackbox/Settings.py | 49 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/blackbox/Functions.py b/blackbox/Functions.py index 1e05415..df8e6c7 100644 --- a/blackbox/Functions.py +++ b/blackbox/Functions.py @@ -7,6 +7,7 @@ import gi import subprocess # import logging from logging import Logger +import shutil gi.require_version("Gtk" "3.0") # GTK 2.0 is dead! from gi.repository import GLib, Gtk diff --git a/blackbox/Settings.py b/blackbox/Settings.py index 9b139df..b3794cd 100644 --- a/blackbox/Settings.py +++ b/blackbox/Settings.py @@ -77,5 +77,52 @@ class Settings(object): def read_cofig_file(self): try: - + if os.path.exists(fn.config_file): + contents = [] + with open(fn.config_file, "r", encoding="UTF-8") as f: + contents = f.readlines() + if len(contents) == 0: + fn.shutil.copy(default_file, fn.config_file) + fn.permissions(fn.config_dir) + else: + return self.read(contents) + else: + # NOTE: String Replaces the Template File + fn.shutil.copy(default_file, fn.config_file) + fn.permissions(fn.config_dir) + with open(fn.config_file, "r", encoding="UTF-8") as f: + contents = f.readlines() + return self.read(contents) + except Exception as e: + print("[ERROR] Exception: %s" % e) + def read(self, contents): + setting_name = None + setting_value_enabled = None + conf_settings = {} + for line in contents: + if line.startswith("- name:"): + setting_name = ( + line.strip("- name: ") + .strip() + .strip('"') + .strip("\n") + .strip() + ) + elif line.startswith(" enabled: "): + setting_value_enabled = ( + line.strip("- name: ") + .strip() + .strip('"') + .strip("\n") + .strip() + ) + if setting_value_enabled == "False": + conf_settings[setting_name] = False + else: + conf_settings[setting_name] = True + if len(conf_settings) > 0: + return conf_settings + else: + print("[ERROR] Failed To Read Settings!") + \ No newline at end of file