From ddeb1684e8f1c898c227a4a517fee06041acac76 Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Wed, 20 Nov 2024 11:22:13 +0100 Subject: [PATCH] Fixes #25908: Allow passing env vars to package managers --- tree/10_ncf_internals/modules/packages/apt_get | 12 ++++++++++-- tree/10_ncf_internals/modules/packages/yum | 14 ++++++++++++++ tree/10_ncf_internals/modules/packages/zypper | 14 ++++++++++++++ .../modules/packages/zypper_pattern | 16 ++++++++++++++-- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/tree/10_ncf_internals/modules/packages/apt_get b/tree/10_ncf_internals/modules/packages/apt_get index 92b3fcfe..c4b47cfc 100755 --- a/tree/10_ncf_internals/modules/packages/apt_get +++ b/tree/10_ncf_internals/modules/packages/apt_get @@ -308,9 +308,17 @@ def package_arguments_builder(is_apt_install): elif line.startswith("options="): global apt_get_options - option = line.split("=", 1)[1].rstrip() + option = line.split("=", 1)[1].rstrip() if option: - apt_get_options.append(option) + if option.startswith("env:"): + env_option = option.split(":", 1)[1] + env_var = env_option.split("=", 1) + if len(env_var) == 2: + name = env_var[0] + value = env_var[1] + os.environ[name] = value + else: + apt_get_options.append(option) if name: args.extend(one_package_argument(name, arch, version, is_apt_install)) diff --git a/tree/10_ncf_internals/modules/packages/yum b/tree/10_ncf_internals/modules/packages/yum index b4e26e80..c5a6f88a 100755 --- a/tree/10_ncf_internals/modules/packages/yum +++ b/tree/10_ncf_internals/modules/packages/yum @@ -123,6 +123,13 @@ def list_updates(online): yum_options.append(option) elif option.startswith("enablerepo=") or option.startswith("disablerepo="): yum_options.append("--" + option) + elif option.startswith("env:"): + env_option = option.split(":", 1)[1] + env_var = env_option.split("=", 1) + if len(env_var) == 2: + name = env_var[0] + value = env_var[1] + os.environ[name] = value online_flag = [] if not online: @@ -237,6 +244,13 @@ def package_arguments_builder(is_yum_install): yum_options.append(option) elif option.startswith("enablerepo=") or option.startswith("disablerepo="): yum_options.append("--" + option) + elif option.startswith("env:"): + env_option = option.split(":", 1)[1] + env_var = env_option.split("=", 1) + if len(env_var) == 2: + name = env_var[0] + value = env_var[1] + os.environ[name] = value if line.startswith("Name="): if name: # Each new "Name=" triggers a new entry. diff --git a/tree/10_ncf_internals/modules/packages/zypper b/tree/10_ncf_internals/modules/packages/zypper index 47d36369..96d3756b 100755 --- a/tree/10_ncf_internals/modules/packages/zypper +++ b/tree/10_ncf_internals/modules/packages/zypper @@ -283,6 +283,20 @@ def package_arguments_builder(is_zypper_install): elif line.startswith("Architecture="): arch = line.split("=", 1)[1].rstrip() + elif line.startswith("options="): + global zypper_options + option = line.split("=", 1)[1].rstrip() + if option: + if option.startswith("env:"): + env_option = option.split(":", 1)[1] + env_var = env_option.split("=", 1) + if len(env_var) == 2: + name = env_var[0] + value = env_var[1] + os.environ[name] = value + else: + zypper_options.append(option) + if name: single_list, multi_list = one_package_argument(name, arch, version, is_zypper_install) single_cmd_args += single_list diff --git a/tree/10_ncf_internals/modules/packages/zypper_pattern b/tree/10_ncf_internals/modules/packages/zypper_pattern index 8ecfca96..afdf389a 100755 --- a/tree/10_ncf_internals/modules/packages/zypper_pattern +++ b/tree/10_ncf_internals/modules/packages/zypper_pattern @@ -264,8 +264,20 @@ def construct_complete_package_names(): version = "=" + line.split("=", 1)[1].rstrip() if (flag == 'Architecture'): architecture = "." + line.split("=", 1)[1].rstrip() - if (flag == 'Options'): - pass + if (flag == 'options'): + global zypper_options + option = line.split("=", 1)[1].rstrip() + if option: + if option.startswith("env:"): + env_option = option.split(":", 1)[1] + env_var = env_option.split("=", 1) + if len(env_var) == 2: + name = env_var[0] + value = env_var[1] + os.environ[name] = value + else: + zypper_options.append(option) + complete_names.append(pattern + architecture + version) return complete_names