[augeas-devel] How to insert empty nodes in Augeas trees?

Raphaël Pinson raphael.pinson at camptocamp.com
Tue Dec 22 15:40:05 UTC 2015


On Tue, Dec 22, 2015 at 4:36 PM, Mol, Xavier (SCC) <xavier.mol at kit.edu>
wrote:

> Hi Raphael.
>
>
>
> > How about something like this:
>
> >    let token = (mapping | pwdrecord | record_nobreak)* . (mapping |
> pwdrecord | record_nobreak)
>
> How is that different from this token definition?
>
>
>
> let token = (mapping | pwdrecord | record_nobreak)+
>
>
>
> And how does record_nobreak look for you? If it is record as I have
> defined it without break at its end, then I don't think that will work.
> Evectively record_nobreak then assumes that all lines/nodes, that are not
> matched by either Util.empty, Util.comment, mapping or pwdrecord belong to
> a record_nobreak node. Did I understand you right?
>
>
>


My bad, I meant:


     let token = (mapping | pwdrecord | record_break)* . (mapping |
pwdrecord | record_nobreak)



Raphaël



>
>
>
>
>
>
> *From:* Raphaël Pinson [mailto:raphael.pinson at camptocamp.com]
> *Sent:* Tuesday, December 22, 2015 4:28 PM
>
> *To:* Mol, Xavier (SCC)
> *Cc:* augeas-devel at redhat.com
> *Subject:* Re: [augeas-devel] How to insert empty nodes in Augeas trees?
>
>
>
>
>
>
>
> On Tue, Dec 22, 2015 at 2:32 PM, Mol, Xavier (SCC) <xavier.mol at kit.edu>
> wrote:
>
> Hi Raphael,
>
>
>
> a concrete example snippet might look similar to what I've done with the
> unit tests (see test_kpwd.aug in attachements). The important lens in this
> context is called 'record' in kpwd.aug. That lens has to consume an unknown
> number of lines from a configuration file, until it encounters a blank
> line. At first I was looking for Util.empty, which worked fine, until I
> wanted to code a put unit test, hence the inquery of how to include empty
> nodes in an Augeas tree. After all, the better solution was to look for two
> line breaks (Util.eol . del "\n" "\n"), which doesn't generate, nor require
> empty nodes in the Augeas tree.
>
>
>
> Then you brought up that we might encounter the end of a file, instead of
> line breaks, which I don't know how to handle with Augeas parsing. Because
> of that very issue, all of my custom lenses require each configuration file
> to end on a new line. Simply making the eol optional causes a lot of
> ambiguities and eof doesn't have a string representation, so there is no
> regular expression for matching it explicitly. Unless you know something
> that I don't. J
>
>
>
>
>
>
>
> How about something like this:
>
>
>
>
>
>     let token = (mapping | pwdrecord | record_nobreak)* . (mapping |
> pwdrecord | record_nobreak)
>
>
>
>
>
>
>
> Cheers,
>
>
>
> Raphaël
>
>
>
>
>
>
>
> *From:* Raphaël Pinson [mailto:raphael.pinson at camptocamp.com]
> *Sent:* Tuesday, December 22, 2015 2:12 PM
>
>
> *To:* Mol, Xavier (SCC)
> *Cc:* augeas-devel at redhat.com
> *Subject:* Re: [augeas-devel] How to insert empty nodes in Augeas trees?
>
>
>
> Do you have concrete examples of what you're trying to achieve, so I
> understand better?
>
>
>
> On Tue, Dec 22, 2015 at 2:05 PM, Mol, Xavier (SCC) <xavier.mol at kit.edu>
> wrote:
>
> Hi Raphael,
>
>
>
> no, I need an empty line after Uitl.eol, before any other text. But you
> bring up an interesting point, that my lens doesn't recognize the end of a
> file, which could be accepted all the same, without requiring an actual
> empty line. But how can I match the end of a file?
>
>
>
> Ciao,
>
> Xavier.
>
>
>
> *From:* Raphaël Pinson [mailto:raphael.pinson at camptocamp.com]
> *Sent:* Tuesday, December 22, 2015 1:31 PM
>
>
> *To:* Mol, Xavier (SCC)
> *Cc:* augeas-devel at redhat.com
> *Subject:* Re: [augeas-devel] How to insert empty nodes in Augeas trees?
>
>
>
> It's common to end every line with a Util.eol, which defaults to a
> newline. Or do you mean that you need an empty line at the end of the file?
>
>
>
>
>
> Raphaël
>
>
>
> On Tue, Dec 22, 2015 at 12:58 PM, Mol, Xavier (SCC) <xavier.mol at kit.edu>
> wrote:
>
> Hi Raphael, all,
>
>
>
> some more finding about this…
>
>
>
> Neither 'touch', nor 'rename' can be used during a put unit test. Also,
> relying on Augeas users to do this just to insert a line break, which is
> required for a valid configuration file, is ugly and error prone. This
> workaround still may be used to add additional empty lines to a
> configuration file just to improve readability (where they don't break
> anything), so still a useful lesson. Though for my custom lens, I have
> decided to look for and create empty lines by default, as with any string
> literal. This way, the Augeas tree doesn't need to feature empty nodes and
> empty lines will be added in put direction automatically.
>
>
>
> Thank you again for your time,
>
> Xavier.
>
>
>
> *From:* augeas-devel-bounces at redhat.com [mailto:
> augeas-devel-bounces at redhat.com] *On Behalf Of *Mol, Xavier (SCC)
> *Sent:* Tuesday, December 22, 2015 10:27 AM
> *To:* Raphaël Pinson
>
>
> *Cc:* augeas-devel at redhat.com
> *Subject:* Re: [augeas-devel] How to insert empty nodes in Augeas trees?
>
>
>
> Hi Raphael,
>
>
>
> thank you again for your quick and helpful reply!
>
>
>
> Ciao,
>
> Xavier.
>
>
>
> *From:* Raphaël Pinson [mailto:raphael.pinson at camptocamp.com
> <raphael.pinson at camptocamp.com>]
> *Sent:* Tuesday, December 22, 2015 10:25 AM
> *To:* Mol, Xavier (SCC)
> *Cc:* augeas-devel at redhat.com
> *Subject:* Re: [augeas-devel] How to insert empty nodes in Augeas trees?
>
>
>
> Hello Xavier,
>
>
>
>
>
> I was going to say that was not possible, but I actually (to my great
> surprise) found a way to do it:
>
>
>
>     augtool> touch /files/etc/fstab/01
>
>     augtool> rename /files/etc/fstab/01 ""
>
>     rename : /files/etc/fstab/01 to  1
>
>     augtool> save
>
>     Saved 1 file(s)
>
>
>
> Just added an empty line at the end of /etc/fstab
>
>
>
>
>
> Cheers,
>
>
>
> Raphaël
>
>
>
>
>
>
>
> On Tue, Dec 22, 2015 at 10:06 AM, Mol, Xavier (SCC) <xavier.mol at kit.edu>
> wrote:
>
> Hello Augeas experts,
>
> is there a way to insert empty nodes in an Augeas tree? I've made a lens,
> that expects an empty line as last part (Util.empty), which works fine with
> existing files. However, when inserting a new node in the tree with that
> lens, the closing empty line is missing. Do I need to have a labelled node
> in the tree without value or children, that simply puts an empty line in
> the resulting string instead?
>
> Thank you for your time,
> Xavier.
>
> ****
> Karlsruher Institute of Technology (KIT)
> Steinbuch Centre for Computing (SCC)
>
> B. Sc. Xavier Mol
> GridKa Storage Administrator and Support Manager
>
> Hermann-von-Helmholtz-Platz 1
> Geb. 449
> 76344 Eggenstein-Leopoldshafen
> Phone: +49 721 608 23041
> Email: xavier.mol at kit.edu
> www.kit.edu
> KIT - University of the State of Baden-Württemberg and National
> Large-scale Research Center of the Helmholtz Association
> "Since 2010, the KIT has been certified as a family-friendly university."
> ****
>
>
> _______________________________________________
> augeas-devel mailing list
> augeas-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/augeas-devel
>
>
>
>
>
> --
>
> Raphaël Pinson
>
> Infrastructure Developer & Training Leader
>
> +33 458 482 013
>
>
>
> Camptocamp France
> Savoie Technolac
> BP 352
> 48, avenue du Lac du Bourget
> 73372 Le Bourget du Lac, Cedex
> www.camptocamp.com
>
>
>
>
>
> --
>
> Raphaël Pinson
>
> Infrastructure Developer & Training Leader
>
> +33 458 482 013
>
>
>
> Camptocamp France
> Savoie Technolac
> BP 352
> 48, avenue du Lac du Bourget
> 73372 Le Bourget du Lac, Cedex
> www.camptocamp.com
>
>
>
>
>
> --
>
> Raphaël Pinson
>
> Infrastructure Developer & Training Leader
>
> +33 458 482 013
>
>
>
> Camptocamp France
> Savoie Technolac
> BP 352
> 48, avenue du Lac du Bourget
> 73372 Le Bourget du Lac, Cedex
> www.camptocamp.com
>
>
>
>
>
>
>
>
>
>
> --
>
> Raphaël Pinson
>
> Infrastructure Developer & Training Leader
>
> +33 458 482 013
>
>
>
> Camptocamp France
> Savoie Technolac
> BP 352
> 48, avenue du Lac du Bourget
> 73372 Le Bourget du Lac, Cedex
> www.camptocamp.com
>


-- 
Raphaël Pinson
Infrastructure Developer & Training Leader
+33 458 482 013

Camptocamp France
Savoie Technolac
BP 352
48, avenue du Lac du Bourget
73372 Le Bourget du Lac, Cedex
www.camptocamp.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20151222/86691689/attachment.htm>


More information about the augeas-devel mailing list