mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
gconftool2: improvements (#4647)
* gconftool2: improvements * added changelog fragment * typo * Update changelogs/fragments/4647-gconftool2-command-arg.yaml Per recommendation from Felix. Danke!
This commit is contained in:
parent
a4b4756777
commit
fbff98c5f2
2 changed files with 16 additions and 18 deletions
2
changelogs/fragments/4647-gconftool2-command-arg.yaml
Normal file
2
changelogs/fragments/4647-gconftool2-command-arg.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- gconftool2 - properly escape values when passing them to ``gconftool-2`` (https://github.com/ansible-collections/community.general/pull/4647).
|
|
@ -99,45 +99,41 @@ class GConf2Preference(object):
|
||||||
|
|
||||||
def call(self, call_type, fail_onerr=True):
|
def call(self, call_type, fail_onerr=True):
|
||||||
""" Helper function to perform gconftool-2 operations """
|
""" Helper function to perform gconftool-2 operations """
|
||||||
config_source = ''
|
config_source = []
|
||||||
direct = ''
|
direct = []
|
||||||
changed = False
|
changed = False
|
||||||
out = ''
|
out = ''
|
||||||
|
|
||||||
# If the configuration source is different from the default, create
|
# If the configuration source is different from the default, create
|
||||||
# the argument
|
# the argument
|
||||||
if self.config_source is not None and len(self.config_source) > 0:
|
if self.config_source is not None and len(self.config_source) > 0:
|
||||||
config_source = "--config-source " + self.config_source
|
config_source = ["--config-source", self.config_source]
|
||||||
|
|
||||||
# If direct is true, create the argument
|
# If direct is true, create the argument
|
||||||
if self.direct:
|
if self.direct:
|
||||||
direct = "--direct"
|
direct = ["--direct"]
|
||||||
|
|
||||||
# Execute the call
|
# Execute the call
|
||||||
cmd = "gconftool-2 "
|
cmd = ["gconftool-2"]
|
||||||
try:
|
try:
|
||||||
# If the call is "get", then we don't need as many parameters and
|
# If the call is "get", then we don't need as many parameters and
|
||||||
# we can ignore some
|
# we can ignore some
|
||||||
if call_type == 'get':
|
if call_type == 'get':
|
||||||
cmd += "--get {0}".format(self.key)
|
cmd.extend(["--get", self.key])
|
||||||
# Otherwise, we will use all relevant parameters
|
# Otherwise, we will use all relevant parameters
|
||||||
elif call_type == 'set':
|
elif call_type == 'set':
|
||||||
cmd += "{0} {1} --type {2} --{3} {4} \"{5}\"".format(direct,
|
cmd.extend(direct)
|
||||||
config_source,
|
cmd.extend(config_source)
|
||||||
self.value_type,
|
cmd.extend(["--type", self.value_type, "--{3}".format(call_type), self.key, self.value])
|
||||||
call_type,
|
|
||||||
self.key,
|
|
||||||
self.value)
|
|
||||||
elif call_type == 'unset':
|
elif call_type == 'unset':
|
||||||
cmd += "--unset {0}".format(self.key)
|
cmd.extend(["--unset", self.key])
|
||||||
|
|
||||||
# Start external command
|
# Start external command
|
||||||
rc, out, err = self.ansible.run_command(cmd, use_unsafe_shell=True)
|
rc, out, err = self.ansible.run_command(cmd)
|
||||||
|
|
||||||
if len(err) > 0:
|
if err and fail_onerr:
|
||||||
if fail_onerr:
|
self.ansible.fail_json(msg='gconftool-2 failed with '
|
||||||
self.ansible.fail_json(msg='gconftool-2 failed with '
|
'error: %s' % (str(err)))
|
||||||
'error: %s' % (str(err)))
|
|
||||||
else:
|
else:
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue