mirror of
https://github.com/Snigdha-OS/snigdhaos-blackbox.git
synced 2025-09-21 03:55:05 +02:00
⏳ @eshanized updated the repository!!!
This commit is contained in:
@@ -10,3 +10,72 @@ base_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
# NOTE: Deafult Config File
|
||||
default_file = "%s/defaults/blackbox.yaml"
|
||||
|
||||
class Settings(object):
|
||||
def __init__(self, display_versions, display_package_progress):
|
||||
self.display_versions = display_versions
|
||||
self.display_package_progress = display_package_progress
|
||||
|
||||
def write_cofig_file(self):
|
||||
try:
|
||||
content = [] # NOTE: Passing an empty array, set default will be called
|
||||
with open(fn.config_file, "r", encoding="UTF-8") as f:
|
||||
contents = f.readlines()
|
||||
if len(contents) > 0:
|
||||
self.read(contents)
|
||||
conf_settings = {}
|
||||
conf_settings[
|
||||
"Display Package Versions"
|
||||
] = self.display_versions
|
||||
conf_settings[
|
||||
"Display Package Progress"
|
||||
] = self.display_package_progress
|
||||
index = 0
|
||||
for line in contents:
|
||||
if line.startswith("- name:"):
|
||||
if (
|
||||
line.strip("- name:")
|
||||
.strip()
|
||||
.strip('"')
|
||||
.strip("\n")
|
||||
.strip()
|
||||
== "Display Package Versions"
|
||||
):
|
||||
index = contents.index(line)
|
||||
index += 2
|
||||
if contents[index].startswith(" enabled: "):
|
||||
del contents[index]
|
||||
contents.insert(
|
||||
index,
|
||||
" enabled: %s\n"
|
||||
% conf_settings["Display Package Versions"],
|
||||
)
|
||||
if (
|
||||
line.strip("- name:")
|
||||
.strip()
|
||||
.strip('"')
|
||||
.strip("\n")
|
||||
.strip()
|
||||
== "Display Package Progress"
|
||||
):
|
||||
index += 4
|
||||
if contents[index].startswith(" enabled: "):
|
||||
del contents[index]
|
||||
contents.insert(
|
||||
index,
|
||||
" enabled: %s\n"
|
||||
% conf_settings["Display Package Progress"],
|
||||
)
|
||||
|
||||
if len(contents) > 0:
|
||||
with open(fn.config_file, "w", encoding="UTF-8") as f:
|
||||
f.writelines(contents)
|
||||
fn.permissions(fn.config_dir)
|
||||
|
||||
except Exception as e:
|
||||
fn.Logger.error("[ERROR] Exception: %s" % e)
|
||||
|
||||
def read_cofig_file(self):
|
||||
try:
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user