[augeas-devel] [PATCH] Added rsyncd.conf lens and associated test.
Marc Fournier
marc.fournier at camptocamp.com
Tue Dec 23 08:17:46 UTC 2008
rsyncd.conf is an ini file which allows indented parameters (like smb.conf) as
well as entries outside any section (like php.ini). This is just a merge of
bits and pieces taken from these 2 lenses. I would like to thank Raphaël and
Free for their respective work !
---
lenses/rsyncd.aug | 67 ++++++++++++++++++++++++++++++++++++++++++
lenses/tests/test_rsyncd.aug | 56 +++++++++++++++++++++++++++++++++++
2 files changed, 123 insertions(+), 0 deletions(-)
create mode 100644 lenses/rsyncd.aug
create mode 100644 lenses/tests/test_rsyncd.aug
diff --git a/lenses/rsyncd.aug b/lenses/rsyncd.aug
new file mode 100644
index 0000000..bd47cfa
--- /dev/null
+++ b/lenses/rsyncd.aug
@@ -0,0 +1,67 @@
+(* Rsyncd module for Augeas
+ Author: Marc Fournier <marc.fournier at camptocamp.com>
+
+ Reference: man rsyncd.conf(5)
+
+*)
+
+module Rsyncd =
+ autoload xfm
+
+(************************************************************************
+ * INI File settings
+ *************************************************************************)
+let comment = IniFile.comment IniFile.comment_re "#"
+let sep = IniFile.sep IniFile.sep_re IniFile.sep_default
+let indent = del /[ \t]*/ " "
+
+(* Import useful INI File primitives *)
+let eol = IniFile.eol
+let empty = IniFile.empty
+let sto_to_comment
+ = Util.del_opt_ws " "
+ . store /[^;# \t\n][^;#\n]*[^;# \t\n]|[^;# \t\n]/
+
+
+(************************************************************************
+ * ENTRY
+ * rsyncd.conf allows indented entries, but by default entries outside
+ * sections are unindented
+ *************************************************************************)
+let entry_re = /[A-Za-z0-9_.-][A-Za-z0-9 _.-]*[A-Za-z0-9_.-]/
+
+let entry = let kw = entry_re in
+ [ indent
+ . key kw
+ . sep
+ . sto_to_comment?
+ . (comment|eol) ]
+ | comment
+
+let anon_entry = let kw = entry_re in
+ [ key kw
+ . sep
+ . sto_to_comment?
+ . (comment|eol) ]
+ | comment
+
+(************************************************************************
+ * RECORD & TITLE
+ * We use IniFile.title_label because there can be entries
+ * outside of sections whose labels would conflict with section names
+ *************************************************************************)
+let title = IniFile.title ( IniFile.record_re - /.anon/ )
+let record = IniFile.record title entry
+
+let record_anon = [ label ".anon" . ( anon_entry | empty )+ ]
+
+(************************************************************************
+ * LENS & FILTER
+ * There can be entries before any section
+ * IniFile.entry includes comment management, so we just pass entry to lns
+ *************************************************************************)
+let lns = record_anon? . record*
+
+let filter = (incl "/etc/rsyncd.conf")
+
+let xfm = transform lns filter
diff --git a/lenses/tests/test_rsyncd.aug b/lenses/tests/test_rsyncd.aug
new file mode 100644
index 0000000..1eb62be
--- /dev/null
+++ b/lenses/tests/test_rsyncd.aug
@@ -0,0 +1,56 @@
+module Test_rsyncd =
+
+ let conf = "
+# A more sophisticated example would be:
+
+uid = nobody
+gid = nobody
+use chroot = yes
+max connections = 4
+syslog facility = local5
+pid file = /var/run/rsyncd.pid
+
+[ftp]
+ # this is a comment
+ path = /var/ftp/./pub
+ comment = whole ftp area (approx 6.1 GB)
+
+[cvs]
+ ; comment with semicolon
+ path = /data/cvs
+ comment = CVS repository (requires authentication)
+ auth users = tridge, susan # comment at EOL
+ secrets file = /etc/rsyncd.secrets
+
+"
+
+ test Rsyncd.lns get conf =
+ { ".anon"
+ {}
+ { "#comment" = "A more sophisticated example would be:" }
+ {}
+ { "uid" = "nobody" }
+ { "gid" = "nobody" }
+ { "use chroot" = "yes" }
+ { "max connections" = "4" }
+ { "syslog facility" = "local5" }
+ { "pid file" = "/var/run/rsyncd.pid" }
+ {}
+ }
+ { "ftp"
+ { "#comment" = "this is a comment" }
+ { "path" = "/var/ftp/./pub" }
+ { "comment" = "whole ftp area (approx 6.1 GB)" }
+ {}
+ }
+ { "cvs"
+ { "#comment" = "comment with semicolon" }
+ { "path" = "/data/cvs" }
+ { "comment" = "CVS repository (requires authentication)" }
+ { "auth users" = "tridge, susan"
+ { "#comment" = "comment at EOL" }
+ }
+ { "secrets file" = "/etc/rsyncd.secrets" }
+ {}
+ }
+
--
1.5.6.5
More information about the augeas-devel
mailing list