[augeas-devel] Various additions to path expressions

lutter at redhat.com lutter at redhat.com
Sat May 7 01:12:48 UTC 2011


These patches, indirectly, address bug #198. They make it possible to find
the lens responsible for loading a certain path with something like

    match /augeas/load/*[ '/etc/hosts/1' =~ glob(incl) + regexp('/.*') ]/lens

Likewise, it is possible to get rid of all the transforms that are _not_
needed for a certain path with

    rm /augeas/load/*[ '/etc/hosts/1' !~ glob(incl) + regexp('/.*') ]

We can therefore run augtool with --noload and execute the following
commands to load only the file needed for a specific path (not necessarily
the path to the toplevel node for the file):

    rm /augeas/load/*[ '/etc/hosts/1' !~ glob(incl) + regexp('/.*') ]
    load

It is possible to do this for more than one path (though the path
expression becomes a bit of a monster). For example, these commands

    rm /augeas/load/*[ '/etc/hosts/1' !~ glob(incl) + regexp('/.*') and '/etc/inittab/1' !~ glob(incl) + regexp('/.*') ]
    print /augeas/load/*/lens

yield the output

    /augeas/load/Hosts/lens = "@Hosts"
    /augeas/load/Inittab/lens = "@Inittab"

In detail, the additions to path expressions are:

  (1) allow a nodeset as the argument to 'regexp'; the resulting regexp is
      the union ('|') of the values of all the nodes

  (2) add a glob function that makes a regexp by interpreting its argument
      as a regexp; IOW, glob('a*.b') is the same as regexp('a.*\.b')

  (3) add an operator !~, which is the negation of =~, i.e. S !~ RX is true
      of S does _not_ match the regular expression RX

  (4) allow concatenation of strings and regexps with the '+' operator; the
      two operands to '+' must have the same type, i.e. it is not possible
      to concatenate a string with a regexp.

David




More information about the augeas-devel mailing list