From 530980cf31c39056db23681682036dd6ba20d03a Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Thu, 20 Jan 2022 04:14:57 +0000 Subject: [PATCH] zulip_tools: Add a get_config_bool to match Puppet logic. Unfortunately, the existing use of this logic in `process_fts_updates` cannot switch to using this code, as that code cannot import zulip_tools. --- puppet/zulip/lib/puppet/parser/functions/zulipconf.rb | 3 ++- scripts/lib/zulip_tools.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/puppet/zulip/lib/puppet/parser/functions/zulipconf.rb b/puppet/zulip/lib/puppet/parser/functions/zulipconf.rb index dc4ad55ebb..61116fb611 100644 --- a/puppet/zulip/lib/puppet/parser/functions/zulipconf.rb +++ b/puppet/zulip/lib/puppet/parser/functions/zulipconf.rb @@ -6,7 +6,8 @@ module Puppet::Parser::Functions output = `/usr/bin/crudini --get #{zulip_conf_path} #{joined} 2>&1`; result = $?.success? if result if [true, false].include? default - # If the default is a bool, coerce into a bool + # If the default is a bool, coerce into a bool. This list is also + # maintained in scripts/lib/zulip_tools.py ['1','y','t','true','yes','enable','enabled'].include? output.strip.downcase else output.strip diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.py index b2d879ab5b..e42dda9f0e 100755 --- a/scripts/lib/zulip_tools.py +++ b/scripts/lib/zulip_tools.py @@ -595,6 +595,16 @@ def get_config( return default_value +def get_config_bool( + config_file: configparser.RawConfigParser, section: str, key: str, default_value: bool = False +) -> bool: + if config_file.has_option(section, key): + val = config_file.get(section, key) + # This list is parallel to puppet/zulip/lib/puppet/parser/functions/zulipconf.rb + return val in ["1", "y", "t", "true", "yes", "enable", "enabled"] + return default_value + + def get_config_file() -> configparser.RawConfigParser: config_file = configparser.RawConfigParser() config_file.read("/etc/zulip/zulip.conf")