On Fri, Jul 11, 2008 at 12:13 PM, Raphaël Pinson <<a href="mailto:raphink@gmail.com">raphink@gmail.com</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>As for other lenses, I sometimes fail to insert values before paths. E.g.<br><br>====================================================<br>augtool> print /files/etc/logrotate.d/apache2/<br>
/files/etc/logrotate.d/apache2<br>/files/etc/logrotate.d/apache2/rule = "/var/log/apache2/*.log"<br>/files/etc/logrotate.d/apache2/rule/schedule = "weekly"<br>/files/etc/logrotate.d/apache2/rule/missingok = "missingok"<br>

/files/etc/logrotate.d/apache2/rule/rotate = "52"<br>/files/etc/logrotate.d/apache2/rule/compress = "compress"<br>/files/etc/logrotate.d/apache2/rule/delaycompress = "delaycompress"<br>/files/etc/logrotate.d/apache2/rule/ifempty = "notifempty"<br>

/files/etc/logrotate.d/apache2/rule/create<br>/files/etc/logrotate.d/apache2/rule/create/mode = "640"<br>/files/etc/logrotate.d/apache2/rule/create/owner = "root"<br>/files/etc/logrotate.d/apache2/rule/create/group = "adm"<br>

/files/etc/logrotate.d/apache2/rule/sharedscripts<br>/files/etc/logrotate.d/apache2/rule/postrotate<br>/files/etc/logrotate.d/apache2/rule/postrotate/line[1] = "if [ -f /var/run/apache2.pid ]; then"<br>/files/etc/logrotate.d/apache2/rule/postrotate/line[2] = "/etc/init.d/apache2 restart > /dev/null"<br>

/files/etc/logrotate.d/apache2/rule/postrotate/line[3] = "fi"<br>augtool> ins schedule before /files/etc/logrotate.d/apache2/rule/postrotate<br>augtool> print /files/etc/logrotate.d/apache2/<br>/files/etc/logrotate.d/apache2<br>

/files/etc/logrotate.d/apache2/rule = "/var/log/apache2/*.log"<br>/files/etc/logrotate.d/apache2/rule/schedule[1] = "weekly"<br>/files/etc/logrotate.d/apache2/rule/missingok = "missingok"<br>

/files/etc/logrotate.d/apache2/rule/rotate = "52"<br>/files/etc/logrotate.d/apache2/rule/compress = "compress"<br>/files/etc/logrotate.d/apache2/rule/delaycompress = "delaycompress"<br>/files/etc/logrotate.d/apache2/rule/ifempty = "notifempty"<br>

/files/etc/logrotate.d/apache2/rule/create<br>/files/etc/logrotate.d/apache2/rule/create/mode = "640"<br>/files/etc/logrotate.d/apache2/rule/create/owner = "root"<br>/files/etc/logrotate.d/apache2/rule/create/group = "adm"<br>

/files/etc/logrotate.d/apache2/rule/sharedscripts<br>/files/etc/logrotate.d/apache2/rule/schedule[2]<br>/files/etc/logrotate.d/apache2/rule/postrotate<br>/files/etc/logrotate.d/apache2/rule/postrotate/line[1] = "if [ -f /var/run/apache2.pid ]; then"<br>

/files/etc/logrotate.d/apache2/rule/postrotate/line[2] = "/etc/init.d/apache2 restart > /dev/null"<br>/files/etc/logrotate.d/apache2/rule/postrotate/line[3] = "fi"<br>augtool> set /files/etc/logrotate.d/apache2/rule/schedule[2] "daily"<br>

augtool> print /files/etc/logrotate.d/apache2/<br>/files/etc/logrotate.d/apache2<br>/files/etc/logrotate.d/apache2/rule = "/var/log/apache2/*.log"<br>/files/etc/logrotate.d/apache2/rule/schedule[1] = "weekly"<br>

/files/etc/logrotate.d/apache2/rule/missingok = "missingok"<br>/files/etc/logrotate.d/apache2/rule/rotate = "52"<br>/files/etc/logrotate.d/apache2/rule/compress = "compress"<br>/files/etc/logrotate.d/apache2/rule/delaycompress = "delaycompress"<br>

/files/etc/logrotate.d/apache2/rule/ifempty = "notifempty"<br>/files/etc/logrotate.d/apache2/rule/create<br>/files/etc/logrotate.d/apache2/rule/create/mode = "640"<br>/files/etc/logrotate.d/apache2/rule/create/owner = "root"<br>

/files/etc/logrotate.d/apache2/rule/create/group = "adm"<br>/files/etc/logrotate.d/apache2/rule/sharedscripts<br>/files/etc/logrotate.d/apache2/rule/schedule[2] = "daily"<br>/files/etc/logrotate.d/apache2/rule/postrotate<br>

/files/etc/logrotate.d/apache2/rule/postrotate/line[1] = "if [ -f /var/run/apache2.pid ]; then"<br>/files/etc/logrotate.d/apache2/rule/postrotate/line[2] = "/etc/init.d/apache2 restart > /dev/null"<br>

/files/etc/logrotate.d/apache2/rule/postrotate/line[3] = "fi"<br><br>This works so far. Now if I try to insert in the beginning of the file ...<br><br>augtool> ins schedule before /files/etc/logrotate.d/apache2/rule<br>

augtool> print /files/etc/logrotate.d/apache2/<br>/files/etc/logrotate.d/apache2<br>/files/etc/logrotate.d/apache2/rule = "/var/log/apache2/*.log"<br>/files/etc/logrotate.d/apache2/rule/schedule[1] = "weekly"<br>

/files/etc/logrotate.d/apache2/rule/missingok = "missingok"<br>/files/etc/logrotate.d/apache2/rule/rotate = "52"<br>/files/etc/logrotate.d/apache2/rule/compress = "compress"<br>/files/etc/logrotate.d/apache2/rule/delaycompress = "delaycompress"<br>

/files/etc/logrotate.d/apache2/rule/ifempty = "notifempty"<br>/files/etc/logrotate.d/apache2/rule/create<br>/files/etc/logrotate.d/apache2/rule/create/mode = "640"<br>/files/etc/logrotate.d/apache2/rule/create/owner = "root"<br>

/files/etc/logrotate.d/apache2/rule/create/group = "adm"<br>/files/etc/logrotate.d/apache2/rule/sharedscripts<br>/files/etc/logrotate.d/apache2/rule/schedule[2] = "daily"<br>/files/etc/logrotate.d/apache2/rule/postrotate<br>

/files/etc/logrotate.d/apache2/rule/postrotate/line[1] = "if [ -f /var/run/apache2.pid ]; then"<br>/files/etc/logrotate.d/apache2/rule/postrotate/line[2] = "/etc/init.d/apache2 restart > /dev/null"<br>

/files/etc/logrotate.d/apache2/rule/postrotate/line[3] = "fi"<br><br>I don't see the schedule entry, but in the end of the file :<br><br>augtool> ins schedule after /files/etc/logrotate.d/apache2/rule<br>

augtool> print /files/etc/logrotate.d/apache2/<br>/files/etc/logrotate.d/apache2<br>/files/etc/logrotate.d/apache2/rule = "/var/log/apache2/*.log"<br>/files/etc/logrotate.d/apache2/rule/schedule[1] = "weekly"<br>

/files/etc/logrotate.d/apache2/rule/missingok = "missingok"<br>/files/etc/logrotate.d/apache2/rule/rotate = "52"<br>/files/etc/logrotate.d/apache2/rule/compress = "compress"<br>/files/etc/logrotate.d/apache2/rule/delaycompress = "delaycompress"<br>

/files/etc/logrotate.d/apache2/rule/ifempty = "notifempty"<br>/files/etc/logrotate.d/apache2/rule/create<br>/files/etc/logrotate.d/apache2/rule/create/mode = "640"<br>/files/etc/logrotate.d/apache2/rule/create/owner = "root"<br>

/files/etc/logrotate.d/apache2/rule/create/group = "adm"<br>/files/etc/logrotate.d/apache2/rule/sharedscripts<br>/files/etc/logrotate.d/apache2/rule/schedule[2] = "daily"<br>/files/etc/logrotate.d/apache2/rule/postrotate<br>

/files/etc/logrotate.d/apache2/rule/postrotate/line[1] = "if [ -f /var/run/apache2.pid ]; then"<br>/files/etc/logrotate.d/apache2/rule/postrotate/line[2] = "/etc/init.d/apache2 restart > /dev/null"<br>

/files/etc/logrotate.d/apache2/rule/postrotate/line[3] = "fi"<br>/files/etc/logrotate.d/apache2/schedule<br>augtool> set /files/etc/logrotate.d/apache2/schedule "weekly"<br>augtool> print /files/etc/logrotate.d/apache2/<br>

/files/etc/logrotate.d/apache2<br>/files/etc/logrotate.d/apache2/rule = "/var/log/apache2/*.log"<br>/files/etc/logrotate.d/apache2/rule/schedule[1] = "weekly"<br>/files/etc/logrotate.d/apache2/rule/missingok = "missingok"<br>

/files/etc/logrotate.d/apache2/rule/rotate = "52"<br>/files/etc/logrotate.d/apache2/rule/compress = "compress"<br>/files/etc/logrotate.d/apache2/rule/delaycompress = "delaycompress"<br>/files/etc/logrotate.d/apache2/rule/ifempty = "notifempty"<br>

/files/etc/logrotate.d/apache2/rule/create<br>/files/etc/logrotate.d/apache2/rule/create/mode = "640"<br>/files/etc/logrotate.d/apache2/rule/create/owner = "root"<br>/files/etc/logrotate.d/apache2/rule/create/group = "adm"<br>

/files/etc/logrotate.d/apache2/rule/sharedscripts<br>/files/etc/logrotate.d/apache2/rule/schedule[2] = "daily"<br>/files/etc/logrotate.d/apache2/rule/postrotate<br>/files/etc/logrotate.d/apache2/rule/postrotate/line[1] = "if [ -f /var/run/apache2.pid ]; then"<br>

/files/etc/logrotate.d/apache2/rule/postrotate/line[2] = "/etc/init.d/apache2 restart > /dev/null"<br>/files/etc/logrotate.d/apache2/rule/postrotate/line[3] = "fi"<br>/files/etc/logrotate.d/apache2/schedule = "weekly"<br>

<br><br>It works... Any idea anyone ?<br><br></blockquote><div><br>I should precise that my apache2 file has no empty line in the beginning.<br><br>If I add an empty line in the beginning of the file, I am able to insert data before the rule...<br>
<br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>====================================================<div class="Ih2E3d"><br>
<br>(* Logrotate module for Augeas                *)<br>(* Author: Raphael Pinson <<a href="mailto:raphink@gmail.com" target="_blank">raphink@gmail.com</a>> *)<br>
(*                                            *)<br>(* Supported :                                *)<br>(*   - defaults                               *)<br>(*   - rules                                  *)<br>(*   - postrotate entries                     *)<br>

(*                                            *)<br>(* Todo :                                     *)<br>(*                                            *)<br><br>module Logrotate =<br>   autoload xfm<br><br>   let sep_spc = Util.del_ws_spc<br>
</div><div class="Ih2E3d">
   let eol = Util.del_str "\n"<br>   let num = /[0-9]+/<br>   let word = /[^,# \n\t{}]+/<br><br><br>   (* define comments and empty lines *)<br></div>   let comment (indent:string) = [ label "comment" . Util.del_str indent . del /#[ \t]*/ "# " .  store /([^ \t\n][^\n]*)?/ . eol ]<div class="Ih2E3d">
<br>
   let empty   = [ del /[ \t]*\n/ "" ]<br><br><br>   (* Useful functions *)<br><br></div>   let select_to_eol (kw:string) (select:regexp) (indent:string) = [ Util.del_str indent . label kw . store select . eol ]<br>
   let value_to_eol (kw:string) (value:regexp) (indent:string )  = [ Util.del_str indent . key kw . sep_spc . store value . eol ]<br>
   let flag_to_eol (kw:string) (indent:string)                   = [ Util.del_str indent . key kw . eol ]<br><br><br>   (* Defaults *)<br><br>   let create (indent:string ) = [ Util.del_str indent . key "create" .<div class="Ih2E3d">
<br>
                       ( sep_spc . [ label "mode" . store num ] . sep_spc .<br>                       [ label "owner" . store word ] . sep_spc .<br>                       [ label "group" . store word ])?<br>

                    . eol ]<br><br></div>   let attrs (indent:string) = select_to_eol "schedule" /(daily|weekly|monthly)/ indent<br>                | value_to_eol "rotate" num indent<br>                | create indent<br>

                | flag_to_eol "nocreate" indent<br>                | value_to_eol "include" word indent<br>                | select_to_eol "missingok" /(no)?missingok/ indent<br>                | select_to_eol "compress" /(no)?compress/ indent<br>

                | select_to_eol "delaycompress" /(no)?delaycompress/ indent<br>                | select_to_eol "ifempty" /(not)?ifempty/ indent<br>                | flag_to_eol "sharedscripts" indent<br>

                | value_to_eol "size" word indent<br>                | value_to_eol "tabooext" word indent<br>                | value_to_eol "olddir" word indent<br>                | flag_to_eol "noolddir" indent<br>

                | value_to_eol "mail" word indent<br>                | flag_to_eol "mailfirst" indent<br>                | flag_to_eol "maillast" indent<br>                | flag_to_eol "nomail" indent<br>

                | value_to_eol "errors" word indent<br>                | value_to_eol "extension" word indent<div class="Ih2E3d"><br><br><br>   (* Define hooks *)<br><br>   let endscript_re = /[ \t]*endscript[ \t]*/<br>
   let hook_func (func_type:string) = [<br>
        del /[ \t]*/ "\t" . key func_type . eol .<br>          [ label "line" . del /[ \t]*/ "" . store (/([^ \t\n][^\n]*)?/ - endscript_re) . eol ]* .<br>        del (endscript_re . "\n") "\tendscript\n" ]<br>

<br></div><div class="Ih2E3d">   let hooks = hook_func "postrotate"<br>             | hook_func "prerotate"<br><br><br>   (* Define rule *)<br><br></div>   let body = Util.del_str "{\n"<br>                       . ( comment "\t" | attrs "\t" | hooks | empty )*<div class="Ih2E3d">
<br>
                       . Util.del_str "}\n"<br><br>   let rule =<br></div>     [ label "rule" . store word . (sep_spc)? . eol? . body ]<div class="Ih2E3d"><br><br><br>   let lns = ( comment "" | empty | attrs "" | rule )*<br>

<br>   let filter = incl "/etc/logrotate.d/*"<br>              . incl "/etc/logrotate.conf"<br>              . Util.stdexcl<br><br>   let xfm = transform lns filter<br><br></div>====================================================<br>
<font color="#888888">
<br><br><br>Raphaël</font><div><div></div><div class="Wj3C7c"><br><br><br><br><div class="gmail_quote">On Wed, Jul 9, 2008 at 11:00 PM, David Lutterkort <<a href="mailto:lutter@watzmann.net" target="_blank">lutter@watzmann.net</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>On Wed, 2008-07-09 at 11:17 +0200, Raphaël Pinson wrote:<br>
> Here are the new versions of logrotate.aug and test_logrotate.aug<br>
><br>
> Notes :<br>
>    - I switched back from seq to label for the hook_func lines,<br>
> because seq would keep increasing the line numbers outside of the<br>
> context, i.e. postrotate/1, postrotate/2, prerotate/3, prerotate/4,<br>
> etc., which doesn't make sense. label on the other hand doesn't act<br>
> this way. Is this a bug in seq ?<br>
<br>
</div>When you say 'seq "foo"' you are using a global sequence "foo" that<br>
keeps increasing while a file is being read. You can reset that sequence<br>
by using 'counter "foo"', so if you have something like<br>
<br>
        [ counter "foo" . stuff . [ seq "foo" . more stuff ]* ]*<br>
<br>
the inner [ .. ] will start counting from 1 everytime (without the<br>
'counter' it keeps increasing globally)<br>
<br>
Generally, using a fixed label is preferrable IMHO; the difference<br>
between one and the other is subtle and has to do with how deleted stuff<br>
is restored: if you use 'seq', the deleted stuff is tied to that exact<br>
numeric label, and if you delete node 5, the other nodes will keep their<br>
exact formatting. When you use 'label "bar"', then deleting 'bar[5]'<br>
will restore the old bar[6] with the deleted things from the deleted<br>
bar[5] etc.<br>
<div><br>
>    - I didn't touch the sep_tab issue yet<br>
<br>
</div>Ok .. that should be a relatively easy fix. Once that's done, I think<br>
it's ready to be committed.<br>
<div><br>
<br>
>    (* Define hooks *)<br>
><br>
>    let endscript_re = /[ \t]*endscript[ \t]*/<br>
>    let hook_func (func_type:string) = [<br>
>         del /[ \t]*/ "\t" . key func_type . eol .<br>
>           [ label "line" . del /[ \t]*/ "" . store (/([^ \t\n][^<br>
> \n]*)?/ - endscript_re) . eol ]* .<br>
>         del (endscript_re . "\n") "\tendscript\n" ]<br>
<br>
</div>Actually, thinking about this more, why not suck the whole script into<br>
one node instead of splitting it into individual lines ?<br>
<font color="#888888"><br>
David<br>
<br>
<br>
</font></blockquote></div><br>
</div></div></blockquote></div><br>