[augeas-devel] Help splitting a key on a slash character

David Lutterkort lutter at redhat.com
Tue May 11 22:12:00 UTC 2010


On Tue, 2010-05-11 at 10:47 -0700, Marc Riddle wrote:
> That was a huge help, I'm very close now, but can't quite seem to get it
> right. Here's what I have right now:

Attached is a modified version of the lens that passes the typechecker
and produces the tree you want.

The main changes I made were
      * Change eol to also eat whitespace and comments before the '\n'
      * Change the definition of value (otherwise the concatenation of
        'store value' and 'eol' is ambiguous). If values can contain
        spaces, you'll need to come up with a slightly more complex
        regexp
      * Process the contents of a 'domainsechead' section within the
        second [key secname] so that the entries go under
        e.g. /domain/LDAP in the tree.

David

-------------- next part --------------
module Sssd =
  autoload xfm

  (* Eat whitespace and comments at end of line *)
  let eol = del /[ \t]*([;#].*)?\n/ "\n"

  let key_re = /[^#;:= \t\n[\/]+/

  let dels (s:string) = del s s

  let eq = del /[ \t]*=[ \t]*/ "="

  let secname = /[^]\/]+/

  let value = /[^#; \t\n]+/

  let comment = [ del /([;#].*)?[ \t]*\n/ "\n" ]

  let kv = [ key key_re . eq . store value . eol ]

  let domainsechead (body:lens) =
    dels "[" . key secname . dels "/" .
     [ key secname . dels "]" . eol . body ]

  let nodomainsechead = dels "[" . key secname . dels "]" . eol

  let entry = comment | kv

  let section = [ domainsechead entry* | nodomainsechead . entry* ]

  let lns = comment* . section*

  let filter = (incl "/etc/sssd/sssd.conf")
      . Util.stdexcl

  let xfm = transform lns filter

   let conf = "
[main]
foo = foobar
[domain/LDAP]
bar = barfoo
"

   test Sssd.lns get conf =
      {}
      { "main"
        { "foo" = "foobar" } }
      { "domain"
        { "LDAP"
         { "bar" = "barfoo" } } }


More information about the augeas-devel mailing list