mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2024-12-26 09:58:31 +01:00
Refactor instance
Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
parent
01d80bb8af
commit
cb8d54b581
1 changed files with 5 additions and 5 deletions
|
@ -21,7 +21,7 @@ class FormConfigs(Configs):
|
||||||
self.dialogbox = DialogBox()
|
self.dialogbox = DialogBox()
|
||||||
self.errors = Errors()
|
self.errors = Errors()
|
||||||
|
|
||||||
self.toml_original: dict = {}
|
self.original_configs: dict = {}
|
||||||
self.config_file: Path = Path(self.etc_path, f'{self.prog_name}.toml')
|
self.config_file: Path = Path(self.etc_path, f'{self.prog_name}.toml')
|
||||||
|
|
||||||
def is_dialog_enabled(self) -> None:
|
def is_dialog_enabled(self) -> None:
|
||||||
|
@ -68,7 +68,7 @@ class FormConfigs(Configs):
|
||||||
def read_configs(self) -> None:
|
def read_configs(self) -> None:
|
||||||
"""Read the original config file."""
|
"""Read the original config file."""
|
||||||
with open(self.config_file, 'r', encoding='utf-8') as 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:
|
def write_configs(self, tags: list) -> None:
|
||||||
"""Write new configs to the file.
|
"""Write new configs to the file.
|
||||||
|
@ -78,7 +78,7 @@ class FormConfigs(Configs):
|
||||||
"""
|
"""
|
||||||
self.read_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.
|
digit_pattern = re.compile(r"^-?\d+(\.\d+)?$") # pattern for int and float numbers.
|
||||||
list_pattern = re.compile(r'^\s*\[.*\]\s*$') # pattern for list.
|
list_pattern = re.compile(r'^\s*\[.*\]\s*$') # pattern for list.
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ class FormConfigs(Configs):
|
||||||
elif list_pattern.match(new):
|
elif list_pattern.match(new):
|
||||||
new = ast.literal_eval(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:
|
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))
|
||||||
|
|
Loading…
Reference in a new issue