mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
flatpak: Change use of Popen to module.run_command() (#274)
* flatpak: Change use of Popen to module.run_command() * Update changelogs/fragments/274-flatpak-run-command.yaml Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
55c1ece888
commit
f2af41d842
4 changed files with 10 additions and 23 deletions
2
changelogs/fragments/274-flatpak-run-command.yaml
Normal file
2
changelogs/fragments/274-flatpak-run-command.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- flatpak and flatpak_remote - use ``module.run_command()`` instead of ``subprocess.Popen()``.
|
|
@ -149,10 +149,8 @@ stdout:
|
|||
sample: "org.gnome.Calendar/x86_64/stable\tcurrent\norg.gnome.gitg/x86_64/stable\tcurrent\n"
|
||||
'''
|
||||
|
||||
import subprocess
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
OUTDATED_FLATPAK_VERSION_ERROR_MESSAGE = "Unknown option --columns=application"
|
||||
|
||||
|
@ -249,16 +247,11 @@ def _flatpak_command(module, noop, command, ignore_failure=False):
|
|||
result['command'] = command
|
||||
return ""
|
||||
|
||||
process = subprocess.Popen(
|
||||
command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout_data, stderr_data = process.communicate()
|
||||
result['rc'] = process.returncode
|
||||
result['rc'], result['stdout'], result['stderr'] = module.run_command(
|
||||
command.split(), check_rc=not ignore_failure
|
||||
)
|
||||
result['command'] = command
|
||||
result['stdout'] = to_native(stdout_data)
|
||||
result['stderr'] = to_native(stderr_data)
|
||||
if result['rc'] != 0 and not ignore_failure:
|
||||
module.fail_json(msg="Failed to execute flatpak command", **result)
|
||||
return to_native(stdout_data)
|
||||
return result['stdout']
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
@ -143,7 +143,6 @@ stdout:
|
|||
sample: "flathub\tFlathub\thttps://dl.flathub.org/repo/\t1\t\n"
|
||||
'''
|
||||
|
||||
import subprocess
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils._text import to_bytes, to_native
|
||||
|
||||
|
@ -187,16 +186,11 @@ def _flatpak_command(module, noop, command):
|
|||
result['command'] = command
|
||||
return ""
|
||||
|
||||
process = subprocess.Popen(
|
||||
command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout_data, stderr_data = process.communicate()
|
||||
result['rc'] = process.returncode
|
||||
result['rc'], result['stdout'], result['stderr'] = module.run_command(
|
||||
command.split(), check_rc=True
|
||||
)
|
||||
result['command'] = command
|
||||
result['stdout'] = stdout_data
|
||||
result['stderr'] = stderr_data
|
||||
if result['rc'] != 0:
|
||||
module.fail_json(msg="Failed to execute flatpak command", **result)
|
||||
return to_native(stdout_data)
|
||||
return result['stdout']
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
@ -1254,8 +1254,6 @@ plugins/modules/packaging/os/apt_rpm.py validate-modules:doc-default-does-not-ma
|
|||
plugins/modules/packaging/os/apt_rpm.py validate-modules:parameter-invalid
|
||||
plugins/modules/packaging/os/apt_rpm.py validate-modules:parameter-type-not-in-doc
|
||||
plugins/modules/packaging/os/apt_rpm.py validate-modules:undocumented-parameter
|
||||
plugins/modules/packaging/os/flatpak.py validate-modules:use-run-command-not-popen
|
||||
plugins/modules/packaging/os/flatpak_remote.py validate-modules:use-run-command-not-popen
|
||||
plugins/modules/packaging/os/homebrew.py validate-modules:parameter-invalid
|
||||
plugins/modules/packaging/os/homebrew_cask.py validate-modules:parameter-invalid
|
||||
plugins/modules/packaging/os/installp.py validate-modules:parameter-list-no-elements
|
||||
|
|
Loading…
Reference in a new issue