From f7bdfb4d6ba1cdae81e47b9b4cd620e35c1b4b3b Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Sun, 28 Nov 2021 06:03:46 -0500 Subject: [PATCH] confighelper: add get_hash method This returns the checksum of a config section and can be used to check if the section has changed. Signed-off-by: Eric Callahan --- moonraker/confighelper.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/moonraker/confighelper.py b/moonraker/confighelper.py index 6afbd31..b31fc08 100644 --- a/moonraker/confighelper.py +++ b/moonraker/confighelper.py @@ -7,6 +7,7 @@ from __future__ import annotations import configparser import os +import hashlib from utils import SentinelClass from components.gpio import GpioOutputPin @@ -73,6 +74,12 @@ class ConfigHelper: def get_options(self) -> Dict[str, str]: return dict(self.config[self.section]) + def get_hash(self) -> hashlib._Hash: + hash = hashlib.sha256() + for option in self.config[self.section]: + hash.update(option.encode()) + return hash + def get_prefix_sections(self, prefix: str) -> List[str]: return [s for s in self.sections() if s.startswith(prefix)]