mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add --non-interactive argurment to Flatpak (#1246)
* Add noninteractive argument * Correct pep8 errors * Add changelog fragment * Update changelogs/fragments/1246-flatpak-use-non-interactive-argument.yaml Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Thibault GUIMBERT <tguimbert@leni.fr> Co-authored-by: Thibault Guimbert <tguimbert@localhost.localdomain> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
9ccc0464ff
commit
2be2d30f3b
2 changed files with 27 additions and 5 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- flatpak - use of the ``--non-interactive`` argument instead of ``-y`` when possible (https://github.com/ansible-collections/community.general/pull/1246).
|
|
@ -122,7 +122,7 @@ command:
|
||||||
description: The exact flatpak command that was executed
|
description: The exact flatpak command that was executed
|
||||||
returned: When a flatpak command has been executed
|
returned: When a flatpak command has been executed
|
||||||
type: str
|
type: str
|
||||||
sample: "/usr/bin/flatpak install --user -y flathub org.gnome.Calculator"
|
sample: "/usr/bin/flatpak install --user --nontinteractive flathub org.gnome.Calculator"
|
||||||
msg:
|
msg:
|
||||||
description: Module error message
|
description: Module error message
|
||||||
returned: failure
|
returned: failure
|
||||||
|
@ -145,6 +145,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"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
from distutils.version import StrictVersion
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
@ -154,10 +156,15 @@ OUTDATED_FLATPAK_VERSION_ERROR_MESSAGE = "Unknown option --columns=application"
|
||||||
def install_flat(module, binary, remote, name, method):
|
def install_flat(module, binary, remote, name, method):
|
||||||
"""Add a new flatpak."""
|
"""Add a new flatpak."""
|
||||||
global result
|
global result
|
||||||
if name.startswith('http://') or name.startswith('https://'):
|
flatpak_version = _flatpak_version(module, binary)
|
||||||
command = [binary, "install", "--{0}".format(method), "-y", name]
|
if StrictVersion(flatpak_version) < StrictVersion('1.1.3'):
|
||||||
|
noninteractive_arg = "-y"
|
||||||
else:
|
else:
|
||||||
command = [binary, "install", "--{0}".format(method), "-y", remote, name]
|
noninteractive_arg = "--noninteractive"
|
||||||
|
if name.startswith('http://') or name.startswith('https://'):
|
||||||
|
command = [binary, "install", "--{0}".format(method), noninteractive_arg, name]
|
||||||
|
else:
|
||||||
|
command = [binary, "install", "--{0}".format(method), noninteractive_arg, remote, name]
|
||||||
_flatpak_command(module, module.check_mode, command)
|
_flatpak_command(module, module.check_mode, command)
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
|
|
||||||
|
@ -165,8 +172,13 @@ def install_flat(module, binary, remote, name, method):
|
||||||
def uninstall_flat(module, binary, name, method):
|
def uninstall_flat(module, binary, name, method):
|
||||||
"""Remove an existing flatpak."""
|
"""Remove an existing flatpak."""
|
||||||
global result
|
global result
|
||||||
|
flatpak_version = _flatpak_version(module, binary)
|
||||||
|
if StrictVersion(flatpak_version) < StrictVersion('1.1.3'):
|
||||||
|
noninteractive_arg = "-y"
|
||||||
|
else:
|
||||||
|
noninteractive_arg = "--noninteractive"
|
||||||
installed_flat_name = _match_installed_flat_name(module, binary, name, method)
|
installed_flat_name = _match_installed_flat_name(module, binary, name, method)
|
||||||
command = [binary, "uninstall", "--{0}".format(method), "-y", name]
|
command = [binary, "uninstall", "--{0}".format(method), noninteractive_arg, name]
|
||||||
_flatpak_command(module, module.check_mode, command)
|
_flatpak_command(module, module.check_mode, command)
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
|
|
||||||
|
@ -236,6 +248,14 @@ def _parse_flatpak_name(name):
|
||||||
return common_name
|
return common_name
|
||||||
|
|
||||||
|
|
||||||
|
def _flatpak_version(module, binary):
|
||||||
|
global result
|
||||||
|
command = [binary, "--version"]
|
||||||
|
output = _flatpak_command(module, False, command)
|
||||||
|
version_number = output.split()[1]
|
||||||
|
return version_number
|
||||||
|
|
||||||
|
|
||||||
def _flatpak_command(module, noop, command, ignore_failure=False):
|
def _flatpak_command(module, noop, command, ignore_failure=False):
|
||||||
global result
|
global result
|
||||||
result['command'] = ' '.join(command)
|
result['command'] = ' '.join(command)
|
||||||
|
|
Loading…
Reference in a new issue