From bf19bcecae2a20c8fc59271bac5800c62251efd6 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Wed, 6 Apr 2022 06:58:44 -0400 Subject: [PATCH] moonraker: report additional configuration info Signed-off-by: Eric Callahan --- moonraker/confighelper.py | 11 +++++++++++ moonraker/moonraker.py | 19 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/moonraker/confighelper.py b/moonraker/confighelper.py index 5c47570..13175d3 100644 --- a/moonraker/confighelper.py +++ b/moonraker/confighelper.py @@ -433,6 +433,17 @@ class ConfigHelper: def get_parsed_config(self) -> Dict[str, Dict[str, ConfigVal]]: return dict(self.parsed) + def get_orig_config(self) -> Dict[str, Dict[str, str]]: + return { + key: dict(val) for key, val in self.config.items() + } + + def get_file_sections(self) -> Dict[str, List[str]]: + return dict(self.file_section_map) + + def get_config_files(self) -> List[str]: + return list(self.file_section_map.keys()) + def validate_config(self) -> None: for sect in self.config.sections(): if sect not in self.parsed: diff --git a/moonraker/moonraker.py b/moonraker/moonraker.py index 33ce38b..39cf792 100755 --- a/moonraker/moonraker.py +++ b/moonraker/moonraker.py @@ -6,6 +6,7 @@ # This file may be distributed under the terms of the GNU GPLv3 license from __future__ import annotations +import pathlib import sys import argparse import importlib @@ -130,11 +131,14 @@ class Server: def _parse_config(self) -> confighelper.ConfigHelper: config = confighelper.get_configuration(self, self.app_args) # log config file + cfg_files = "\n".join(config.get_config_files()) strio = io.StringIO() config.write_config(strio) cfg_item = f"\n{'#'*20} Moonraker Configuration {'#'*20}\n\n" cfg_item += strio.getvalue() cfg_item += "#"*65 + cfg_item += f"\nAll Configuration Files:\n{cfg_files}\n" + cfg_item += "#"*65 strio.close() self.add_log_rollover_item('config', cfg_item) return config @@ -400,8 +404,21 @@ class Server: async def _handle_config_request(self, web_request: WebRequest ) -> Dict[str, Any]: + cfg_file_list: List[Dict[str, Any]] = [] + cfg_parent = pathlib.Path( + self.app_args["config_file"] + ).expanduser().resolve().parent + for fname, sections in self.config.get_file_sections().items(): + path = pathlib.Path(fname) + try: + rel_path = str(path.relative_to(str(cfg_parent))) + except ValueError: + rel_path = fname + cfg_file_list.append({"filename": rel_path, "sections": sections}) return { - 'config': self.config.get_parsed_config() + 'config': self.config.get_parsed_config(), + 'orig': self.config.get_orig_config(), + 'files': cfg_file_list } def main(cmd_line_args: argparse.Namespace) -> None: