[augeas-devel] [Interfaces] Draft lense

Raphaël Pinson raphink at gmail.com
Wed Aug 20 17:24:15 UTC 2008


On Wed, Aug 20, 2008 at 7:03 PM, Free Ekanayaka <free at 64studio.com> wrote:

>
>
>  RP> This way, it doesn't affect the rest of the file, but still fixes the
>  RP> mapping issue that you're facing.
>
> Yeah, I thought something like that too, but if you have a
> configuration like:
>
> auto lo eth0
> auto eth1
>
> it would generate a tree like:
>
> { "auto"
>    { "1" = "lo" }
>    { "2" = "eth0" } }
> { "auto"
>    { "1" = "eth1" } }
>
> which is closer to the actual configuration file, but probably less
> parsable than:
>
> { "auto" = "lo" }
> { "auto" = "eth0" }
> { "auto" = "eth1" }
>

If I'm not wrong, this tree would pose a problem on put, because it's not
reversible. From looking at the tree, you can't tell how to represent it
back in the file, so there will be a conflict imo.



> RP> I faced this issue in inifile.aug and bbhosts.aug (and more). You could
> get
>  RP> around it with something like
>
>  RP> let iface      = type "iface" . entry "family" . entry "method" . eol
>  RP>                      . (option|comment|empty)*
>  RP> let mapping = type "mapping" . eol
>  RP>                      . (option|comment|empty)*
>
>  RP> let stanza = iface
>  RP>                 | auto
>  RP>                 | allow_auto
>  RP>                 | allow_hotplug
>  RP>                 | mapping
>  RP> let lns = (comment|empty)* . stanza*
>
> Smart idea, even the placement of the comments in the tree can result
> a little bit odd sometimes. I've modified the lens accordingly and it
> works (below you find the new version of the files). The only problem
> is that I came across a weird bug which I believe is related with
> Util.comment.
>


Yes, the placement can be funny, mostly because you have absolutely no way
to tell whether a comment made before a stanza belongs to the current stanza
or to the next one. I chose to consider that it belongs to the previous one
because it's much easier to parse and it doesn't really matter anyway. If
you're interested in comment management, you can have a look at the wiki on
http://augeas.net/page/Dealing_with_comments which is not really up-to-date.



>
> Basically I have to define my option lens like this:
>
> let option = [  del /[ \t]*/ "   " . key  ( /[abcdefghijklmopqrstuvwxyz-]+/
> - words ) . spc . value_to_eol . eol ]
>
> instead of:
>
> let option = [  del /[ \t]*/ "   " . key  ( /[a-z-]+/ - words ) . spc .
> value_to_eol . eol ]
>
> Note that the former declaration is exactly the same as the latter,
> but it excludes the letter "n", which of course makes the lens fail
> with all options starting with a word containing "n". However the lens
> works beautifully in all other cases.
>
> If I don't exclude the "n" character and declare the option lens with
> the regular [a-z-], I get this error:
>
> lenses/interfaces.aug:27.3-.111:Failed to compile iface
> lenses/interfaces.aug:27.82-.99:exception: overlapping lenses in tree
> union.put
>    Example matched by both: 'comment/'
>    First lens: lenses/interfaces.aug:24.16-.95
>    Second lens: lenses/util.aug:21.4-22.55



>
>
> lenses/interfaces.aug:28.3-.77:Failed to compile mapping
> lenses/interfaces.aug:28.52-.67:exception: overlapping lenses in tree
> union.put
>    Example matched by both: 'comment/'
>    First lens: lenses/interfaces.aug:24.16-.95
>    Second lens: lenses/util.aug:21.4-22.55
>

This is a problem with put. When augeas meets a "comment" node, it doesn't
know if it's an option named "comment" or a comment, hence the conflict. To
fix this and make it clearer, we began to rename the comment nodes into
"#comment" some time ago. My local repository is like this, but it's not
committed into the main repository yet so I forgot to tell you about it. You
can change 'label "comment"' in your util.aug and it should fix the issue.



Ciao


Raphael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20080820/beea3043/attachment.htm>


More information about the augeas-devel mailing list