@eshanized updated the repository!!!

This commit is contained in:
Eshan Roy (Eshanized)
2024-04-23 13:16:28 +05:30
parent 93bbe73ebf
commit 4dad4abbe0
2 changed files with 49 additions and 1 deletions

View File

@@ -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

View File

@@ -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!")