[augeas-devel] How to write lens so that it can parse empty file.
Nathaniel Cook
nvcook42 at gmail.com
Thu May 31 14:38:09 UTC 2012
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 = ?
The lens can correctly parse the empty string returning a null tree.
Is their something I am doing wrong? I am new at this. Thanks
Nathaniel Cook
More information about the augeas-devel
mailing list