From f006cc63dfc594f9f8575a4f0f7c1235d85d54a5 Mon Sep 17 00:00:00 2001 From: Steven Oliver Date: Tue, 5 Mar 2019 20:49:00 -0500 Subject: [PATCH 01/13] Add flatpak --- doc/ref/modules/all/index.rst | 1 + doc/ref/modules/all/salt.modules.flatpak.rst | 6 + doc/ref/states/all/index.rst | 1 + doc/ref/states/all/salt.modules.flatpak.rst | 6 + salt/modules/flatpak.py | 112 +++++++++++++++ salt/states/flatpak.py | 140 +++++++++++++++++++ 6 files changed, 266 insertions(+) create mode 100644 doc/ref/modules/all/salt.modules.flatpak.rst create mode 100644 doc/ref/states/all/salt.modules.flatpak.rst create mode 100644 salt/modules/flatpak.py create mode 100644 salt/states/flatpak.py diff --git a/doc/ref/modules/all/index.rst b/doc/ref/modules/all/index.rst index 58779683fd9a..1c96d691593b 100644 --- a/doc/ref/modules/all/index.rst +++ b/doc/ref/modules/all/index.rst @@ -139,6 +139,7 @@ execution modules extfs file firewalld + flatpak freebsd_sysctl freebsd_update freebsdjail diff --git a/doc/ref/modules/all/salt.modules.flatpak.rst b/doc/ref/modules/all/salt.modules.flatpak.rst new file mode 100644 index 000000000000..7924b497dd61 --- /dev/null +++ b/doc/ref/modules/all/salt.modules.flatpak.rst @@ -0,0 +1,6 @@ +================= +salt.modules.flatpak +================= + +.. automodule:: salt.modules.flatpak + :members: diff --git a/doc/ref/states/all/index.rst b/doc/ref/states/all/index.rst index 523a70785ee1..764d9bd5a161 100644 --- a/doc/ref/states/all/index.rst +++ b/doc/ref/states/all/index.rst @@ -95,6 +95,7 @@ state modules file firewall firewalld + flatpak gem git github diff --git a/doc/ref/states/all/salt.modules.flatpak.rst b/doc/ref/states/all/salt.modules.flatpak.rst new file mode 100644 index 000000000000..2851fd3a08b1 --- /dev/null +++ b/doc/ref/states/all/salt.modules.flatpak.rst @@ -0,0 +1,6 @@ +================ +salt.states.flatpak +================ + +.. automodule:: salt.states.flatpak + :members: diff --git a/salt/modules/flatpak.py b/salt/modules/flatpak.py new file mode 100644 index 000000000000..ddee0b90332c --- /dev/null +++ b/salt/modules/flatpak.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- +''' +Manage flatpak packages via Salt + +.. versionadded:: Neon + +:depends: flatpak for distribution +''' + +from __future__ import absolute_import, print_function, unicode_literals +import subprocess + +import salt.utils.path + +FLATPAK_BINARY_NAME = 'flatpak' + +log = logging.getLogger(__name__) + +__virtualname__ = 'flatpak' + + +def __virtual__(): + if salt.utils.path.which('flatpak'): + return __virtualname__ + + return (False, 'The flatpak execution module cannot be loaded: the "flatpak" binary is not in the path.') + + +def install(location, pkg): + ''' + Install the specified flatpak package from the specified location. + Returns a dictionary of "result" and "output". + location + The location or remote to install the flatpak from. + pkg + The flatpak package name + ''' + ret = {'result': None, 'output': ""} + + try: + # Try to run it, merging stderr into output + ret['output'] = subprocess.check_output([FLATPAK_BINARY_NAME, 'install', location, pkg], stderr=subprocess.STDOUT) + ret['result'] = True + except subprocess.CalledProcessError as e: + ret['output'] = e.output + ret['result'] = False + + return ret + + +def is_installed(pkg): + ''' + Returns True if there is any version of the specified package installed. + pkg + The package name + ''' + try: + output = subprocess.check_output([FLATPAK_BINARY_NAME, 'info', pkg], stderr=subprocess.STDOUT) + except subprocess.CalledProcessError: + return False + + return True + + +def uninstall(pkg): + ''' + Uninstall the specified package. Returns a dictionary of "result" and "output". + pkg + The package name + ''' + ret = {'result': None, 'output': ""} + try: + ret['output'] = subprocess.check_output([FLATPAK_BINARY_NAME, 'uninstall', pkg]) + ret['result'] = True + except subprocess.CalledProcessError as e: + ret['output'] = e.output + ret['result'] = False + + +def add_remote(name, location): + ''' + Add a new location to install flatpak packages from. + name + The repositories name + location + The location of the repository + ''' + ret = {'result': None, 'output': ""} + try: + ret['output'] = subprocess.check_output([FLATPAK_BINARY_NAME, 'remote-add', name, location]) + ret['result'] = True + except subprocess.CalledProcessError as e: + ret['output'] = e.output + ret['result'] = False + +def is_remote_added(remote): + ''' + Returns True if the remote has already been added. + remote + The remote's name + ''' + try: + output = subprocess.check_output([FLATPAK_BINARY_NAME, 'remotes'], stderr=subprocess.STDOUT) + except subprocess.CalledProcessError: + return [] + + lines = output.splitlines()[1:] + for item in lines: + i = item.split() + if i[0] == remote: + return True + return False diff --git a/salt/states/flatpak.py b/salt/states/flatpak.py new file mode 100644 index 000000000000..6899f7b1ca8d --- /dev/null +++ b/salt/states/flatpak.py @@ -0,0 +1,140 @@ +# -*- coding: utf-8 -*- +''' +Management of flatpak packages +============================== +Allows the installation and uninstallation of flatpak packages. + +.. versionadded:: Neon +''' +from __future__ import absolute_import, print_function, unicode_literals +import salt.utils.path + +__virtualname__ = 'flatpak' + + +def __virtual__(): + if salt.utils.path.which('flatpak'): + return __virtualname__ + + return (False, 'The flatpak state module cannot be loaded: the "flatpak" binary is not in the path.') + + +def installed(location, name): + ''' + Ensure that the named package is installed + location + The location or remote to install the flatpak from. + name + The flatpak package + ''' + ret = {'name': name, + 'changes': {}, + 'pchanges': {}, + 'result': None, + 'comment': ''} + + old = __salt__['flatpak.is_installed'](name) + if not old: + if __opts__['test']: + ret['comment'] = 'Package "{0}" would have been installed'.format(name) + ret['pchanges']['new'] = name + ret['pchanges']['old'] = None + ret['result'] = None + return ret + + install = __salt__['flatpak.install'](name, location) + if install['result']: + ret['comment'] = 'Package "{0}" was installed'.format(name) + ret['changes']['new'] = name + ret['changes']['old'] = None + ret['result'] = True + return ret + + ret['comment'] = 'Package "{0}" failed to install'.format(name) + ret['comment'] += '\noutput:\n' + install['output'] + ret['result'] = False + return ret + + ret['comment'] = 'Package "{0}" is already installed'.format(name) + if __opts__['test']: + ret['result'] = None + return ret + + ret['result'] = True + return ret + +def uninstalled(name): + ''' + Ensure that the named package is not installed + name + The flatpak package + ''' + ret = {'name': name, + 'changes': {}, + 'pchanges': {}, + 'result': None, + 'comment': ''} + + old = __salt__['flatpak.is_installed'](name) + if not old: + ret['comment'] = 'Package {0} is not installed'.format(name) + ret['result'] = True + return ret + + if __opts__['test']: + ret['comment'] = 'Package {0} would have been uninstalled'.format(name) + ret['result'] = None + ret['pchanges']['old'] = old[0]['version'] + ret['pchanges']['new'] = None + return ret + + uninstall = __salt__['flatpak.uninstall'](name) + ret['comment'] = 'Package {0} uninstalled'.format(name) + ret['result'] = True + ret['changes']['old'] = old[0]['version'] + ret['changes']['new'] = None + return ret + +def add_remote(name, location): + ''' + Add a new location to install flatpak packages from. + name + The repositories name + location + The location of the repository + ''' + ret = {'name': name, + 'changes': {}, + 'pchanges': {}, + 'result': None, + 'comment': ''} + + old = __salt__['flatpak.is_remote_added'](name) + if not old: + if __opts__['test']: + ret['comment'] = 'Remote "{0}" would have been added'.format(name) + ret['pchanges']['new'] = name + ret['pchanges']['old'] = None + ret['result'] = None + return ret + + install = __salt__['flatpak.add_remote'](name) + if install['result']: + ret['comment'] = 'Remote "{0}" was added'.format(name) + ret['changes']['new'] = name + ret['changes']['old'] = None + ret['result'] = True + return ret + + ret['comment'] = 'Failed to add remote "{0}"'.format(name) + ret['comment'] += '\noutput:\n' + install['output'] + ret['result'] = False + return ret + + ret['comment'] = 'Remote "{0}" already exists'.format(name) + if __opts__['test']: + ret['result'] = None + return ret + + ret['result'] = True + return ret From 359160585035371cf5457568794d87e7f9968b82 Mon Sep 17 00:00:00 2001 From: Steven Oliver Date: Tue, 5 Mar 2019 21:32:50 -0500 Subject: [PATCH 02/13] Correct issues with flatpak installs * Install now installs packages and runtimes * Correct error in how is_installed parsed output --- salt/modules/flatpak.py | 30 ++++++++++++++---------------- salt/states/flatpak.py | 3 ++- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/salt/modules/flatpak.py b/salt/modules/flatpak.py index ddee0b90332c..3e9542b4733d 100644 --- a/salt/modules/flatpak.py +++ b/salt/modules/flatpak.py @@ -9,13 +9,12 @@ from __future__ import absolute_import, print_function, unicode_literals import subprocess +import re import salt.utils.path FLATPAK_BINARY_NAME = 'flatpak' -log = logging.getLogger(__name__) - __virtualname__ = 'flatpak' @@ -26,20 +25,19 @@ def __virtual__(): return (False, 'The flatpak execution module cannot be loaded: the "flatpak" binary is not in the path.') -def install(location, pkg): +def install(location, name): ''' - Install the specified flatpak package from the specified location. + Install the specified flatpak package or runtime from the specified location. Returns a dictionary of "result" and "output". location - The location or remote to install the flatpak from. - pkg - The flatpak package name + The location or remote to install from. + name + The name of the package or runtime ''' ret = {'result': None, 'output': ""} try: - # Try to run it, merging stderr into output - ret['output'] = subprocess.check_output([FLATPAK_BINARY_NAME, 'install', location, pkg], stderr=subprocess.STDOUT) + ret['output'] = subprocess.check_output([FLATPAK_BINARY_NAME, 'install', location, name], stderr=subprocess.STDOUT) ret['result'] = True except subprocess.CalledProcessError as e: ret['output'] = e.output @@ -48,14 +46,14 @@ def install(location, pkg): return ret -def is_installed(pkg): +def is_installed(name): ''' - Returns True if there is any version of the specified package installed. - pkg - The package name + Returns True if the specified package or runtime is installed. + name + The name of the package or the runtime ''' try: - output = subprocess.check_output([FLATPAK_BINARY_NAME, 'info', pkg], stderr=subprocess.STDOUT) + output = subprocess.check_output([FLATPAK_BINARY_NAME, 'info', name], stderr=subprocess.STDOUT) except subprocess.CalledProcessError: return False @@ -104,9 +102,9 @@ def is_remote_added(remote): except subprocess.CalledProcessError: return [] - lines = output.splitlines()[1:] + lines = output.splitlines() for item in lines: - i = item.split() + i = re.split(r'\t+', item.rstrip('\t')) if i[0] == remote: return True return False diff --git a/salt/states/flatpak.py b/salt/states/flatpak.py index 6899f7b1ca8d..79dd56fe831b 100644 --- a/salt/states/flatpak.py +++ b/salt/states/flatpak.py @@ -7,6 +7,7 @@ .. versionadded:: Neon ''' from __future__ import absolute_import, print_function, unicode_literals + import salt.utils.path __virtualname__ = 'flatpak' @@ -25,7 +26,7 @@ def installed(location, name): location The location or remote to install the flatpak from. name - The flatpak package + The name of the package or runtime ''' ret = {'name': name, 'changes': {}, From 2dc038b0e0c566d916d343613ebc3a24b09f4ba8 Mon Sep 17 00:00:00 2001 From: Steven Oliver Date: Wed, 6 Mar 2019 19:48:18 -0500 Subject: [PATCH 03/13] Correct lint issues --- salt/modules/flatpak.py | 1 + salt/states/flatpak.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/salt/modules/flatpak.py b/salt/modules/flatpak.py index 3e9542b4733d..194c6fbbdbb1 100644 --- a/salt/modules/flatpak.py +++ b/salt/modules/flatpak.py @@ -91,6 +91,7 @@ def add_remote(name, location): ret['output'] = e.output ret['result'] = False + def is_remote_added(remote): ''' Returns True if the remote has already been added. diff --git a/salt/states/flatpak.py b/salt/states/flatpak.py index 79dd56fe831b..c0a19bf3bd7d 100644 --- a/salt/states/flatpak.py +++ b/salt/states/flatpak.py @@ -64,6 +64,7 @@ def installed(location, name): ret['result'] = True return ret + def uninstalled(name): ''' Ensure that the named package is not installed @@ -96,6 +97,7 @@ def uninstalled(name): ret['changes']['new'] = None return ret + def add_remote(name, location): ''' Add a new location to install flatpak packages from. From d4187dd7dbbe2cf77593a2ca2459e7338c0ee748 Mon Sep 17 00:00:00 2001 From: Steven Oliver Date: Sun, 24 Mar 2019 19:13:32 -0400 Subject: [PATCH 04/13] Fix docstrings. Use salt cmd.run instead of subprocess. --- salt/modules/flatpak.py | 158 +++++++++++++++++++++++++--------------- salt/states/flatpak.py | 97 ++++++++++++------------ 2 files changed, 150 insertions(+), 105 deletions(-) diff --git a/salt/modules/flatpak.py b/salt/modules/flatpak.py index 194c6fbbdbb1..c0b7cac8491d 100644 --- a/salt/modules/flatpak.py +++ b/salt/modules/flatpak.py @@ -1,11 +1,11 @@ # -*- coding: utf-8 -*- -''' +""" Manage flatpak packages via Salt .. versionadded:: Neon :depends: flatpak for distribution -''' +""" from __future__ import absolute_import, print_function, unicode_literals import subprocess @@ -22,88 +22,128 @@ def __virtual__(): if salt.utils.path.which('flatpak'): return __virtualname__ - return (False, 'The flatpak execution module cannot be loaded: the "flatpak" binary is not in the path.') + return False, 'The flatpak execution module cannot be loaded: the "flatpak" binary is not in the path.' def install(location, name): - ''' - Install the specified flatpak package or runtime from the specified location. - Returns a dictionary of "result" and "output". - location - The location or remote to install from. - name - The name of the package or runtime - ''' + """Install the specified flatpak package or runtime from the specified location. + + Args: + location (str): The location or remote to install from. + name (str): The name of the package or runtime. + + Returns: + dict: The "result" and "output". + + CLI Example: + .. code-block:: bash + salt '*' flatpak.install flathub org.gimp.GIMP + """ ret = {'result': None, 'output': ""} - try: - ret['output'] = subprocess.check_output([FLATPAK_BINARY_NAME, 'install', location, name], stderr=subprocess.STDOUT) - ret['result'] = True - except subprocess.CalledProcessError as e: - ret['output'] = e.output + out = __salt__['cmd.run_all'](FLATPAK_BINARY_NAME + ' install ' + location + ' ' + name) + + if out['retcode'] and out['stderr']: + ret['stderr'] = out['stderr'].strip() ret['result'] = False + else: + ret['stdout'] = out['stdout'].strip() + ret['result'] = True return ret def is_installed(name): - ''' - Returns True if the specified package or runtime is installed. - name - The name of the package or the runtime - ''' - try: - output = subprocess.check_output([FLATPAK_BINARY_NAME, 'info', name], stderr=subprocess.STDOUT) - except subprocess.CalledProcessError: - return False + """Determine if a package or runtime is installed. + + Args: + name (str): The name of the package or the runtime. - return True + Returns: + bool: True if the specified package or runtime is installed. + + CLI Example: + .. code-block:: bash + salt '*' flatpak.is_installed org.gimp.GIMP + """ + out = __salt__['cmd.run_all'](FLATPAK_BINARY_NAME + ' info ' + name) + + if out['retcode'] and out['stderr']: + return False + else: + return True def uninstall(pkg): - ''' - Uninstall the specified package. Returns a dictionary of "result" and "output". - pkg - The package name - ''' + """Uninstall the specified package. + + Args: + pkg (str): The package name. + + Returns: + dict: The "result" and "output". + + CLI Example: + .. code-block:: bash + salt '*' flatpak.uninstall org.gimp.GIMP + """ ret = {'result': None, 'output': ""} - try: - ret['output'] = subprocess.check_output([FLATPAK_BINARY_NAME, 'uninstall', pkg]) - ret['result'] = True - except subprocess.CalledProcessError as e: - ret['output'] = e.output + + out = __salt__['cmd.run_all'](FLATPAK_BINARY_NAME + ' uninstall ' + pkg) + + if out['retcode'] and out['stderr']: + ret['stderr'] = out['stderr'].strip() ret['result'] = False + else: + ret['stdout'] = out['stdout'].strip() + ret['result'] = True + + return ret def add_remote(name, location): - ''' - Add a new location to install flatpak packages from. - name - The repositories name - location - The location of the repository - ''' + """Add a new location to install flatpak packages from. + + Args: + name (str): The repositories name. + location (str): The location of the repository. + + Returns: + dict: The "result" and "output". + + CLI Example: + .. code-block:: bash + salt '*' flatpak.add_remote flathub https://flathub.org/repo/flathub.flatpakrepo + """ ret = {'result': None, 'output': ""} - try: - ret['output'] = subprocess.check_output([FLATPAK_BINARY_NAME, 'remote-add', name, location]) - ret['result'] = True - except subprocess.CalledProcessError as e: - ret['output'] = e.output + out = __salt__['cmd.run_all'](FLATPAK_BINARY_NAME + ' remote-add ' + name + ' ' + location) + + if out['retcode'] and out['stderr']: + ret['stderr'] = out['stderr'].strip() ret['result'] = False + else: + ret['stdout'] = out['stdout'].strip() + ret['result'] = True + + return ret def is_remote_added(remote): - ''' - Returns True if the remote has already been added. - remote - The remote's name - ''' - try: - output = subprocess.check_output([FLATPAK_BINARY_NAME, 'remotes'], stderr=subprocess.STDOUT) - except subprocess.CalledProcessError: - return [] - - lines = output.splitlines() + """Determines if a remote exists. + + Args: + remote (str): The remote's name. + + Returns: + bool: True if the remote has already been added. + + CLI Example: + .. code-block:: bash + salt '*' flatpak.is_remote_added flathub + """ + out = __salt__['cmd.run_all'](FLATPAK_BINARY_NAME + ' remotes') + + lines = out.splitlines() for item in lines: i = re.split(r'\t+', item.rstrip('\t')) if i[0] == remote: diff --git a/salt/states/flatpak.py b/salt/states/flatpak.py index c0a19bf3bd7d..04541b8b9959 100644 --- a/salt/states/flatpak.py +++ b/salt/states/flatpak.py @@ -1,11 +1,11 @@ # -*- coding: utf-8 -*- -''' +""" Management of flatpak packages ============================== Allows the installation and uninstallation of flatpak packages. .. versionadded:: Neon -''' +""" from __future__ import absolute_import, print_function, unicode_literals import salt.utils.path @@ -17,20 +17,21 @@ def __virtual__(): if salt.utils.path.which('flatpak'): return __virtualname__ - return (False, 'The flatpak state module cannot be loaded: the "flatpak" binary is not in the path.') + return False, 'The flatpak state module cannot be loaded: the "flatpak" binary is not in the path.' def installed(location, name): - ''' - Ensure that the named package is installed - location - The location or remote to install the flatpak from. - name - The name of the package or runtime - ''' + """Ensure that the named package is installed. + + Args: + location (str): The location or remote to install the flatpak from. + name (str): The name of the package or runtime. + + Returns: + dict: The "result" and "output". + """ ret = {'name': name, 'changes': {}, - 'pchanges': {}, 'result': None, 'comment': ''} @@ -38,13 +39,13 @@ def installed(location, name): if not old: if __opts__['test']: ret['comment'] = 'Package "{0}" would have been installed'.format(name) - ret['pchanges']['new'] = name - ret['pchanges']['old'] = None + ret['changes']['new'] = name + ret['changes']['old'] = None ret['result'] = None return ret - install = __salt__['flatpak.install'](name, location) - if install['result']: + __salt__['flatpak.install'](name, location) + if __salt__['flatpak.is_installed'](name): ret['comment'] = 'Package "{0}" was installed'.format(name) ret['changes']['new'] = name ret['changes']['old'] = None @@ -66,14 +67,16 @@ def installed(location, name): def uninstalled(name): - ''' - Ensure that the named package is not installed - name - The flatpak package - ''' + """Ensure that the named package is not installed. + + Args: + name (str): The flatpak package. + + Returns: + dict: The "result" and "output". + """ ret = {'name': name, 'changes': {}, - 'pchanges': {}, 'result': None, 'comment': ''} @@ -82,33 +85,35 @@ def uninstalled(name): ret['comment'] = 'Package {0} is not installed'.format(name) ret['result'] = True return ret + else + if __opts__['test']: + ret['comment'] = 'Package {0} would have been uninstalled'.format(name) + ret['changes']['old'] = old[0]['version'] + ret['changes']['new'] = None + ret['result'] = None + return ret - if __opts__['test']: - ret['comment'] = 'Package {0} would have been uninstalled'.format(name) - ret['result'] = None - ret['pchanges']['old'] = old[0]['version'] - ret['pchanges']['new'] = None - return ret - - uninstall = __salt__['flatpak.uninstall'](name) - ret['comment'] = 'Package {0} uninstalled'.format(name) - ret['result'] = True - ret['changes']['old'] = old[0]['version'] - ret['changes']['new'] = None - return ret + __salt__['flatpak.uninstall'](name) + if not __salt__['flatpak.is_installed'](name): + ret['comment'] = 'Package {0} uninstalled'.format(name) + ret['changes']['old'] = old[0]['version'] + ret['changes']['new'] = None + ret['result'] = True + return ret def add_remote(name, location): - ''' - Add a new location to install flatpak packages from. - name - The repositories name - location - The location of the repository - ''' + """Add a new location to install flatpak packages from. + + Args: + name (str): The repositories name. + location (str): The location of the repository. + + Returns: + dict: The "result" and "output". + """ ret = {'name': name, 'changes': {}, - 'pchanges': {}, 'result': None, 'comment': ''} @@ -116,13 +121,13 @@ def add_remote(name, location): if not old: if __opts__['test']: ret['comment'] = 'Remote "{0}" would have been added'.format(name) - ret['pchanges']['new'] = name - ret['pchanges']['old'] = None + ret['changes']['new'] = name + ret['changes']['old'] = None ret['result'] = None return ret - install = __salt__['flatpak.add_remote'](name) - if install['result']: + __salt__['flatpak.add_remote'](name) + if __salt__['flatpak.is_remote_added'](name): ret['comment'] = 'Remote "{0}" was added'.format(name) ret['changes']['new'] = name ret['changes']['old'] = None From 8faa3f94032a8412574fbefb4a032f4f1a8fd1e0 Mon Sep 17 00:00:00 2001 From: Steven Oliver Date: Mon, 25 Mar 2019 13:37:00 -0400 Subject: [PATCH 05/13] Add missing colon --- salt/states/flatpak.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/states/flatpak.py b/salt/states/flatpak.py index 04541b8b9959..7f92b4790d92 100644 --- a/salt/states/flatpak.py +++ b/salt/states/flatpak.py @@ -85,7 +85,7 @@ def uninstalled(name): ret['comment'] = 'Package {0} is not installed'.format(name) ret['result'] = True return ret - else + else: if __opts__['test']: ret['comment'] = 'Package {0} would have been uninstalled'.format(name) ret['changes']['old'] = old[0]['version'] From 9a56a976181b1449143869417b81e917e2afa9ec Mon Sep 17 00:00:00 2001 From: Steven Oliver Date: Thu, 28 Mar 2019 16:41:41 -0400 Subject: [PATCH 06/13] Adjust docstrings --- salt/modules/flatpak.py | 51 ++++++++++++++++++++++------------------- salt/states/flatpak.py | 48 +++++++++++++++++++++++++++++--------- 2 files changed, 65 insertions(+), 34 deletions(-) diff --git a/salt/modules/flatpak.py b/salt/modules/flatpak.py index c0b7cac8491d..dc9145eb0878 100644 --- a/salt/modules/flatpak.py +++ b/salt/modules/flatpak.py @@ -1,11 +1,11 @@ # -*- coding: utf-8 -*- -""" +''' Manage flatpak packages via Salt .. versionadded:: Neon :depends: flatpak for distribution -""" +''' from __future__ import absolute_import, print_function, unicode_literals import subprocess @@ -26,20 +26,21 @@ def __virtual__(): def install(location, name): - """Install the specified flatpak package or runtime from the specified location. + ''' + Install the specified flatpak package or runtime from the specified location. Args: location (str): The location or remote to install from. name (str): The name of the package or runtime. Returns: - dict: The "result" and "output". + dict: The ``result`` and ``output``. CLI Example: - .. code-block:: bash + .. code-block:: bash salt '*' flatpak.install flathub org.gimp.GIMP - """ - ret = {'result': None, 'output': ""} + ''' + ret = {'result': None, 'output': ''} out = __salt__['cmd.run_all'](FLATPAK_BINARY_NAME + ' install ' + location + ' ' + name) @@ -54,7 +55,8 @@ def install(location, name): def is_installed(name): - """Determine if a package or runtime is installed. + ''' + Determine if a package or runtime is installed. Args: name (str): The name of the package or the runtime. @@ -63,9 +65,9 @@ def is_installed(name): bool: True if the specified package or runtime is installed. CLI Example: - .. code-block:: bash + .. code-block:: bash salt '*' flatpak.is_installed org.gimp.GIMP - """ + ''' out = __salt__['cmd.run_all'](FLATPAK_BINARY_NAME + ' info ' + name) if out['retcode'] and out['stderr']: @@ -75,19 +77,20 @@ def is_installed(name): def uninstall(pkg): - """Uninstall the specified package. + ''' + Uninstall the specified package. Args: pkg (str): The package name. Returns: - dict: The "result" and "output". + dict: The ``result`` and ``output``. CLI Example: - .. code-block:: bash + .. code-block:: bash salt '*' flatpak.uninstall org.gimp.GIMP - """ - ret = {'result': None, 'output': ""} + ''' + ret = {'result': None, 'output': ''} out = __salt__['cmd.run_all'](FLATPAK_BINARY_NAME + ' uninstall ' + pkg) @@ -102,20 +105,21 @@ def uninstall(pkg): def add_remote(name, location): - """Add a new location to install flatpak packages from. + ''' + Add a new location to install flatpak packages from. Args: name (str): The repositories name. location (str): The location of the repository. Returns: - dict: The "result" and "output". + dict: The ``result`` and ``output``. CLI Example: - .. code-block:: bash + .. code-block:: bash salt '*' flatpak.add_remote flathub https://flathub.org/repo/flathub.flatpakrepo - """ - ret = {'result': None, 'output': ""} + ''' + ret = {'result': None, 'output': ''} out = __salt__['cmd.run_all'](FLATPAK_BINARY_NAME + ' remote-add ' + name + ' ' + location) if out['retcode'] and out['stderr']: @@ -129,7 +133,8 @@ def add_remote(name, location): def is_remote_added(remote): - """Determines if a remote exists. + ''' + Determines if a remote exists. Args: remote (str): The remote's name. @@ -138,9 +143,9 @@ def is_remote_added(remote): bool: True if the remote has already been added. CLI Example: - .. code-block:: bash + .. code-block:: bash salt '*' flatpak.is_remote_added flathub - """ + ''' out = __salt__['cmd.run_all'](FLATPAK_BINARY_NAME + ' remotes') lines = out.splitlines() diff --git a/salt/states/flatpak.py b/salt/states/flatpak.py index 7f92b4790d92..83322df69517 100644 --- a/salt/states/flatpak.py +++ b/salt/states/flatpak.py @@ -1,11 +1,11 @@ # -*- coding: utf-8 -*- -""" +''' Management of flatpak packages ============================== Allows the installation and uninstallation of flatpak packages. .. versionadded:: Neon -""" +''' from __future__ import absolute_import, print_function, unicode_literals import salt.utils.path @@ -21,15 +21,24 @@ def __virtual__(): def installed(location, name): - """Ensure that the named package is installed. + ''' + Ensure that the named package is installed. Args: location (str): The location or remote to install the flatpak from. name (str): The name of the package or runtime. Returns: - dict: The "result" and "output". - """ + dict: The ``result`` and ``output``. + + Example: + .. code-block:: bash + + install_package: + flatpack.installed: + - location: flathub + - name: gimp + ''' ret = {'name': name, 'changes': {}, 'result': None, @@ -67,14 +76,22 @@ def installed(location, name): def uninstalled(name): - """Ensure that the named package is not installed. + ''' + Ensure that the named package is not installed. Args: name (str): The flatpak package. Returns: - dict: The "result" and "output". - """ + dict: The ``result`` and ``output``. + + Example: + .. code-block:: bash + + uninstall_package: + flatpack.uninstalled: + - name: gimp + ''' ret = {'name': name, 'changes': {}, 'result': None, @@ -103,15 +120,24 @@ def uninstalled(name): def add_remote(name, location): - """Add a new location to install flatpak packages from. + ''' + Add a new location to install flatpak packages from. Args: name (str): The repositories name. location (str): The location of the repository. Returns: - dict: The "result" and "output". - """ + dict: The ``result`` and ``output``. + + Example: + .. code-block:: bash + + add_flathub: + flatpack.add_remote: + - name: flathub + - location: https://flathub.org/repo/flathub.flatpakrepo + ''' ret = {'name': name, 'changes': {}, 'result': None, From cac3088adc561e2a75ed9382c6cd5ae0bdca2b00 Mon Sep 17 00:00:00 2001 From: Steven Oliver Date: Fri, 29 Mar 2019 09:59:31 -0400 Subject: [PATCH 07/13] Correct lint errors --- salt/modules/flatpak.py | 1 - salt/states/flatpak.py | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/salt/modules/flatpak.py b/salt/modules/flatpak.py index dc9145eb0878..5a787b025779 100644 --- a/salt/modules/flatpak.py +++ b/salt/modules/flatpak.py @@ -8,7 +8,6 @@ ''' from __future__ import absolute_import, print_function, unicode_literals -import subprocess import re import salt.utils.path diff --git a/salt/states/flatpak.py b/salt/states/flatpak.py index 83322df69517..9f9984ddcfaa 100644 --- a/salt/states/flatpak.py +++ b/salt/states/flatpak.py @@ -53,7 +53,7 @@ def installed(location, name): ret['result'] = None return ret - __salt__['flatpak.install'](name, location) + install_ret = __salt__['flatpak.install'](name, location) if __salt__['flatpak.is_installed'](name): ret['comment'] = 'Package "{0}" was installed'.format(name) ret['changes']['new'] = name @@ -62,7 +62,7 @@ def installed(location, name): return ret ret['comment'] = 'Package "{0}" failed to install'.format(name) - ret['comment'] += '\noutput:\n' + install['output'] + ret['comment'] += '\noutput:\n' + install_ret['output'] ret['result'] = False return ret @@ -152,7 +152,7 @@ def add_remote(name, location): ret['result'] = None return ret - __salt__['flatpak.add_remote'](name) + install_ret = __salt__['flatpak.add_remote'](name) if __salt__['flatpak.is_remote_added'](name): ret['comment'] = 'Remote "{0}" was added'.format(name) ret['changes']['new'] = name @@ -161,7 +161,7 @@ def add_remote(name, location): return ret ret['comment'] = 'Failed to add remote "{0}"'.format(name) - ret['comment'] += '\noutput:\n' + install['output'] + ret['comment'] += '\noutput:\n' + install_ret['output'] ret['result'] = False return ret From 8dd0ca9653ca141356aa85eac4e17ed408647bbb Mon Sep 17 00:00:00 2001 From: Steven Oliver Date: Sun, 31 Mar 2019 21:41:47 -0400 Subject: [PATCH 08/13] Add missing = in docs --- doc/ref/modules/all/salt.modules.flatpak.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ref/modules/all/salt.modules.flatpak.rst b/doc/ref/modules/all/salt.modules.flatpak.rst index 7924b497dd61..c0878224f661 100644 --- a/doc/ref/modules/all/salt.modules.flatpak.rst +++ b/doc/ref/modules/all/salt.modules.flatpak.rst @@ -1,6 +1,6 @@ -================= +==================== salt.modules.flatpak -================= +==================== .. automodule:: salt.modules.flatpak :members: From db7e1878c26d9856aa64668aae9bc96db1d44a22 Mon Sep 17 00:00:00 2001 From: Steven Oliver Date: Fri, 12 Apr 2019 10:25:28 -0400 Subject: [PATCH 09/13] Add blank lines to code examples --- salt/modules/flatpak.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/salt/modules/flatpak.py b/salt/modules/flatpak.py index 5a787b025779..227ca1fcf9bd 100644 --- a/salt/modules/flatpak.py +++ b/salt/modules/flatpak.py @@ -37,6 +37,7 @@ def install(location, name): CLI Example: .. code-block:: bash + salt '*' flatpak.install flathub org.gimp.GIMP ''' ret = {'result': None, 'output': ''} @@ -65,6 +66,7 @@ def is_installed(name): CLI Example: .. code-block:: bash + salt '*' flatpak.is_installed org.gimp.GIMP ''' out = __salt__['cmd.run_all'](FLATPAK_BINARY_NAME + ' info ' + name) @@ -87,6 +89,7 @@ def uninstall(pkg): CLI Example: .. code-block:: bash + salt '*' flatpak.uninstall org.gimp.GIMP ''' ret = {'result': None, 'output': ''} @@ -116,6 +119,7 @@ def add_remote(name, location): CLI Example: .. code-block:: bash + salt '*' flatpak.add_remote flathub https://flathub.org/repo/flathub.flatpakrepo ''' ret = {'result': None, 'output': ''} @@ -143,6 +147,7 @@ def is_remote_added(remote): CLI Example: .. code-block:: bash + salt '*' flatpak.is_remote_added flathub ''' out = __salt__['cmd.run_all'](FLATPAK_BINARY_NAME + ' remotes') From c531bc373e90995c6b588493bf9634a39e4c238c Mon Sep 17 00:00:00 2001 From: Steven Oliver Date: Sun, 14 Apr 2019 13:12:10 -0400 Subject: [PATCH 10/13] Fix number of equal signs in title --- doc/ref/states/all/salt.modules.flatpak.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ref/states/all/salt.modules.flatpak.rst b/doc/ref/states/all/salt.modules.flatpak.rst index 2851fd3a08b1..54f63a0c2dd4 100644 --- a/doc/ref/states/all/salt.modules.flatpak.rst +++ b/doc/ref/states/all/salt.modules.flatpak.rst @@ -1,6 +1,6 @@ -================ +=================== salt.states.flatpak -================ +=================== .. automodule:: salt.states.flatpak :members: From 59ffad586413c6ee8bea7901470821df3f9cd53c Mon Sep 17 00:00:00 2001 From: Steven Oliver Date: Sun, 14 Apr 2019 13:32:13 -0400 Subject: [PATCH 11/13] Prevent duplicate object description in docs --- salt/states/flatpak.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/states/flatpak.py b/salt/states/flatpak.py index 9f9984ddcfaa..dbe648a2ff51 100644 --- a/salt/states/flatpak.py +++ b/salt/states/flatpak.py @@ -121,7 +121,7 @@ def uninstalled(name): def add_remote(name, location): ''' - Add a new location to install flatpak packages from. + Adds a new location to install flatpak packages from. Args: name (str): The repositories name. From 523c903cd860dc9e1698f3a262c8811fd99eb854 Mon Sep 17 00:00:00 2001 From: Steven Oliver Date: Sun, 14 Apr 2019 13:40:37 -0400 Subject: [PATCH 12/13] Use noindex for duplicate description in docs --- salt/modules/flatpak.py | 9 +-------- salt/states/flatpak.py | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/salt/modules/flatpak.py b/salt/modules/flatpak.py index 227ca1fcf9bd..ea0cb9f2e83c 100644 --- a/salt/modules/flatpak.py +++ b/salt/modules/flatpak.py @@ -108,14 +108,7 @@ def uninstall(pkg): def add_remote(name, location): ''' - Add a new location to install flatpak packages from. - - Args: - name (str): The repositories name. - location (str): The location of the repository. - - Returns: - dict: The ``result`` and ``output``. + :noindex: CLI Example: .. code-block:: bash diff --git a/salt/states/flatpak.py b/salt/states/flatpak.py index dbe648a2ff51..7a77172b5637 100644 --- a/salt/states/flatpak.py +++ b/salt/states/flatpak.py @@ -124,7 +124,7 @@ def add_remote(name, location): Adds a new location to install flatpak packages from. Args: - name (str): The repositories name. + name (str): The repository's name. location (str): The location of the repository. Returns: From aa59567c0746465ef422646a2c0de4e42b317ec9 Mon Sep 17 00:00:00 2001 From: Steven Oliver Date: Wed, 17 Apr 2019 21:01:45 -0400 Subject: [PATCH 13/13] Updates to docs --- doc/ref/modules/all/salt.modules.flatpak.rst | 1 - ...modules.flatpak.rst => salt.states.flatpak.rst} | 1 - salt/modules/flatpak.py | 14 +++++++++++++- salt/states/flatpak.py | 9 ++++++--- 4 files changed, 19 insertions(+), 6 deletions(-) rename doc/ref/states/all/{salt.modules.flatpak.rst => salt.states.flatpak.rst} (81%) diff --git a/doc/ref/modules/all/salt.modules.flatpak.rst b/doc/ref/modules/all/salt.modules.flatpak.rst index c0878224f661..e9ef81601c70 100644 --- a/doc/ref/modules/all/salt.modules.flatpak.rst +++ b/doc/ref/modules/all/salt.modules.flatpak.rst @@ -1,4 +1,3 @@ -==================== salt.modules.flatpak ==================== diff --git a/doc/ref/states/all/salt.modules.flatpak.rst b/doc/ref/states/all/salt.states.flatpak.rst similarity index 81% rename from doc/ref/states/all/salt.modules.flatpak.rst rename to doc/ref/states/all/salt.states.flatpak.rst index 54f63a0c2dd4..2ff3b61ae21c 100644 --- a/doc/ref/states/all/salt.modules.flatpak.rst +++ b/doc/ref/states/all/salt.states.flatpak.rst @@ -1,4 +1,3 @@ -=================== salt.states.flatpak =================== diff --git a/salt/modules/flatpak.py b/salt/modules/flatpak.py index ea0cb9f2e83c..722631c0297d 100644 --- a/salt/modules/flatpak.py +++ b/salt/modules/flatpak.py @@ -36,6 +36,7 @@ def install(location, name): dict: The ``result`` and ``output``. CLI Example: + .. code-block:: bash salt '*' flatpak.install flathub org.gimp.GIMP @@ -65,6 +66,7 @@ def is_installed(name): bool: True if the specified package or runtime is installed. CLI Example: + .. code-block:: bash salt '*' flatpak.is_installed org.gimp.GIMP @@ -88,6 +90,7 @@ def uninstall(pkg): dict: The ``result`` and ``output``. CLI Example: + .. code-block:: bash salt '*' flatpak.uninstall org.gimp.GIMP @@ -108,9 +111,17 @@ def uninstall(pkg): def add_remote(name, location): ''' - :noindex: + Adds a new location to install flatpak packages from. + + Args: + name (str): The repository's name. + location (str): The location of the repository. + + Returns: + dict: The ``result`` and ``output``. CLI Example: + .. code-block:: bash salt '*' flatpak.add_remote flathub https://flathub.org/repo/flathub.flatpakrepo @@ -139,6 +150,7 @@ def is_remote_added(remote): bool: True if the remote has already been added. CLI Example: + .. code-block:: bash salt '*' flatpak.is_remote_added flathub diff --git a/salt/states/flatpak.py b/salt/states/flatpak.py index 7a77172b5637..91c003b06721 100644 --- a/salt/states/flatpak.py +++ b/salt/states/flatpak.py @@ -32,7 +32,8 @@ def installed(location, name): dict: The ``result`` and ``output``. Example: - .. code-block:: bash + + .. code-block:: yaml install_package: flatpack.installed: @@ -86,7 +87,8 @@ def uninstalled(name): dict: The ``result`` and ``output``. Example: - .. code-block:: bash + + .. code-block:: yaml uninstall_package: flatpack.uninstalled: @@ -131,7 +133,8 @@ def add_remote(name, location): dict: The ``result`` and ``output``. Example: - .. code-block:: bash + + .. code-block:: yaml add_flathub: flatpack.add_remote: