[augeas-devel] First tests with aug mv

Raphaël Pinson raphink at gmail.com
Tue Jul 29 11:04:45 UTC 2008


Hi there,

David implemented the "mv" function yesterday so I'm playing a bit with it
today.


============================================================
module CommentTest =

   autoload xfm

   let c_key (kw:string) = Util.del_str kw . label ("." . kw)

   let entry   = [ key "field" . Util.del_str "=" . store /.*/ .
Util.del_str "\n" ]
   let c_entry = [ Util.del_str "#" . c_key "field" . Util.del_str "=" .
store /.*/ . Util.del_str "\n" ]

   let lns = (entry | c_entry)*


   let filter = (incl "/commenttest")

   let xfm = transform lns filter
============================================================

$ cat fakeroot/commenttest
field=toto
field=titi

$ augtool -I . -r fakeroot/
augtool> print /files/commenttest/
/files/commenttest
/files/commenttest/field[1] = "toto"
/files/commenttest/field[2] = "titi"
augtool> mv /files/commenttest/field[1] /files/commenttest/.field
augtool> save
augeas.c:908 Fixme: Multiple transforms for /files
augeas.c:908 Fixme: Multiple transforms for /files
Saving failed
augtool> quit

 $ cat fakeroot/commenttest
field=titi
#field=toto

============================================================


There's a few things to note here:
* mv works ! Thank you David :)
* save works but is not happy :(
* "field=toto" got moved from 1st place to 2nd placed when it got commented.
This is a side effect to this (un)commenting method I hadn't considered.
* dealing with key in the lens is quite tricky. While it's possible to
declare a c_key function, it will only take a string, since the contents of
Util.del_str kw cannot be assigned to label currently. The following will
NOT work:

============================================================
let entry_gen (kw:string) = [ key kw . Util.del_str "=" . store /.*/ .
Util.del_str "\n" ]
let c_entry_gen (kw:string) = [ Util.del_str "#" . c_key kw . Util.del_str
"=" . store /.*/ . Util.del_str "\n" ]

let field = "field1"
            | "field2"

let entry = entry_gen field
let c_entry = c_entry_gen field
============================================================

The reason why it doesn't work is quite obvious: field is not a string, but
a regexp. For it to work, entry_gen and c_entry_gen would have to take
regexps instead of strings, but then c_key would have to take a regexp, too,
which is not possible.



Just a few thoughts...



Raphaël
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20080729/39bea71b/attachment.htm>


More information about the augeas-devel mailing list