[augeas-devel] Creating new files from tree additions

David Lutterkort dlutter at redhat.com
Wed Apr 23 22:43:26 UTC 2008


On Wed, 2008-04-23 at 23:21 +0100, Dean Wilson wrote:
> I've got a lense that reads config files in from a main file and a
> directory full of files (most of which have one line in them)

That works (now) I fixed a bug there yesterday. The new file has to be
in an already existing directory, i.e. when you create a file with
absolute path P, `dirname $P` must be there already; I still need to add
code to do the equivalent of 'mkdir $(dirname $P)'

> By adding leaves to the tree and saving I can add new lines to either
> type of file but I can't seem to make augtool create new files by
> adding new nodes under the directory in the tree. Should I be able to
> do this with augtool?

Yes. I just tried that with new file in /etc/yum.repos.d, which worked;
but for some reason

        set /files/etc/apt/sources.list.d/bar/type deb
        set /files/etc/apt/sources.list.d/bar/uri http://server.com/
        set /files/etc/apt/sources.list.d/bar/distribution etch
        save
        
gives me an empty file, with no indication of error. I am looking into
that.

> Also - is there a 'magic' string I can use to mean 'highest line
> number +1' so I can easily add things from shell scripts without using
> actual numbers. So
> 
> set /files/etc/lines/magic_string/foo
> set /files/etc/lines/magic_string/baz
> set /files/etc/lines/magic_string/bar
> 
> Or should I just use seriously high numbers and treat it the same way?

If the number is part of the path (put there by a 'seq'), then there's
no really good way to get at the highest number; in the tests I just use
'10000' to mean infinity and hope for the best.

If the number comes from distinguishing different nodes with the same
label (e.g., the component nodes for apt sources), you can say something
like 'ins alias after /files/etc/hosts/3/alias[last()]' which puts a new
alias sibling right next to the one that is last now. (And to set it
you, of course refer to it as
'set /files/etc/hosts/3/alias[last()] ...' ;)

I am thinking that I should get rid of using 'seq' in as many places as
possible - it's not possible in all cases, for example AcceptEnv for
sshd_config, but for /etc/hosts-style files should be doable. By
changing the 'seq "hosts"' in the record lens in hosts.aug to 'label
"host"' you'd get each host entry underneath "/files/etc/hosts/host" -
any thoughts on that ?

David




More information about the augeas-devel mailing list