[augeas-devel] Re: using defnode to add new nodes

David Lutterkort lutter at redhat.com
Wed Jun 17 23:58:01 UTC 2009


On Wed, 2009-06-17 at 11:54 +0200, Kjetil Torgrim Homme wrote:
> On Tue, 2009-06-16 at 18:12 +0000, David Lutterkort wrote:
> > On Tue, 2009-06-16 at 11:08 +0200, Kjetil Torgrim Homme wrote:
> > > David Lutterkort <lutter at redhat.com> writes:
> > > > The path you use will only find the service-name node for 'foo' if it
> > > > has a protocol child set to 'tcp' - but the set that defnode does, does
> > > > not create a protocol child. With that, you wind up with a defvar with a
> > > > path that matches no nodes, and var contains the empty node set.
> > > 
> > > exactly.  the bug is that it doesn't add the new node to the node set.
> > > after all, it's not a dynamic evaluation, so adding it statically
> > > should work.
> > 
> > Variables are not changed once they have been defined - i.e., when you
> > do 'defvar var expr', expr is evaluated and the result is assigned to
> > var (just like in any other language). After that, the value of var is
> > not changed.
> 
> right.  I'm not suggesting that the variable defined by defnode is
> changed *after* defnode returns.  I'm just suggesting that the node
> defnode creates is included in the node list returned.

Aaah .. all kinds of lights are going off .. you are saying that after
doing a 'set' inside defnode, just stick the new node into the
variable ? Yeah, I like that .. happen to have a patch ? ;)

> IMHO, for consistency, you either need to drop that instantiation, or
> you need to include the node in the result set.  obviously the latter is
> more useful.

Heh .. yeah, I finally got what you are after. That seems sensible to
me.

> I'm sure it's possible to come up with problematic examples, and I
> encourage you to do so, so that we can discuss how Augeas is to be
> *used*.  a little (but not much) more tricky example: defnode doesn't
> work with the hosts lens, since it creates hosts/N/ rather than
> hosts[N].

Just as an aside: the reason the hosts lens creates a /files/etc/hosts/N
node rather than something like /files/etc/hosts/entry[N] (i.e. uses the
'seq' lens) has to do how spacing is preserved. Basically, with the
current scheme, Augeas can detect that an entry has been deleted, and
make sure comments etc. stay in the right place. With the alternate
scheme, deleting a host entry in the middle would cause all lines after
the deleted line to shift up one line, past comments.

>         augtool> print '/files/etc/hosts/*/*[../ipaddr = "127.0.0.1"]'
>         /files/etc/hosts/1/ipaddr = "127.0.0.1"
>         /files/etc/hosts/1/canonical = "localhost.localdomain"
>         /files/etc/hosts/1/alias[1] = "localhost"
>         /files/etc/hosts/1/alias[2] = "localhost"
>         augtool> defnode host '/files/etc/hosts/*/*[../ipaddr = "127.0.0.1"]'
>         Failed
> 
> first of all, such inconsistencies across lenses should be fixed.
> secondly, I think it's quite reasonable that in the non-matching case,
> defnode would create a new object at the level of the first wildcard.
> in either case I would like to be able to say
> 
>         set $host/ipaddr 127.0.0.1
>         set $host/canonical localhost
>         set $host/alias[1] localhost.localdomain

The problem is that at the point where the node is created, I have no
idea what an appropriate name for the new node would be (since I only
have the wildcard, I don't even know what regexp the label is supposed
to match)

David





More information about the augeas-devel mailing list