2021-07-24 22:30:46 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
2022-08-05 22:12:10 +02:00
|
|
|
# Copyright (c) 2021, Alexei Znamensky <russoz@gmail.com>
|
2022-08-05 12:28:29 +02:00
|
|
|
# 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
|
2021-07-24 22:30:46 +02:00
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
module: xfconf_info
|
|
|
|
author:
|
2022-07-24 12:09:24 +02:00
|
|
|
- "Alexei Znamensky (@russoz)"
|
2021-07-24 22:30:46 +02:00
|
|
|
short_description: Retrieve XFCE4 configurations
|
|
|
|
version_added: 3.5.0
|
|
|
|
description:
|
|
|
|
- This module allows retrieving Xfce 4 configurations with the help of C(xfconf-query).
|
2022-11-06 21:16:43 +01:00
|
|
|
extends_documentation_fragment:
|
|
|
|
- community.general.attributes
|
|
|
|
- community.general.attributes.info_module
|
2023-02-20 17:49:31 +01:00
|
|
|
attributes:
|
|
|
|
check_mode:
|
|
|
|
version_added: 3.3.0
|
|
|
|
# This was backported to 2.5.4 and 1.3.11 as well, since this was a bugfix
|
2021-07-24 22:30:46 +02:00
|
|
|
options:
|
|
|
|
channel:
|
|
|
|
description:
|
|
|
|
- >
|
|
|
|
A Xfconf preference channel is a top-level tree key, inside of the
|
|
|
|
Xfconf repository that corresponds to the location for which all
|
|
|
|
application properties/keys are stored.
|
|
|
|
- If not provided, the module will list all available channels.
|
|
|
|
type: str
|
|
|
|
property:
|
|
|
|
description:
|
|
|
|
- >
|
|
|
|
A Xfce preference key is an element in the Xfconf repository
|
|
|
|
that corresponds to an application preference.
|
|
|
|
- If provided, then I(channel) is required.
|
|
|
|
- If not provided and a I(channel) is provided, then the module will list all available properties in that I(channel).
|
|
|
|
type: str
|
|
|
|
notes:
|
|
|
|
- See man xfconf-query(1) for more details.
|
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = """
|
|
|
|
- name: Get list of all available channels
|
|
|
|
community.general.xfconf_info: {}
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: Get list of all properties in a specific channel
|
|
|
|
community.general.xfconf_info:
|
|
|
|
channel: xsettings
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: Retrieve the DPI value
|
|
|
|
community.general.xfconf_info:
|
|
|
|
channel: xsettings
|
|
|
|
property: /Xft/DPI
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: Get workspace names (4)
|
|
|
|
community.general.xfconf_info:
|
|
|
|
channel: xfwm4
|
|
|
|
property: /general/workspace_names
|
|
|
|
register: result
|
|
|
|
"""
|
|
|
|
|
|
|
|
RETURN = '''
|
|
|
|
channels:
|
|
|
|
description:
|
2022-07-24 12:09:24 +02:00
|
|
|
- List of available channels.
|
|
|
|
- Returned when the module receives no parameter at all.
|
2021-07-24 22:30:46 +02:00
|
|
|
returned: success
|
|
|
|
type: list
|
|
|
|
elements: str
|
|
|
|
sample:
|
|
|
|
- xfce4-desktop
|
|
|
|
- displays
|
|
|
|
- xsettings
|
|
|
|
- xfwm4
|
|
|
|
properties:
|
|
|
|
description:
|
2022-07-24 12:09:24 +02:00
|
|
|
- List of available properties for a specific channel.
|
|
|
|
- Returned by passing only the I(channel) parameter to the module.
|
2021-07-24 22:30:46 +02:00
|
|
|
returned: success
|
|
|
|
type: list
|
|
|
|
elements: str
|
|
|
|
sample:
|
2022-07-24 12:09:24 +02:00
|
|
|
- /Gdk/WindowScalingFactor
|
|
|
|
- /Gtk/ButtonImages
|
|
|
|
- /Gtk/CursorThemeSize
|
|
|
|
- /Gtk/DecorationLayout
|
|
|
|
- /Gtk/FontName
|
|
|
|
- /Gtk/MenuImages
|
|
|
|
- /Gtk/MonospaceFontName
|
|
|
|
- /Net/DoubleClickTime
|
|
|
|
- /Net/IconThemeName
|
|
|
|
- /Net/ThemeName
|
|
|
|
- /Xft/Antialias
|
|
|
|
- /Xft/Hinting
|
|
|
|
- /Xft/HintStyle
|
|
|
|
- /Xft/RGBA
|
2021-07-24 22:30:46 +02:00
|
|
|
is_array:
|
|
|
|
description:
|
2022-07-24 12:09:24 +02:00
|
|
|
- Flag indicating whether the property is an array or not.
|
2021-07-24 22:30:46 +02:00
|
|
|
returned: success
|
|
|
|
type: bool
|
|
|
|
value:
|
|
|
|
description:
|
2022-07-24 12:09:24 +02:00
|
|
|
- The value of the property. Empty if the property is of array type.
|
2021-07-24 22:30:46 +02:00
|
|
|
returned: success
|
|
|
|
type: str
|
|
|
|
sample: Monospace 10
|
|
|
|
value_array:
|
|
|
|
description:
|
2022-07-24 12:09:24 +02:00
|
|
|
- The array value of the property. Empty if the property is not of array type.
|
2021-07-24 22:30:46 +02:00
|
|
|
returned: success
|
|
|
|
type: list
|
|
|
|
elements: str
|
|
|
|
sample:
|
2022-07-24 12:09:24 +02:00
|
|
|
- Main
|
|
|
|
- Work
|
|
|
|
- Tmp
|
2021-07-24 22:30:46 +02:00
|
|
|
'''
|
|
|
|
|
2022-06-06 10:38:46 +02:00
|
|
|
from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper
|
|
|
|
from ansible_collections.community.general.plugins.module_utils.xfconf import xfconf_runner
|
2021-07-24 22:30:46 +02:00
|
|
|
|
|
|
|
|
2022-06-06 10:38:46 +02:00
|
|
|
class XFConfInfo(ModuleHelper):
|
2021-07-24 22:30:46 +02:00
|
|
|
module = dict(
|
|
|
|
argument_spec=dict(
|
|
|
|
channel=dict(type='str'),
|
|
|
|
property=dict(type='str'),
|
|
|
|
),
|
|
|
|
required_by=dict(
|
|
|
|
property=['channel']
|
|
|
|
),
|
2021-07-27 18:24:29 +02:00
|
|
|
supports_check_mode=True,
|
2021-07-24 22:30:46 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def __init_module__(self):
|
2022-06-06 10:38:46 +02:00
|
|
|
self.runner = xfconf_runner(self.module, check_rc=True)
|
|
|
|
self.vars.set("list_arg", False, output=False)
|
2021-07-24 22:30:46 +02:00
|
|
|
self.vars.set("is_array", False)
|
|
|
|
|
|
|
|
def process_command_output(self, rc, out, err):
|
|
|
|
result = out.rstrip()
|
|
|
|
if "Value is an array with" in result:
|
|
|
|
result = result.split("\n")
|
|
|
|
result.pop(0)
|
|
|
|
result.pop(0)
|
|
|
|
self.vars.is_array = True
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
def _process_list_properties(self, rc, out, err):
|
|
|
|
return out.splitlines()
|
|
|
|
|
|
|
|
def _process_list_channels(self, rc, out, err):
|
|
|
|
lines = out.splitlines()
|
|
|
|
lines.pop(0)
|
|
|
|
lines = [s.lstrip() for s in lines]
|
|
|
|
return lines
|
|
|
|
|
|
|
|
def __run__(self):
|
2022-06-06 10:38:46 +02:00
|
|
|
self.vars.list_arg = not (bool(self.vars.channel) and bool(self.vars.property))
|
2021-07-24 22:30:46 +02:00
|
|
|
output = 'value'
|
|
|
|
proc = self.process_command_output
|
|
|
|
if self.vars.channel is None:
|
|
|
|
output = 'channels'
|
|
|
|
proc = self._process_list_channels
|
|
|
|
elif self.vars.property is None:
|
|
|
|
output = 'properties'
|
|
|
|
proc = self._process_list_properties
|
2022-07-24 12:09:24 +02:00
|
|
|
|
2022-06-06 10:38:46 +02:00
|
|
|
with self.runner.context('list_arg channel property', output_process=proc) as ctx:
|
|
|
|
result = ctx.run(**self.vars)
|
2022-07-24 12:09:24 +02:00
|
|
|
|
2022-06-06 10:38:46 +02:00
|
|
|
if not self.vars.list_arg and self.vars.is_array:
|
2021-07-24 22:30:46 +02:00
|
|
|
output = "value_array"
|
|
|
|
self.vars.set(output, result)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2022-06-06 10:38:46 +02:00
|
|
|
XFConfInfo.execute()
|
2021-07-24 22:30:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|