[augeas-devel] [PATCH] Modify aliases, exports, fstab, group and monit to use new generic
Raphaël Pinson
raphink at gmail.com
Mon Mar 30 20:56:22 UTC 2009
From: Raphaël Pinson <raphink at raphink.net>
---
lenses/aliases.aug | 13 +++++++------
lenses/exports.aug | 19 ++++++++++---------
lenses/fstab.aug | 15 +++++++++------
lenses/group.aug | 21 ++++++++++-----------
lenses/monit.aug | 17 ++++++++---------
lenses/tests/test_aliases.aug | 9 +++++++--
6 files changed, 51 insertions(+), 43 deletions(-)
diff --git a/lenses/aliases.aug b/lenses/aliases.aug
index 4f7d0cf..44f83b9 100644
--- a/lenses/aliases.aug
+++ b/lenses/aliases.aug
@@ -6,18 +6,19 @@ module Aliases =
let name = /([^ \t\n#:@]+|"[^"\n]*")/ (* " make emacs calm down *)
let colon = del /:[ \t]+/ ":\t"
- let eol = del /[ \t]*\n/ "\n"
+ let eol = Util.eol
- let comment = [ del /^[ \t]*(#.*)?\n/ "#\n" ]
+ let comment = Util.comment
+ let empty = Util.empty
let comma = del /,[ \t]*(\n[ \t]+)?/ ", "
- let alias = [ seq "alias" .
+ let value_list = Build.opt_list ([ label "value" . store word]) comma
+ let alias = [ seq "alias" .
[ label "name" . store name ] . colon .
- [ label "value" . store word ] .
- ([comma . label "value" . store word])*
+ value_list
] . eol
- let lns = (comment | alias)*
+ let lns = (comment | empty | alias)*
let xfm = transform lns (incl "/etc/aliases")
diff --git a/lenses/exports.aug b/lenses/exports.aug
index 499a3af..e666d77 100644
--- a/lenses/exports.aug
+++ b/lenses/exports.aug
@@ -78,19 +78,20 @@ module Exports =
let client_re = /[a-zA-Z0-9\-\.@\*\?\/]+/
- let eol = del /[ \t]*\n/ "\n"
+ let eol = Util.eol
+ let lbracket = Util.del_str "("
+ let rbracket = Util.del_str ")"
+ let sep_com = Sep.comma
+ let sep_spc = Sep.space
let option = [ label "option" . store /[^,)]+/ ]
- let client = [ label "client" . store client_re .
- ( Util.del_str "(" .
- option .
- ( Util.del_str "," . option ) * .
- Util.del_str ")" )? ]
+ let client = [ label "client" . store client_re .
+ ( Build.brackets lbracket rbracket
+ ( Build.opt_list option sep_com ) )? ]
- let entry = [ label "dir" . store /\/[^ \t]*/ .
- Util.del_ws_spc .
- client . (Util.del_ws_spc . client)* . eol ]
+ let entry = [ label "dir" . store /\/[^ \t]*/
+ . sep_spc . Build.opt_list client sep_spc . eol ]
let lns = (Hosts.empty | Hosts.comment | entry)*
diff --git a/lenses/fstab.aug b/lenses/fstab.aug
index 2246026..031f570 100644
--- a/lenses/fstab.aug
+++ b/lenses/fstab.aug
@@ -3,17 +3,20 @@
module Fstab =
autoload xfm
- let sep_tab = Util.del_ws_tab
- let sep_spc = Util.del_ws_spc
- let comma = Util.del_str ","
- let eol = del /[ \t]*\n/ "\n"
+ let sep_tab = Sep.tab
+ let sep_spc = Sep.space
+ let comma = Sep.comma
+ let eol = Util.eol
let comment = Util.comment
let empty = Util.empty
- let word = /[^,# \n\t]+/
+ let word = Rx.neg1
+
let comma_sep_list (l:string) =
- [ label l . store word ] . ([comma . label l . store word])*
+ let lns = [ label l . store word ] in
+ Build.opt_list lns comma
+
let record = [ seq "mntent" .
[ label "spec" . store word ] . sep_tab .
[ label "file" . store word ] . sep_tab .
diff --git a/lenses/group.aug b/lenses/group.aug
index 26bfc61..20f2cae 100644
--- a/lenses/group.aug
+++ b/lenses/group.aug
@@ -17,25 +17,24 @@ let eol = Util.eol
let comment = Util.comment
let empty = Util.empty
-let colon = del ":" ":"
-let comma = del "," ","
+let colon = Sep.colon
+let comma = Sep.comma
-let sto_to_eol = store /([^ \t\n].*[^ \t\n]|[^ \t\n])/
+let sto_to_spc = store Rx.space_in
-let word = /[A-Za-z0-9_.-]+/
-let integer = /[0-9]+/
+let word = Rx.word
+let integer = Rx.integer
(************************************************************************
* ENTRIES
*************************************************************************)
-let user = [ label "user" . store word ]
-let entry = [ key word
- . colon
- . [ label "password" . store word . colon ]
+let user = [ label "user" . store word ]
+let user_list = Build.opt_list user comma
+let params = [ label "password" . store word . colon ]
. [ label "gid" . store integer . colon ]
- . (user . (comma . user)*)?
- . eol ]
+ . user_list?
+let entry = Build.key_value_line word colon params
(************************************************************************
* LENS
diff --git a/lenses/monit.aug b/lenses/monit.aug
index bd4e63e..dde4573 100644
--- a/lenses/monit.aug
+++ b/lenses/monit.aug
@@ -33,29 +33,28 @@ module Monit =
* USEFUL PRIMITIVES
*************************************************************************)
-let eol = Util.eol
-let spc = Util.del_ws_spc
+let spc = Sep.space
let comment = Util.comment
let empty = Util.empty
-let sto_to_eol = store /([^ \t\n].*[^ \t\n]|[^ \t\n])/
-let sto_to_spc = store /[^ \t\n]+/
+let sto_to_spc = store Rx.space_in
+let sto_no_spc = store Rx.no_spaces
-let word = /[A-Za-z0-9_.-]+/
-let value = [ key word . spc . sto_to_eol . eol ]
+let word = Rx.word
+let value = Build.key_value_line word spc sto_to_spc
(************************************************************************
* ENTRIES
*************************************************************************)
(* set statement *)
-let set = [ key "set" . spc . value ]
+let set = Build.key_value "set" spc value
(* include statement *)
-let include = [ key "include" . spc . sto_to_eol . eol ]
+let include = Build.key_value_line "include" spc sto_to_spc
(* service statement *)
-let service = [ key "check" . spc . value . (spc . value)+ ]
+let service = Build.key_value "check" spc (Build.list value spc)
let entry = (set|include|service)
diff --git a/lenses/tests/test_aliases.aug b/lenses/tests/test_aliases.aug
index 63b441b..d052847 100644
--- a/lenses/tests/test_aliases.aug
+++ b/lenses/tests/test_aliases.aug
@@ -14,12 +14,17 @@ daemon: root
adm: root
"
test Aliases.lns get file =
- {} {} {} {} {} (* The comments *)
+ { }
+ { "#comment" = "Aliases in this file will NOT be expanded in the header from" }
+ { "#comment" = "Mail, but WILL be visible over networks or from /bin/mail." }
+ {}
+ { "#comment" = "Basic system aliases -- these MUST be present." }
{ "1" { "name" = "mailer-daemon" }
{ "value" = "postmaster" } }
{ "2" { "name" = "postmaster" }
{ "value" = "root" } }
- {} {}
+ {}
+ { "#comment" = "General redirections for pseudo accounts." }
{ "3" { "name" = "bin" }
{ "value" = "root" }
{ "value" = "adm" } }
--
1.5.6.3
More information about the augeas-devel
mailing list