From 754ec8c5bfa019ad710c6dbe5b9d3267fff2b94e Mon Sep 17 00:00:00 2001 From: "moylop260@vauxoo.com" Date: Wed, 26 May 2021 14:22:37 +0000 Subject: [PATCH] [FIX] module_change_auto_install: Split string sep by comma Optimize validation Add logger to apply patch --- module_change_auto_install/patch.py | 31 +++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/module_change_auto_install/patch.py b/module_change_auto_install/patch.py index 9285ffddb..14dc00fa6 100644 --- a/module_change_auto_install/patch.py +++ b/module_change_auto_install/patch.py @@ -13,18 +13,40 @@ _original_load_information_from_description_file = ( ) +def split_strip(s): + """Split string and strip each component sep by comma + + >>> split_strip("foo, bar,") + ['foo', 'bar'] + + >>> split_strip("") + [] + + >>> split_strip(None) + [] + """ + s = (s or "").strip(" ,") + if not s: + return [] + return [x.strip() for x in s.split(",")] + + def _overload_load_information_from_description_file(module, mod_path=None): res = _original_load_information_from_description_file(module, mod_path=None) auto_install = res.get("auto_install", False) - modules_auto_install_enabled = config.get("modules_auto_install_enabled", []) - modules_auto_install_disabled = config.get("modules_auto_install_disabled", []) + modules_auto_install_enabled = split_strip( + config.get("modules_auto_install_enabled") + ) + modules_auto_install_disabled = split_strip( + config.get("modules_auto_install_disabled") + ) - if module in modules_auto_install_disabled and auto_install: + if auto_install and module in modules_auto_install_disabled: _logger.info("Module '%s' has been marked as not auto installable." % module) res["auto_install"] = False - if module in modules_auto_install_enabled and not auto_install: + if not auto_install and module in modules_auto_install_enabled: _logger.info("Module '%s' has been marked as auto installable." % module) res["auto_install"] = True @@ -32,6 +54,7 @@ def _overload_load_information_from_description_file(module, mod_path=None): def post_load(): + _logger.info("Applying patch module_change_auto_intall") modules.module.load_information_from_description_file = ( _overload_load_information_from_description_file )