Merge pull request #198 from fosslinux/config-unchanged

tell user config setting is unchanged
This commit is contained in:
jesopo 2019-11-01 06:52:36 +00:00 committed by GitHub
commit 00cf00f31a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,8 @@ class ConfigResults(enum.Enum):
Changed = 1 Changed = 1
Retrieved = 2 Retrieved = 2
Removed = 3 Removed = 3
Unchanged = 4
class ConfigResult(object): class ConfigResult(object):
def __init__(self, result, data=None): def __init__(self, result, data=None):
self.result = result self.result = result
@ -121,6 +123,10 @@ class Module(ModuleManager.BaseModule):
raise ConfigInvalidValue(str(e)) raise ConfigInvalidValue(str(e))
if not validated_value == None: if not validated_value == None:
existing_value = target.get_setting(setting, None)
if existing_value == validated_value:
return ConfigResult(ConfigResults.Unchanged)
else:
target.set_setting(setting, validated_value) target.set_setting(setting, validated_value)
formatted_value = setting_object.format(validated_value) formatted_value = setting_object.format(validated_value)
return ConfigResult(ConfigResults.Changed, formatted_value) return ConfigResult(ConfigResults.Changed, formatted_value)
@ -231,6 +237,9 @@ class Module(ModuleManager.BaseModule):
elif result.result == ConfigResults.Removed: elif result.result == ConfigResults.Removed:
event["stdout"].write("Unset setting '%s'%s" % event["stdout"].write("Unset setting '%s'%s" %
(setting.lstrip("-"), for_str)) (setting.lstrip("-"), for_str))
elif result.result == ConfigResults.Unchanged:
event["stdout"].write("Config '%s'%s unchanged" %
(setting, for_str))
else: else:
event["stdout"].write("Available config: %s" % event["stdout"].write("Available config: %s" %
", ".join(export_settings.keys())) ", ".join(export_settings.keys()))