Greg,
Since dealing with Gnome is next on my checklist, I cracked open the edit_xml stuff a bit... Basically it works like an edit_line in a files promise:
bundle agent gconftest
{
files:
"/tmp/foo.xml" # This is the XML file to be edited
edit_xml => xml_set;
}
First, I called this bundle to create the new XML file:
bundle edit_xml xml_set
{
insert_tree:
"<Host name=\"cfe_host\"><Alias>cfe_alias</Alias></Host>";
}
It gripes about it, but it creates it like so:
-----
<?xml version="1.0"?>
<Host name="cfe_host"><Alias>cfe_alias</Alias></Host>
-----
Then I change the bundle to try out the set_attribute operation:
bundle edit_xml xml_set
{
set_attribute:
"attrib"
attribute_value => "xyzzy",
select_xpath => "/Host";
}
And the file changes to:
<Host name="cfe_host" attrib="xyzzy"><Alias>cfe_alias</Alias></Host>
That is, an "attribute" is a key-value pair that falls within the tag. The promise above set an "attrib" attribute in the /Host node with a value of "xyzzy."
Next, I changed the bundle to try out set_text:
bundle edit_xml xml_setattr
{
set_text:
"xyzzy"
select_xpath => "/Host/Alias";
}
And you end up with this:
<Host name="cfe_host" attrib="xyzzy"><Alias>xyzzy</Alias></Host>
So, with this basic outline, you can see how we need to approach the gconf file. First, of course, we need to use edit_defaults to set the maximum file size to 5M, since the XML file is 2M. For example, let's look at the /apps/gdm/simple-greeter/disable_user_list node in the %gconf-tree.xml file:
<dir name="apps">
<dir name="gdm">
<dir name="simple-greeter">
<entry name="disable_user_list" mtime="1357935465" type="bool" value="false">
</entry>
</dir>
</dir>
So based on what I figured out above, this presents a different situation than the examples here and in the docs - /apps/gdm/simple-greeter/disable_user_list isn't actually an XML path - we have a list of "dir" nodes with "name" attributes that work their way down to an "entry" node which has a "name" attribute of "disable_user_list." So the xpath is /gconf/dir/dir/dir/entry, in effect, which won't work well for select_xpath.
So, what I did instead is used "insert_tree" to just overwrite the whole tree in question:
bundle edit_xml do_gconf
{
insert_tree:
"<dir name=\"apps\">
<dir name=\"gdm\">
<dir name=\"simple-greeter\">
<entry name=\"disable_user_list\" type=\"bool\" value=\"true\">
</entry>
</dir>
</dir>
</dir>"
select_xpath => "/gconf";
}
I can't set the mtime attribute, since that wouldn't converge. And after an agent run, this tree turns up right at the end of the Gnome config file, replacing the other tree that used to be earlier in the file. Subsequent runs determine the promise has been kept, so nothing is done with the file. So, this means that the Gnome greeter's user list has been turned off. Success!! Hooray...ish.
It looks like we'd want a way to do a "select_attributes," as it were. Maybe this is already part of the XML Xpath specification? Wading through the XML Path Language doc here:
... it looks like we can do something like this:
"/gconf/dir[@name=apps]/dir[@name=gdm]/dir[@name=simple-greeter]/entry[@name=disable_user_list]"
And then use set_attribute edits to modify the "value" attribute of that node. Let me try that...
Okay, the XML library didn't complain about the select_xpath value, but it also didn't deal with the promise correctly either with or without quotes around the names in the path:
!! The promised attribute (value) with value (false) was not set in /tmp/gconf.xml.defaults/%gconf-tree.xml
I: Report relates to a promise with handle ""
I: Made in version 'not specified' of './
gconf.cf' near line 30
[root]#
It does, however, appear to be getting to the right node - if I change "false" to "true" in the promise it reports the promise as kept:
cf3> !! The promised attribute to be set (value) with value (true) exists in /tmp/gconf.xml.defaults/%gconf-tree.xml (promise kept)
It just doesn't seem to be able to change it for some unknown reason. Verbose mode isn't any more informative, unfortunately. But in any case, we do seem to be well on the road to making promises Gnome configs. I'll start at "/gconf" and work my way down and see what I can figure out.
I noticed something potentially problematic, as well. I copied a fresh tree.xml file in place, and ran the promise on it, and instead of seeing one line change, I saw nearly 2,000 changes - the rewrite of the file is collapsing empty nodes and replacing " with double quotes:
- <stringvalue></stringvalue>
+ <stringvalue/>
- if the "vnc" auth...
+ if the "vnc" auth...
Is this normal for XML?
-Michael Pelletier.