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

Dominique Dumont dominique.dumont at hp.com
Fri Jul 11 13:11:03 UTC 2008


David Lutterkort <dlutter at redhat.com> writes:

> 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.

Thanks for the help. I've translated your pseudo-code in Perl and I'm
able to load data extracted by Augeas into Config::Model.

For those who are interested, here's the actual Perl code that use
Augeas perl bindings (Config::Augeas):

    my @worklist = ( $mainpath );
    my @result ;
    while ( @worklist ) {
	my $p = pop @worklist ;
	my @newpath = $augeas_obj -> match($p . "/*") ;
	push @worklist, @newpath ;
	push @result,   @newpath ;
    }

Now I need to code the save part ...

All the best.

-- 
Dominique Dumont 
"Delivering successful solutions requires giving people what they
need, not what they want." Kurt Bittner




More information about the augeas-devel mailing list