[augeas-devel] Re: A few lenses... [logrotate.aug]
David Lutterkort
dlutter at redhat.com
Mon Jul 14 20:33:28 UTC 2008
On Fri, 2008-07-11 at 12:13 +0200, Raphaël Pinson wrote:
> As for other lenses, I sometimes fail to insert values before paths.
> ...
> augtool> ins schedule before /files/etc/logrotate.d/apache2/rule
>
> I don't see the schedule entry, but in the end of the file :
Not sure what's going wrong there; looks like a bug. I'll have to look
into that.
Some more things I noticed from playing with the file:
> (* Useful functions *)
>
> let select_to_eol (kw:string) (select:regexp) (indent:string) =
> [ Util.del_str indent . label kw . store select . eol ]
> let value_to_eol (kw:string) (value:regexp) (indent:string ) =
> [ Util.del_str indent . key kw . sep_spc . store value . eol ]
> let flag_to_eol (kw:string) (indent:string) =
> [ Util.del_str indent . key kw . eol ]
With that, select_to_eol and the other functions will only accept
entries that have exactly 'indent' as indentation. I think what you want
is 'del /[ \t]*/ indent' instead of the 'Util.del_str indent' in all of
them, so that even if indent defaults to a tab, you accept entries that
are indented with a few spaces.
There were a couple mroe places where I had to make that change (e.g. in
create)
> (* Define hooks *)
>
> let endscript_re = /[ \t]*endscript[ \t]*/
> let hook_func (func_type:string) = [
> del /[ \t]*/ "\t" . key func_type . eol .
> [ label "line" . del /[ \t]*/ "" . store (/([^ \t\n][^
> \n]*)?/ - endscript_re) . eol ]* .
> del (endscript_re . "\n") "\tendscript\n" ]
>
> let hooks = hook_func "postrotate"
> | hook_func "prerotate"
I think it would be better to read the whole script into a single node,
instead of splitting it into lines. There's not much to be gained from
splitting the script up.
>
> (* Define rule *)
>
> let body = Util.del_str "{\n"
> . ( comment "\t" | attrs "\t" | hooks |
> empty )*
> . Util.del_str "}\n"
>
> let rule =
> [ label "rule" . store word . (sep_spc)? . eol? . body ]
You should replace the '(sep_spc)? . eol?' with 'del /[ \t\n]*/ " "' -
it's a little simpler to read.
Also, a rule for logrotate can specify multiple files, e.g.
"/var/log/httpd/access.log" /var/log/httpd/error.log {
...
}
is legal. Something like
let rule = [ label "rule" .
[ label "file" . store word ] .
[ del /[ \t]+/ " " . label "file" . store word ]* .
del /[ \t\n]*/ " " . body ]
puts each file name into a separate 'file' node underneath 'rule'.
I attach the latest version with my changes.
David
-------------- next part --------------
(* Logrotate module for Augeas *)
(* Author: Raphael Pinson <raphink at gmail.com> *)
(* *)
(* Supported : *)
(* - defaults *)
(* - rules *)
(* - postrotate entries *)
(* *)
(* Todo : *)
(* *)
module Logrotate =
autoload xfm
let sep_spc = Util.del_ws_spc
let eol = Util.del_str "\n"
let num = /[0-9]+/
let word = /[^,# \n\t{}]+/
(* define comments and empty lines *)
let comment (indent:string) = [ label "comment" . del /[ \t]*/ indent .
del /#[ \t]*/ "# " . store /([^ \t\n][^\n]*)?/ . eol ]
let empty = [ del /[ \t]*\n/ "" ]
(* Useful functions *)
let select_to_eol (kw:string) (select:regexp) (indent:string) = [
del /[ \t]*/ indent . label kw . store select . eol ]
let value_to_eol (kw:string) (value:regexp) (indent:string ) = [
del /[ \t]*/ indent . key kw . sep_spc . store value . eol ]
let flag_to_eol (kw:string) (indent:string) = [
del /[ \t]*/ indent . key kw . eol ]
(* Defaults *)
let create (indent:string ) = [ del /[ \t]*/ indent . key "create" .
( sep_spc . [ label "mode" . store num ] . sep_spc .
[ label "owner" . store word ] . sep_spc .
[ label "group" . store word ])?
. eol ]
let attrs (indent:string) = select_to_eol "schedule" /(daily|weekly|monthly)/ indent
| value_to_eol "rotate" num indent
| create indent
| flag_to_eol "nocreate" indent
| value_to_eol "include" word indent
| select_to_eol "missingok" /(no)?missingok/ indent
| select_to_eol "compress" /(no)?compress/ indent
| select_to_eol "delaycompress" /(no)?delaycompress/ indent
| select_to_eol "ifempty" /(not)?ifempty/ indent
| flag_to_eol "sharedscripts" indent
| value_to_eol "size" word indent
| value_to_eol "tabooext" word indent
| value_to_eol "olddir" word indent
| flag_to_eol "noolddir" indent
| value_to_eol "mail" word indent
| flag_to_eol "mailfirst" indent
| flag_to_eol "maillast" indent
| flag_to_eol "nomail" indent
| value_to_eol "errors" word indent
| value_to_eol "extension" word indent
| flag_to_eol "dateext" indent
(* Define hooks *)
let endscript_re = /[ \t]*endscript[ \t]*/
let hook_func (func_type:string) = [
del /[ \t]*/ "\t" . key func_type . eol .
[ label "line" . del /[ \t]*/ "" . store (/([^ \t\n][^\n]*)?/ -
endscript_re) . eol ]* .
del (endscript_re . "\n") "\tendscript\n" ]
let hooks = hook_func "postrotate"
| hook_func "prerotate"
(* Define rule *)
let body = Util.del_str "{\n"
. ( comment "\t" | attrs "\t" | hooks | empty )*
. Util.del_str "}\n"
let rule = [ label "rule" .
[ label "file" . store word ] .
[ del /[ \t]+/ " " . label "file" . store word ]* .
del /[ \t\n]*/ " " . body ]
let lns = ( comment "" | empty | attrs "" | rule )*
let filter = incl "/etc/logrotate.d/*"
. incl "/etc/logrotate.conf"
. Util.stdexcl
let xfm = transform lns filter
More information about the augeas-devel
mailing list