mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-27 04:41:26 -07:00
Add xdg_mime module (#10007)
* Add version of xdg_mime module
* Fix xdg_mime_get since the command is different
* Add query parameter
* Fix order of parameters
* Add myself to BOTMETA
* Add unit tests
* Fix the way we deal when there is no handler set
* Improve documentation
* Remove unused import
* Fix documentation
* Strip xdg-mime from version string
* Fix information about version
* Add error message sample
* Add test to invalid handler
* Add support to multiple mime-types
* Change the output parameter from handlers to handler
* Change tests related to multiple mime-type support
* Small fixes
* Stop using constant to enable changed state
* Add before_handlers and after_handlers
* Change tests to use before and after structures
* Add a stronger message about using a non-installed handler
* Manage some edge cases
* Change error message to match the new value
* Add some fixes
* Change some tests
* Update plugins/modules/xdg_mime.py
* Remove a blank line
* Remove single quote
* Add xdg-mime to the version in the mocks
* Remove after_handlers and make code simpler
* Update tests to work without after_handlers
* Remove diff_params and clean output_params
* Make mime_type plural since it supports multiple items
* Move the handler check to module init
* Use anchors in the test to make yaml simpler
* Update plugins/modules/xdg_mime.py
* Update plugins/modules/xdg_mime.py
* Update plugins/modules/xdg_mime.py
* Update plugins/modules/xdg_mime.py
* Update plugins/modules/xdg_mime.py
* Update plugins/modules/xdg_mime.py
* Update plugins/modules/xdg_mime.py
* Update plugins/modules/xdg_mime.py
* Update plugins/modules/xdg_mime.py
* Update plugins/modules/xdg_mime.py
* Add blank line to separe examples
* Update plugins/modules/xdg_mime.py
* Add a small homage to my late grandma
* Update plugins/modules/xdg_mime.py
* Fix pep8 problem with the homage
* Remove trailing whitespace
* Update plugins/modules/xdg_mime.py
---------
(cherry picked from commit 373334d668
)
Co-authored-by: Marcos Alano <mhalano@users.noreply.github.com>
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright (c) 2025, Marcos Alano <marcoshalano@gmail.com>
|
|
# Based on gio_mime module. Copyright (c) 2022, Alexei Znamensky <russoz@gmail.com>
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
__metaclass__ = type
|
|
|
|
from ansible_collections.community.general.plugins.module_utils.cmd_runner import CmdRunner, cmd_runner_fmt
|
|
|
|
|
|
def xdg_mime_runner(module, **kwargs):
|
|
return CmdRunner(
|
|
module,
|
|
command=['xdg-mime'],
|
|
arg_formats=dict(
|
|
default=cmd_runner_fmt.as_fixed('default'),
|
|
query=cmd_runner_fmt.as_fixed('query'),
|
|
mime_types=cmd_runner_fmt.as_list(),
|
|
handler=cmd_runner_fmt.as_list(),
|
|
version=cmd_runner_fmt.as_fixed('--version'),
|
|
),
|
|
**kwargs
|
|
)
|
|
|
|
|
|
def xdg_mime_get(runner, mime_type):
|
|
def process(rc, out, err):
|
|
if not out.strip():
|
|
return None
|
|
out = out.splitlines()[0]
|
|
return out.split()[-1]
|
|
|
|
with runner("query default mime_types", output_process=process) as ctx:
|
|
return ctx.run(mime_types=mime_type)
|