@ -6,6 +6,27 @@
# Copyright: (c) 2017 Ansible Project
# Copyright: (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# ATTENTION CONTRIBUTORS!
#
# TL;DR: Run this module's integration tests manually before opening a pull request
#
# Long explanation:
# The integration tests for this module are currently NOT run on the Ansible project's continuous
# delivery pipeline. So please: When you make changes to this module, make sure that you run the
# included integration tests manually for both Python 2 and Python 3:
#
# Python 2:
# ansible-test integration -v --docker fedora28 --docker-privileged --allow-unsupported --python 2.7 flatpak_remote
# Python 3:
# ansible-test integration -v --docker fedora28 --docker-privileged --allow-unsupported --python 3.6 flatpak_remote
#
# Because of external dependencies, the current integration tests are somewhat too slow and brittle
# to be included right now. I have plans to rewrite the integration tests based on a local flatpak
# repository so that they can be included into the normal CI pipeline.
# //oolongbrothers
from __future__ import ( absolute_import , division , print_function )
from __future__ import ( absolute_import , division , print_function )
__metaclass__ = type
__metaclass__ = type
@ -26,7 +47,7 @@ description:
- Existing remotes will not be updated .
- Existing remotes will not be updated .
- See the M ( flatpak ) module for managing flatpaks .
- See the M ( flatpak ) module for managing flatpaks .
author :
author :
- John Kwiatkoski ( @ jayk ayy)
- John Kwiatkoski ( @ JayK ayy)
- Alexander Bethke ( @oolongbrothers )
- Alexander Bethke ( @oolongbrothers )
requirements :
requirements :
- flatpak
- flatpak
@ -120,6 +141,7 @@ stdout:
import subprocess
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
def add_remote ( module , binary , name , flatpakrepo_url , method ) :
def add_remote ( module , binary , name , flatpakrepo_url , method ) :
@ -147,7 +169,7 @@ def remote_exists(module, binary, name, method):
output = _flatpak_command ( module , False , command )
output = _flatpak_command ( module , False , command )
for line in output . splitlines ( ) :
for line in output . splitlines ( ) :
listed_remote = line . split ( )
listed_remote = line . split ( )
if listed_remote [ 0 ] == name:
if listed_remote [ 0 ] == to_native( name) :
return True
return True
return False
return False
@ -168,7 +190,7 @@ def _flatpak_command(module, noop, command):
result [ ' stderr ' ] = stderr_data
result [ ' stderr ' ] = stderr_data
if result [ ' rc ' ] != 0 :
if result [ ' rc ' ] != 0 :
module . fail_json ( msg = " Failed to execute flatpak command " , * * result )
module . fail_json ( msg = " Failed to execute flatpak command " , * * result )
return stdout_data
return to_native( stdout_data)
def main ( ) :
def main ( ) :
@ -205,7 +227,7 @@ def main():
if not binary :
if not binary :
module . fail_json ( msg = " Executable ' %s ' was not found on the system. " % executable , * * result )
module . fail_json ( msg = " Executable ' %s ' was not found on the system. " % executable , * * result )
remote_already_exists = remote_exists ( module , binary , bytes ( name , ' utf-8 ' ) , method )
remote_already_exists = remote_exists ( module , binary , to_bytes ( name ) , method )
if state == ' present ' and not remote_already_exists :
if state == ' present ' and not remote_already_exists :
add_remote ( module , binary , name , flatpakrepo_url , method )
add_remote ( module , binary , name , flatpakrepo_url , method )