ansible-gsetting icon indicating copy to clipboard operation
ansible-gsetting copied to clipboard

Fix key in changed_settings & unchanged_settings

Open clifford2 opened this issue 1 year ago • 1 comments

Fixed "key" names in module result dict's "changed_settings" & "unchanged_settings"

clifford2 avatar May 15 '24 18:05 clifford2

Hi Jiří. Thanks for sharing this cool piece of code!

I noticed that the changed_settings & unchanged_settings return dicts contained incorrect keys, and attempted a fix. I hope this is of value to you?

clifford2 avatar May 15 '24 18:05 clifford2

Hi Clifford, thank you. I no longer use Gnome and this Ansible module, so it's getting increasingly difficult for me to review patches and i'll archive the repo soon. But i tried experimenting in REPL and indeed your patch improves the representation of the setting in the dict. Merging. Thanks!

>>> class Setting:
...     def __init__(self, schema, path, key):
...         if not schema:
...             schema, key = self.split_key(key)
...         if path:
...             if not path.endswith('/'):
...                 path += '/'
...         arg1 = schema
...         if path:
...             arg1 += ':' + path
...         self.args = (arg1, key)
...     @staticmethod
...     def split_key(full_key):
...         key_array = full_key.split('.')
...         schema = '.'.join(key_array[0:-1])
...         single_key = key_array[-1]
...         return (schema, single_key)
... 
>>> 
>>> a=Setting('org.gnome.settings-daemon.plugins.media-keys.custom-keybinding', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/', 'name')
>>> {'test': a}
{'test': <__main__.Setting object at 0x7f3adc74d520>}
>>> {'test': '.'.join(a.args)}
{'test': 'org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/.name'}

jistr avatar Jun 22 '24 13:06 jistr