[augeas-devel] How to get the content of /etc/hosts with the API ?

David Lutterkort dlutter at redhat.com
Mon Jul 7 18:04:30 UTC 2008


On Mon, 2008-07-07 at 15:04 +0200, Dominique Dumont wrote:
> So the only way to get all the data from /etc/hosts is to use
> "/files/etc/hosts/*/*" pattern. 
> 
> The only hitch is that I need to know the "depth" of the struture of
> the configuration data to be able to get data. It works for /etc/hosts
> with a depth of 2, but that's not a generic solution.
> 
> So could we have a "print" equivalent that would send the data back
> through the API ?

The real issue is that there is no way to say 'match any number of
components' in a path expression. What you want is something like
'match /files/etc/hosts/**' (rsync syntax) or
'match /files/etc/hosts//*' (XPath syntax) - it's one of the things I
would like to add to the path expression syntax at some point.

In the meantime, you can work around it in this specific case by doing
the recursive traversal manually (my Perl is crappy, so here's rough
pseudocode)

        def list_all(path)
          worklist = [ path ]
          result = []
          while (worklist.size > 0) {
            p = worklist.pop()
            newpaths = aug.match(p + "/*")
            worklist.append(newpaths)
            result.append(newpaths)
          }
          return result
        
and you can get rid of worklist if you just keep an index into 'result'
of which of the paths you already checked.

David





More information about the augeas-devel mailing list