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>
pull/269/head
Jon Dufresne 2020-05-09 01:03:04 -07:00 committed by GitHub
parent 55c1ece888
commit f2af41d842
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 23 deletions

View File

@ -0,0 +1,2 @@
minor_changes:
- flatpak and flatpak_remote - use ``module.run_command()`` instead of ``subprocess.Popen()``.

View File

@ -149,10 +149,8 @@ stdout:
sample: "org.gnome.Calendar/x86_64/stable\tcurrent\norg.gnome.gitg/x86_64/stable\tcurrent\n" 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.six.moves.urllib.parse import urlparse
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
OUTDATED_FLATPAK_VERSION_ERROR_MESSAGE = "Unknown option --columns=application" 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 result['command'] = command
return "" return ""
process = subprocess.Popen( result['rc'], result['stdout'], result['stderr'] = module.run_command(
command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) command.split(), check_rc=not ignore_failure
stdout_data, stderr_data = process.communicate() )
result['rc'] = process.returncode
result['command'] = command result['command'] = command
result['stdout'] = to_native(stdout_data) return result['stdout']
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)
def main(): def main():

View File

@ -143,7 +143,6 @@ stdout:
sample: "flathub\tFlathub\thttps://dl.flathub.org/repo/\t1\t\n" sample: "flathub\tFlathub\thttps://dl.flathub.org/repo/\t1\t\n"
''' '''
import subprocess
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_bytes, to_native from ansible.module_utils._text import to_bytes, to_native
@ -187,16 +186,11 @@ def _flatpak_command(module, noop, command):
result['command'] = command result['command'] = command
return "" return ""
process = subprocess.Popen( result['rc'], result['stdout'], result['stderr'] = module.run_command(
command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) command.split(), check_rc=True
stdout_data, stderr_data = process.communicate() )
result['rc'] = process.returncode
result['command'] = command result['command'] = command
result['stdout'] = stdout_data return result['stdout']
result['stderr'] = stderr_data
if result['rc'] != 0:
module.fail_json(msg="Failed to execute flatpak command", **result)
return to_native(stdout_data)
def main(): def main():

View File

@ -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-invalid
plugins/modules/packaging/os/apt_rpm.py validate-modules:parameter-type-not-in-doc 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/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.py validate-modules:parameter-invalid
plugins/modules/packaging/os/homebrew_cask.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 plugins/modules/packaging/os/installp.py validate-modules:parameter-list-no-elements