Refactor instance

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2024-06-07 15:39:38 +03:00
parent 01d80bb8af
commit cb8d54b581

View file

@ -21,7 +21,7 @@ class FormConfigs(Configs):
self.dialogbox = DialogBox()
self.errors = Errors()
self.toml_original: dict = {}
self.original_configs: dict = {}
self.config_file: Path = Path(self.etc_path, f'{self.prog_name}.toml')
def is_dialog_enabled(self) -> None:
@ -68,7 +68,7 @@ class FormConfigs(Configs):
def read_configs(self) -> None:
"""Read the original config file."""
with open(self.config_file, 'r', encoding='utf-8') as file:
self.toml_original: dict = tomlkit.parse(file.read())
self.original_configs: dict = tomlkit.parse(file.read())
def write_configs(self, tags: list) -> None:
"""Write new configs to the file.
@ -78,7 +78,7 @@ class FormConfigs(Configs):
"""
self.read_configs()
for key, new in zip(self.toml_original['CONFIGS'].keys(), tags):
for key, new in zip(self.original_configs['CONFIGS'].keys(), tags):
digit_pattern = re.compile(r"^-?\d+(\.\d+)?$") # pattern for int and float numbers.
list_pattern = re.compile(r'^\s*\[.*\]\s*$') # pattern for list.
@ -94,7 +94,7 @@ class FormConfigs(Configs):
elif list_pattern.match(new):
new = ast.literal_eval(new)
self.toml_original['CONFIGS'][key] = new
self.original_configs['CONFIGS'][key] = new
with open(self.config_file, 'w', encoding='utf-8') as file:
file.write(tomlkit.dumps(self.toml_original))
file.write(tomlkit.dumps(self.original_configs))