mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-11 08:34:21 -07:00
urpmi: command args as list rather than string (#10606)
* urpmi: command args as list rather than string * add changelog frag
This commit is contained in:
parent
9fc5d2ec4d
commit
83ce53136c
2 changed files with 13 additions and 14 deletions
2
changelogs/fragments/10606-urpmi-cmd-list.yml
Normal file
2
changelogs/fragments/10606-urpmi-cmd-list.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- urpmi - using safer mechanism to run external command (https://github.com/ansible-collections/community.general/pull/10606).
|
|
@ -93,7 +93,7 @@ def query_package(module, name, root):
|
|||
# rpm -q returns 0 if the package is installed,
|
||||
# 1 if it is not installed
|
||||
rpm_path = module.get_bin_path("rpm", True)
|
||||
cmd = "%s -q %s %s" % (rpm_path, name, root_option(root))
|
||||
cmd = [rpm_path, "-q", name] + root_option(root)
|
||||
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||
if rc == 0:
|
||||
return True
|
||||
|
@ -105,7 +105,7 @@ def query_package_provides(module, name, root):
|
|||
# rpm -q returns 0 if the package is installed,
|
||||
# 1 if it is not installed
|
||||
rpm_path = module.get_bin_path("rpm", True)
|
||||
cmd = "%s -q --whatprovides %s %s" % (rpm_path, name, root_option(root))
|
||||
cmd = [rpm_path, "-q", "--whatprovides", name] + root_option(root)
|
||||
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||
return rc == 0
|
||||
|
||||
|
@ -113,7 +113,7 @@ def query_package_provides(module, name, root):
|
|||
def update_package_db(module):
|
||||
|
||||
urpmiupdate_path = module.get_bin_path("urpmi.update", True)
|
||||
cmd = "%s -a -q" % (urpmiupdate_path,)
|
||||
cmd = [urpmiupdate_path, "-a", "-q"]
|
||||
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||
if rc != 0:
|
||||
module.fail_json(msg="could not update package db")
|
||||
|
@ -129,7 +129,7 @@ def remove_packages(module, packages, root):
|
|||
continue
|
||||
|
||||
urpme_path = module.get_bin_path("urpme", True)
|
||||
cmd = "%s --auto %s %s" % (urpme_path, root_option(root), package)
|
||||
cmd = [urpme_path, "--auto"] + root_option(root) + [package]
|
||||
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||
|
||||
if rc != 0:
|
||||
|
@ -153,20 +153,17 @@ def install_packages(module, pkgspec, root, force=True, no_recommends=True):
|
|||
|
||||
if len(packages) != 0:
|
||||
if no_recommends:
|
||||
no_recommends_yes = '--no-recommends'
|
||||
no_recommends_yes = ['--no-recommends']
|
||||
else:
|
||||
no_recommends_yes = ''
|
||||
no_recommends_yes = []
|
||||
|
||||
if force:
|
||||
force_yes = '--force'
|
||||
force_yes = ['--force']
|
||||
else:
|
||||
force_yes = ''
|
||||
force_yes = []
|
||||
|
||||
urpmi_path = module.get_bin_path("urpmi", True)
|
||||
cmd = ("%s --auto %s --quiet %s %s %s" % (urpmi_path, force_yes,
|
||||
no_recommends_yes,
|
||||
root_option(root),
|
||||
packages))
|
||||
cmd = [urpmi_path, "--auto"] + force_yes + ["--quiet"] + no_recommends_yes + root_option(root) + packages
|
||||
|
||||
rc, out, err = module.run_command(cmd)
|
||||
|
||||
|
@ -185,9 +182,9 @@ def install_packages(module, pkgspec, root, force=True, no_recommends=True):
|
|||
|
||||
def root_option(root):
|
||||
if root:
|
||||
return "--root=%s" % (root)
|
||||
return ["--root=%s" % (root)]
|
||||
else:
|
||||
return ""
|
||||
return []
|
||||
|
||||
|
||||
def main():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue