From 7c55bfe5e3df7f2725604b6c238c84c9f5ce70fb Mon Sep 17 00:00:00 2001 From: Adam <123621952+morington@users.noreply.github.com> Date: Sun, 30 Jun 2024 23:16:33 +0300 Subject: [PATCH] Bug fix. Overwriting configurations does not delete data from configs. --- confhub/builder.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/confhub/builder.py b/confhub/builder.py index 472c587..7468c6d 100644 --- a/confhub/builder.py +++ b/confhub/builder.py @@ -54,21 +54,17 @@ def create_files(self, config_path: Path) -> None: for filename, data in self.datafiles.items(): file_path = config_path / Path(f'{filename}.yml') - existing_file = None if file_path.exists(): - while existing_file is None: - result = input(f"The `{file_path}` file already exists, should I recreate it? [Y/n] ") + with open(file_path, 'r', encoding='utf-8') as file: + yaml_data = yaml.safe_load(file) - if result.lower() in ['y', 'n', '', ' ']: - if result.lower() == 'n': - existing_file = False - else: - existing_file = True + for key in data: + if key in yaml_data: + for inner_key in data[key]: + if inner_key in yaml_data[key]: + data[key][inner_key] = yaml_data[key][inner_key] - if existing_file or existing_file is None: - with open(file_path, 'w', encoding='utf-8') as file: - yaml.dump(data, file, default_flow_style=False) + with open(file_path, 'w', encoding='utf-8') as file: + yaml.dump(data, file, default_flow_style=False) - logger.info("Create file", path=file_path) - else: - logger.info('Skip...', path=file_path) + logger.info("Create file", path=file_path)