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