[augeas-devel] lense problem

Francis Giraldeau francis.giraldeau at usherbrooke.ca
Wed Jun 23 13:03:45 UTC 2010


Le mercredi 23 juin 2010 à 11:45 +0200, Frederic Descamps a écrit : 
> Hello,
> 
> I'm new in the use of augeas and I'm trying to create a lense (for
> radius configuration files)
> 
> I'm not able to create the sections (that are identified by section_name
> { } )

First, you can get the regexp corresponding to the listen lens with this
snipet, before the actual test in test_radius.aug (the second command is
only to get a newline): 

let _ = print_regexp(lens_ctype(Radius.listen))
let _ = print_endline ""

It gaves me this: 

/[\t ]*listen[\t ]+\\{[\t ]*\n([\t ]*type:[\t ]+(auth|proxy|acct|
detail)[\t ]*\n|[\t ]*port:[\t ]+[0-9]+[\t ]*\n|[\t ]*#?[\t ]*
\n|[\t ]*#[\t ]*([^\t\n ].*[^\t\n ]|[^\t\n ])[\t ]*\n)*[\t ]*\\}[\t ]*
\n/

The regexp doesn't match because of "type:" should be "type = ".

I modified slightly the test and it pass, so you can continue, see
joined files, you can replace kvsec1 and kvsec2 and play with it. 

Have a nice day, 

Francis
-------------- next part --------------
module Test_radius = 

    let conf ="prefix = /usr
name = radiusd
# moron comment

confdir = ${raddbdir}
# another moron comment

listen {
        type = auth
        port = 0
}

$INCLUDE sites-enabled
"
let _ = print_regexp(lens_ctype(Radius.listen))
let _ = print_endline ""

    test Radius.lns get conf =
       { "prefix" = "/usr" }
       { "name" = "radiusd" }
       { "#comment" = "moron comment" }
       {}
       { "confdir" = "${raddbdir}" }
       { "#comment" = "another moron comment" }
       {}
       { "listen"
         { "type" = "auth" }
         { "port" = "0" } }
       {}
       { "$INCLUDE" = "sites-enabled" } 
		
-------------- next part --------------
module Radius =
  autoload xfm

  let filter = (incl "/home/fred/sysctl.conf")
             . (incl "/home/fred/radiusd.conf")

  let key_re = /[A-Za-z0-9_.-]+/
  let eq = del /[ \t]*=[ \t]*/ " = "
  let value_re = /[^ \t\n](.*[^ \t\n])?/


  let empty = Util.empty
  let comment = Util.comment
  let dels = Util.del_str
  let eol = Util.eol
  let indent = Util.indent

  let kv = [ indent . key key_re . eq . store value_re . eol ]
  
  let ws = del /[ \t]+/ " "
  let wsc = del /:[ \t]+/ ": "

  let obr = del /\{([ \t]*)\n/ "{\n"
  let cbr = del /[ \t]*}[ \t]*\n/ "}\n"

  let entry = [ indent . key key_re . eq . store value_re . eol ]

  
  let ikey (k:regexp) = indent . key k
  let section (n:regexp) (b:lens) = [ ikey n . ws .obr . (b|empty|comment)* . cbr ]
  let kvsec1 (k:regexp) (v:regexp) = [ ikey k . wsc . store v .eol ]
  let kvsec2 (k:regexp) (v:regexp) = [ ikey k . ws . del "=" "=" . ws . store v .eol ]

  let listen =
        let setting = kvsec2 "type" /auth|proxy|acct|detail/
                     |kvsec2 "port" Rx.integer
                     in section "listen" setting

  let include = [ key "$INCLUDE" . dels " " . store /[^\n]*/ . dels "\n"]


  let lns = (empty | listen | comment | kv | include) *

  let xfm = transform lns filter


More information about the augeas-devel mailing list