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

dconf: minor refactor #6336

Merged
merged 3 commits into from
Apr 16, 2023
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
2 changes: 2 additions & 0 deletions changelogs/fragments/6336-dconf-refactor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- dconf - minor refactoring improving parameters and dependencies validation (https://github.com/ansible-collections/community.general/pull/6336).
27 changes: 10 additions & 17 deletions plugins/modules/dconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,19 @@


import os
import traceback

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
from ansible_collections.community.general.plugins.module_utils import deps

try:
from gi.repository.GLib import Variant, GError
except ImportError:
Variant = None
GError = AttributeError

PSUTIL_IMP_ERR = None
try:
with deps.declare("psutil"):
import psutil
HAS_PSUTIL = True
except ImportError:
PSUTIL_IMP_ERR = traceback.format_exc()
HAS_PSUTIL = False

from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils.common.text.converters import to_native


class DBusWrapper(object):
Expand Down Expand Up @@ -414,7 +409,10 @@ def main():
# Converted to str below after special handling of bool.
value=dict(required=False, default=None, type='raw'),
),
supports_check_mode=True
supports_check_mode=True,
required_if=[
('state', 'present', ['value']),
],
)

# Try to be forgiving about the user specifying a boolean as the value, or
Expand All @@ -435,12 +433,7 @@ def main():
'using string comparison to check value equality. This fallback '
'will be deprecated in a future version of community.general.')

if not HAS_PSUTIL:
module.fail_json(msg=missing_required_lib("psutil"), exception=PSUTIL_IMP_ERR)

# If present state was specified, value must be provided.
if module.params['state'] == 'present' and module.params['value'] is None:
module.fail_json(msg='State "present" requires "value" to be set.')
deps.validate(module)

# Create wrapper instance.
dconf = DconfPreference(module, module.check_mode)
Expand Down