Debian Codegraph @

ansible_collections/community/general/plugins/modules/gconftool2_info.py

raw
1 #!/usr/bin/python
2 # Copyright (c) 2022, Alexei Znamensky <[email protected]>
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 from __future__ import annotations
7
8 DOCUMENTATION = r"""
9 module: gconftool2_info
10 author:
11 - "Alexei Znamensky (@russoz)"
12 short_description: Retrieve GConf configurations
13 version_added: 5.1.0
14 description:
15 - This module allows retrieving application preferences from the GConf database, with the help of C(gconftool-2).
16 extends_documentation_fragment:
17 - community.general._attributes
18 - community.general._attributes.info_module
19 options:
20 key:
21 description:
22 - The key name for an element in the GConf database.
23 type: str
24 required: true
25 seealso:
26 - name: C(gconftool-2) command manual page
27 description: Manual page for the command.
28 link: https://help.gnome.org/admin//system-admin-guide/2.32/gconf-6.html.en
29 - name: gconf repository (archived)
30 description: Git repository for the project. It is an archived project, so the repository is read-only.
31 link: https://gitlab.gnome.org/Archive/gconf
32 """
33
34 EXAMPLES = r"""
35 - name: Get value for a certain key in the database.
36 community.general.gconftool2_info:
37 key: /desktop/gnome/background/picture_filename
38 register: result
39 """
40
41 RETURN = r"""
42 value:
43 description:
44 - The value of the property.
45 returned: success
46 type: str
47 sample: Monospace 10
48 version:
49 description: Version of gconftool-2.
50 type: str
51 returned: always
52 sample: "3.2.6"
53 version_added: 10.0.0
54 """
55
56 from ansible_collections.community.general.plugins.module_utils._gconftool2 import gconftool2_runner
57 from ansible_collections.community.general.plugins.module_utils._module_helper import ModuleHelper
58
59
60 class GConftoolInfo(ModuleHelper):
61 output_params = ["key"]
62 module = dict(
63 argument_spec=dict(
64 key=dict(type="str", required=True, no_log=False),
65 ),
66 supports_check_mode=True,
67 )
68
69 def __init_module__(self):
70 self.runner = gconftool2_runner(self.module, check_rc=True)
71 with self.runner("version") as ctx:
72 rc, out, err = ctx.run()
73 self.vars.version = out.strip()
74
75 def __run__(self):
76 with self.runner.context(args_order=["state", "key"]) as ctx:
77 rc, out, err = ctx.run(state="get")
78 self.vars.value = None if err and not out else out.rstrip()
79
80
81 def main():
82 GConftoolInfo.execute()
83
84
85 if __name__ == "__main__":
86 main()