From 730e66cdf019f7c17454bf61e16070b308d43397 Mon Sep 17 00:00:00 2001 From: Eukanj827 Date: Wed, 3 Aug 2022 21:00:46 +0800 Subject: [PATCH] Update config_utils.py --- .../dbmind/tools/cmd/config_utils.py | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/gausskernel/dbmind/tools/cmd/config_utils.py b/src/gausskernel/dbmind/tools/cmd/config_utils.py index e1c51818..2c2b73d3 100644 --- a/src/gausskernel/dbmind/tools/cmd/config_utils.py +++ b/src/gausskernel/dbmind/tools/cmd/config_utils.py @@ -55,7 +55,12 @@ CONFIG_OPTIONS = { 'LOG-level': ['DEBUG', 'INFO', 'WARNING', 'ERROR'] } - +#function name: check_config_validity +#description: Checks the validity of the passed parameter +#arguments: section, option, value +#return value: bool and string +#date: 2022/8/ +#contact: 1865997821 def check_config_validity(section, option, value): config_item = '%s-%s' % (section, option) # exceptional cases: @@ -87,6 +92,16 @@ def check_config_validity(section, option, value): return True, None + +#function name: load_sys_configs +#description: Create and load the modification file +#arguments: The configuration to modify +#return value: a new configuration file +#note:To facilitate the user to modify the configuration items through the +#configuration file easily, we add inline comments to the file, but we need to remove the inline comments while parsing. +#Otherwise, it will cause the read configuration items to be wrong. +#date: 2022/8/ +#contact: 1865997821 def load_sys_configs(confile): # Note: To facilitate the user to modify the configuration items through the # configuration file easily, we add inline comments to the file, but we need @@ -96,6 +111,8 @@ def load_sys_configs(confile): with open(file=confile, mode='r') as fp: configs.read_file(fp) + +# Define a class that encapsulates the modification item class ConfigWrapper(object): def __getattribute__(self, name): try: @@ -122,7 +139,7 @@ def load_sys_configs(confile): return ConfigWrapper() - +# Defines a class that updates the encapsulated modification file class ConfigUpdater: def __init__(self, filepath): self.config = ConfigParser(inline_comment_prefixes=None) @@ -170,7 +187,7 @@ class ConfigUpdater: self.fp.flush() self.fp.close() - +# Defines a class that dynamically displays a modified item class DynamicConfig: @staticmethod def get(*args, **kwargs):