[augeas-devel] Re: augeas: parsing one file only

David Lutterkort lutter at redhat.com
Mon Mar 2 05:12:43 UTC 2009



>         I'm wondering whether it's possible to parse just one specific
>         file with
>         augeas somehow. It appears that it reads all the files known
>         to the
>         autoload-enabled modules when starting augtool or calling
>         aug_init().
>         This is rather slow compared to parsing just one file, if
>         that's exactly
>          one's intention.
>         
>         One way to achieve this is having the root parameter to
>         augtool or
>         aug_init() point to a root tree containing only the desired
>         file. But i
>         would like to ask whether there is some other way (even
>         planned). Or is
>         it intentional not to allow such use case?
> 
> 
> This is a common request. You can have a look at the ticket associated
> with it [0] and the links in it.
> I am sure that David would be happy to get a patch for it.

Yes, definitely. I am going to release 0.4.1 tomorrow - the release
after that will need to contain a way to tailor which files are
processed by Augeas, since I am using it for a project[1] where the
current startup time, caused by parsing too many files, is simply
unacceptable.

But I would _love_ for somebody to beat me to it, and send a patch along
the lines of ticket 42 that Raphael pointed out. Just to summarize the
ticket, the plan is to have Augeas store information about the files it
is going to process in a certain part of the tree, say
under /augeas/transform. That part would look something like

        /augeas/transform/Hosts
                            /lens = "Hosts.lns"
                            /incl = "/etc/hosts"
                         /Shellvars
                            /lens = "Shellvars.lns"
                            /incl = "/etc/sysconfig/atd"
                            ... 5 million more /incl nodes ..
                            /excl = "*~"
                            /excl = "*.rpmsave"
                            ...
        

To load only a specific file (or a few files), you'd call aug_init
setting a flag AUG_NO_DEFAULT_LOAD to keep it from parsing the files it
usually would. Then you'd do something like

        aug_rm(aug, "/augeas/transform/*");
        aug_set(aug, "/augeas/transform/Mytransform/lens", "Foo.lns");
        aug_set(aug, "/augeas/transform/Mytransform/incl", "/etc/foo");
        
to get rid of the default settings for parsing files, and set things up
to process /etc/foo with Foo.lns. I need to add another API call to then
actually cause the parsing of files:

        aug_load(aug);

which will go through the entries in /augeas/transform and parse files.

I am not entirely clear on what the exact effect of aug_load should be,
but I think it will throw away anything under /files (including unsaved
changes), and recreate that part of the tree from scratch.

David

> [0] https://fedorahosted.org/augeas/ticket/42
[1] http://people.redhat.com/dlutter/netcf/

David






More information about the augeas-devel mailing list