Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xfconf and xfconf_info: use do_raise #4975

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/4975-xfconf-use-do-raise.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- xfconf - use ``do_raise()`` instead of defining custom exception class (https://github.com/ansible-collections/community.general/pull/4975).
- xfconf_info - use ``do_raise()`` instead of defining custom exception class (https://github.com/ansible-collections/community.general/pull/4975).
8 changes: 2 additions & 6 deletions plugins/modules/system/xfconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@
from ansible_collections.community.general.plugins.module_utils.xfconf import xfconf_runner


class XFConfException(Exception):
pass


class XFConfProperty(StateModuleHelper):
change_params = 'value',
diff_params = 'value',
Expand Down Expand Up @@ -198,7 +194,7 @@ def process_command_output(self, rc, out, err):
if err.rstrip() == self.does_not:
return None
if rc or len(err):
raise XFConfException('xfconf-query failed with error (rc={0}): {1}'.format(rc, err))
self.do_raise('xfconf-query failed with error (rc={0}): {1}'.format(rc, err))

result = out.rstrip()
if "Value is an array with" in result:
Expand Down Expand Up @@ -231,7 +227,7 @@ def state_present(self):
value_type = value_type * values_len
elif types_len != values_len:
# or complain if lists' lengths are different
raise XFConfException('Number of elements in "value" and "value_type" must be the same')
self.do_raise('Number of elements in "value" and "value_type" must be the same')

# calculates if it is an array
self.vars.is_array = \
Expand Down
56 changes: 27 additions & 29 deletions plugins/modules/system/xfconf_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
DOCUMENTATION = '''
module: xfconf_info
author:
- "Alexei Znamensky (@russoz)"
- "Alexei Znamensky (@russoz)"
short_description: Retrieve XFCE4 configurations
version_added: 3.5.0
description:
Expand Down Expand Up @@ -61,8 +61,8 @@
RETURN = '''
channels:
description:
- List of available channels.
- Returned when the module receives no parameter at all.
- List of available channels.
- Returned when the module receives no parameter at all.
returned: success
type: list
elements: str
Expand All @@ -73,57 +73,53 @@
- xfwm4
properties:
description:
- List of available properties for a specific channel.
- Returned by passing only the I(channel) parameter to the module.
- List of available properties for a specific channel.
- Returned by passing only the I(channel) parameter to the module.
returned: success
type: list
elements: str
sample:
- /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
- /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
is_array:
description:
- Flag indicating whether the property is an array or not.
- Flag indicating whether the property is an array or not.
returned: success
type: bool
value:
description:
- The value of the property. Empty if the property is of array type.
- The value of the property. Empty if the property is of array type.
returned: success
type: str
sample: Monospace 10
value_array:
description:
- The array value of the property. Empty if the property is not of array type.
- The array value of the property. Empty if the property is not of array type.
returned: success
type: list
elements: str
sample:
- Main
- Work
- Tmp
- Main
- Work
- Tmp
'''

from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper
from ansible_collections.community.general.plugins.module_utils.xfconf import xfconf_runner


class XFConfException(Exception):
pass


class XFConfInfo(ModuleHelper):
module = dict(
argument_spec=dict(
Expand Down Expand Up @@ -170,8 +166,10 @@ def __run__(self):
elif self.vars.property is None:
output = 'properties'
proc = self._process_list_properties

with self.runner.context('list_arg channel property', output_process=proc) as ctx:
result = ctx.run(**self.vars)

if not self.vars.list_arg and self.vars.is_array:
output = "value_array"
self.vars.set(output, result)
Expand Down