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 <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2021-11-28 06:03:46 -05:00
parent eda5623b2e
commit f7bdfb4d6b
1 changed files with 7 additions and 0 deletions

View File

@ -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)]