Compare commits

..

4 Commits

Author SHA1 Message Date
dw-0
08ab2d6090 Merge commit '681e5d8d05d035905e6fc694af93ee27ac87dbf2' into fix/section-adding 2024-09-24 22:11:53 +02:00
dw-0
681e5d8d05 Squashed 'kiauh/core/submodules/simple_config_parser/' changes from 7835d2b..3a006f1
3a006f1 fix: correctly update last element value

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: 3a006f1b4695919f27c6759c94b538acdda13e48
2024-09-24 22:11:53 +02:00
dw-0
687822d540 Merge commit '12080a2c42152df276b6239d7fda72504ea7fe0f' into fix/section-adding 2024-09-24 21:37:56 +02:00
dw-0
12080a2c42 Squashed 'kiauh/core/submodules/simple_config_parser/' changes from 90081a6..7835d2b
7835d2b refactor: further improvement of adding new sections (#3)

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: 7835d2b6e37ea0de940b0e4158278f4cfc349379
2024-09-24 21:37:56 +02:00

View File

@@ -192,11 +192,24 @@ class SimpleConfigParser:
self.config[section] = {"_raw": f"[{section}]\n"}
def _check_set_section_spacing(self):
prev_section: str = self.get_sections()[-1]
prev_section_content: Dict = self.config[prev_section]
last_item: str = list(prev_section_content.keys())[-1]
if last_item.startswith("#_") and prev_section_content[last_item][-1] != "\n":
prev_section_content[last_item].append("\n")
prev_section_name: str = self.get_sections()[-1]
prev_section_content: Dict = self.config[prev_section_name]
last_option_name: str = list(prev_section_content.keys())[-1]
if last_option_name.startswith("#_"):
last_elem_value: str = prev_section_content[last_option_name][-1]
# if the last section is a collector, we first check if the last element
# in the collector ends with a newline. if it does not, we append a newline.
# this can happen if the config file does not end with a newline.
if not last_elem_value.endswith("\n"):
prev_section_content[last_option_name][-1] = f"{last_elem_value}\n"
# if the last item in a collector is not a newline, we append a newline, so
# that the new section is seperated from the options of the previous section
# by a newline
if last_elem_value != "\n":
prev_section_content[last_option_name].append("\n")
else:
prev_section_content[self._generate_rand_id()] = ["\n"]