Convert some run_command() string args to lists (#8264)

* Convert some run_command() string args to lists.

* Change run_command with pipe and shell to Python code.

* Add changelog.

* Simplify syntax.

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>

---------

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
Felix Fontein 2024-04-29 22:57:08 +02:00 committed by GitHub
commit 70adba8991
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 144 additions and 144 deletions

View file

@ -170,7 +170,7 @@ def local_rpm_package_name(path):
def query_package(module, name):
# rpm -q returns 0 if the package is installed,
# 1 if it is not installed
rc, out, err = module.run_command("%s -q %s" % (RPM_PATH, name))
rc, out, err = module.run_command([RPM_PATH, "-q", name])
if rc == 0:
return True
else:
@ -203,7 +203,7 @@ def query_package_provides(module, name, allow_upgrade=False):
name = local_rpm_package_name(name)
rc, out, err = module.run_command("%s -q --provides %s" % (RPM_PATH, name))
rc, out, err = module.run_command([RPM_PATH, "-q", "--provides", name])
if rc == 0:
if not allow_upgrade:
return True
@ -253,7 +253,7 @@ def remove_packages(module, packages):
if not query_package(module, package):
continue
rc, out, err = module.run_command("%s -y remove %s" % (APT_PATH, package), environ_update={"LANG": "C"})
rc, out, err = module.run_command([APT_PATH, "-y", "remove", package], environ_update={"LANG": "C"})
if rc != 0:
module.fail_json(msg="failed to remove %s: %s" % (package, err))
@ -271,14 +271,14 @@ def install_packages(module, pkgspec, allow_upgrade=False):
if pkgspec is None:
return (False, "Empty package list")
packages = ""
packages = []
for package in pkgspec:
if not query_package_provides(module, package, allow_upgrade=allow_upgrade):
packages += "'%s' " % package
packages.append(package)
if len(packages) != 0:
rc, out, err = module.run_command("%s -y install %s" % (APT_PATH, packages), environ_update={"LANG": "C"})
if packages:
command = [APT_PATH, "-y", "install"] + packages
rc, out, err = module.run_command(command, environ_update={"LANG": "C"})
installed = True
for package in pkgspec:
@ -287,7 +287,7 @@ def install_packages(module, pkgspec, allow_upgrade=False):
# apt-rpm always have 0 for exit code if --force is used
if rc or not installed:
module.fail_json(msg="'apt-get -y install %s' failed: %s" % (packages, err))
module.fail_json(msg="'%s' failed: %s" % (" ".join(command), err))
else:
return (True, "%s present(s)" % packages)
else: