Validates the layout of the section/option mapping. Returns a bool indicating if validation was successful, and a list of log messages for the init log.
(parser: ConfigParser)
| 533 | |
| 534 | |
| 535 | def _validate_structure(parser: ConfigParser) -> tuple[bool, list[LogMessage]]: |
| 536 | """Validates the layout of the section/option mapping. Returns a bool indicating if validation |
| 537 | was successful, and a list of log messages for the init log.""" |
| 538 | logs: list[LogMessage] = [] |
| 539 | success = True |
| 540 | all_sections = set(parser.sections()) |
| 541 | for section in all_sections: |
| 542 | section_name = section |
| 543 | if section in DEPRECATED_COMMANDS: |
| 544 | section = DEPRECATED_COMMANDS[section] |
| 545 | logs.append( |
| 546 | ( |
| 547 | logging.WARNING, |
| 548 | f"WARNING: [{section_name}] is deprecated and will be removed!" |
| 549 | f"Use [{section}] instead.", |
| 550 | ) |
| 551 | ) |
| 552 | # The parser already handled duplicate sections, but it doesn't know about deprecated |
| 553 | # aliases. If there's a conflict, make sure we error out instead of warning. |
| 554 | if section in all_sections: |
| 555 | success = False |
| 556 | logs.append( |
| 557 | ( |
| 558 | logging.ERROR, |
| 559 | f"[{section_name}] conflicts with [{section}], only specify one.", |
| 560 | ) |
| 561 | ) |
| 562 | continue |
| 563 | elif section not in CONFIG_MAP: |
| 564 | success = False |
| 565 | logs.append((logging.ERROR, f"Unsupported config section: [{section_name}]")) |
| 566 | continue |
| 567 | for option_name, _ in parser.items(section_name): |
| 568 | if option_name not in CONFIG_MAP[section]: |
| 569 | success = False |
| 570 | logs.append( |
| 571 | ( |
| 572 | logging.ERROR, |
| 573 | f"Unsupported config option in [{section_name}]: [{option_name}]", |
| 574 | ) |
| 575 | ) |
| 576 | return (success, logs) |
| 577 | |
| 578 | |
| 579 | def _parse_config(parser: ConfigParser) -> tuple[ConfigDict | None, list[LogMessage]]: |