[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [augeas-devel] How to write lens so that it can parse empty file.




On Thu, May 31, 2012 at 4:38 PM, Nathaniel Cook <nvcook42 gmail com> wrote:
I have been working on writing a simplified lens for the ganglia
gmetad.conf file. I have the lens working as I like but when I try to
use augeas to add entries to the file I get errors on save if the file
doesn't exist or is empty. It says it cannot parse the entire input:

/augeas/files/etc/gmetad.conf/error = "parse_failed"
/augeas/files/etc/gmetad.conf/error/pos = "0"
/augeas/files/etc/gmetad.conf/error/line = "1"
/augeas/files/etc/gmetad.conf/error/char = "0"
/augeas/files/etc/gmetad.conf/error/lens =
"/usr/share/augeas/lenses/gmetad.aug:22.12-.56:"
/augeas/files/etc/gmetad.conf/error/message = "Get did not match entire input"


Here is the lens:


module Gmetad =
   autoload xfm

   let quote = Util.del_str "\""
   let space = del /[ \t]+/ " "
   let eol = Util.del_str "\n"
   let empty =  del /[ \t]*/ "" . eol

   let host = store /[a-zA-Z0-9._]+/
   let hosts = ( space . [ seq "hosts" . host ] )+
   let group = [ label "group" . quote . store /[a-zA-Z0-9._ ]+/ . quote ]
   let data_source = [ counter "hosts" .  label "data_source" .
Util.del_str "data_source" . space . group . [ label "hosts" . hosts ]
]

   let gridname = [ label "gridname" . Util.del_str "gridname" .
space . quote . store /[a-zA-Z0-9._]+/ . quote ]

   let lns  = (gridname . empty)* . (data_source . empty)*

   let filter = incl "/etc/gmetad.conf"
   let xfm = transform lns filter


Here is the test module:

module Test_gmetad =
   let conf = "gridname \"grid\"
data_source \"group_name\" ds1 ds2 ds3.example.com
data_source \"group_other\" www1 www2 www3.example.com
"
   test Gmetad.lns get  conf =
   { "gridname" = "grid" }
   { "data_source"
           { "group" = "group_name" }
           { "hosts"
               { "1" = "ds1" }
               { "2" = "ds2" }
               { "3" = "ds3.example.com" }
           }
   }
   { "data_source"
       { "group" = "group_other" }
       { "hosts"
           { "1" = "www1" }
           { "2" = "www2" }
           { "3" = "www3.example.com" }
       }
   }

   let empty = ""

   test Gmetad.lns get empty = ?



An empty (or non existent) file is not an empty string, but a single carriage return. The test should thus be:

test Gmetad.lns get "\n" = ?

which fails since the lens cannot parse a single carriage return. This is the reason why it fails in augtool.


Doesn't this format not support empty lines? If it does, I'd advise to use Util.eol in gridname and data_source, and write lns as:

let lns = (gridname | data_source | Util.empty)*

or does the order strictly matter?


Raphaël


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]