mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07: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
|
@ -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():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue