[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[augeas-devel] augeas: master - Cobblersettings: new lens and test



Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=3674bf7334b965cccd6e255ad4de4572b093b785
Commit:        3674bf7334b965cccd6e255ad4de4572b093b785
Parent:        23aa2ded7d2e1deffe380c49e2284d8f40ca7285
Author:        Bryan Kearney <bkearney localhost localdomain>
AuthorDate:    Mon Jan 4 13:49:40 2010 -0500
Committer:     David Lutterkort <lutter redhat com>
CommitterDate: Mon Jan 4 14:54:12 2010 -0800

Cobblersettings: new lens and test

---
 lenses/cobblersettings.aug            |   72 +++++++++++++++++++++++++++++++++
 lenses/tests/test_cobblersettings.aug |   46 +++++++++++++++++++++
 tests/Makefile.am                     |    1 +
 3 files changed, 119 insertions(+), 0 deletions(-)

diff --git a/lenses/cobblersettings.aug b/lenses/cobblersettings.aug
new file mode 100644
index 0000000..66edbca
--- /dev/null
+++ b/lenses/cobblersettings.aug
@@ -0,0 +1,72 @@
+(*
+    Parse the /etc/cobbler/settings file  which is in
+    YAML 1.0 format.
+
+    The lens can handle the following contructs
+    * key: value
+    * key: "value"
+    * key: 'value'
+    * key: [value1, value2]
+    * key:
+       - value1
+       - value2
+    * key:
+       key2: value1
+       key3: value2
+
+    Author: Bryan Kearney
+
+    About: License
+      This file is licensed under the LGPLv2+, like the rest of Augeas.
+*)
+module CobblerSettings =
+    autoload xfm
+
+    let kw = /[a-zA-Z0-9_]+/
+    (* TODO Would be better if this stripped off the "" and '' chracters *)
+    let kv = /([^]['", \t\n#:@-]+|"[^"\n]*"|'[^'\n]*')/
+
+    let lbr = del /\[/ "["
+    let rbr = del /\]/ "]"
+    let colon = del /[ \t]*:[ \t]*/ ": "
+    let dash = del /-[ \t]*/ "- "
+    (* let comma = del /,[ \t]*(\n[ \t]+)?/ ", " *)
+    let comma = del /[ \t]*,[ \t]*/ ", "
+
+    let eol_only = del /\n/ "\n"
+
+    (* TODO Would be better to make items a child of a document *)
+    let docmarker = /-{3}/
+
+    let eol   = Util.eol
+    let comment = Util.comment
+    let empty   = Util.empty
+    let indent = del /[ \t]+/ "\t"
+    let ws = del /[ \t]*/ " "
+
+    let value_list = Build.opt_list [label "item" . store kv] comma
+    let setting = [key kw . colon . store kv] . eol
+    let simple_setting_suffix = store kv . eol
+    let setting_list_suffix =  [label "sequence" . lbr . ws . (value_list . ws)? . rbr ] . eol
+    let indendented_setting_list_suffix =  eol_only . (indent . setting)+
+    let indented_list_suffix =  [label "list" . eol_only . ([ label "value" . indent . dash  . store kv] . eol)+]
+
+    (* Break out setting because of a current bug in augeas *)
+    let nested_setting = [key kw . colon . (
+                                            (* simple_setting_suffix | *)
+                                            setting_list_suffix |
+                                            indendented_setting_list_suffix |
+                                            indented_list_suffix
+                                            )
+                        ]
+
+    let document = [label "---" . store docmarker] . eol
+
+    let lns = (document | comment | empty | setting | nested_setting )*
+
+    let xfm = transform lns (incl "/etc/cobbler/settings")
+
+
+(* Local Variables: *)
+(* mode: caml *)
+(* End: *)
diff --git a/lenses/tests/test_cobblersettings.aug b/lenses/tests/test_cobblersettings.aug
new file mode 100644
index 0000000..9646741
--- /dev/null
+++ b/lenses/tests/test_cobblersettings.aug
@@ -0,0 +1,46 @@
+module Test_cobblersettings =
+
+test Cobblersettings.lns get "Simple_Setting: Value \n" =
+  { "Simple_Setting" = "Value" }
+
+test Cobblersettings.lns get "Simple_Setting2: 'Value2 acme com' \n" =
+  { "Simple_Setting2" = "'Value2 acme com'" }
+
+test Cobblersettings.lns get "Simple_Setting3: ''\n" =
+  { "Simple_Setting3" = "''" }
+
+test Cobblersettings.lns get "Simple_Setting4: \"\"\n" =
+  { "Simple_Setting4" = "\"\"" }
+
+test Cobblersettings.lns get "Simple_Setting_Trailing_Space : Value \n" =
+  { "Simple_Setting_Trailing_Space" = "Value" }
+
+test Cobblersettings.lns get "Setting_List:[Value1, Value2, Value3]\n" =
+  { "Setting_List"
+      { "sequence"
+          { "item" = "Value1" }
+          { "item" = "Value2" }
+          { "item" = "Value3" } } }
+
+test Cobblersettings.lns get "Empty_Setting_List: []\n" =
+  { "Empty_Setting_List"
+      { "sequence" } }
+
+test Cobblersettings.lns get "# Commented_Out_Setting: 'some value'\n" =
+  { "#comment" = "Commented_Out_Setting: 'some value'" }
+
+test Cobblersettings.lns get "---\n" =
+  { "---" = "---"}
+
+test Cobblersettings.lns get "Nested_Setting:\n Test: Value\n" =
+  { "Nested_Setting"
+      { "Test" = "Value" } }
+
+test Cobblersettings.lns get "Nested_Setting:\n - Test \n" =
+  { "Nested_Setting"
+      { "list"
+          { "value" = "Test" } } }
+
+(* Local Variables: *)
+(* mode: caml       *)
+(* End:             *)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 567461e..91bf4af 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,6 +15,7 @@ lens_tests =			\
   lens-aptpreferences.sh	\
   lens-aptsource.sh		\
   lens-bbhosts.sh		\
+  lens-cobblersettings.sh	\
   lens-cron.sh			\
   lens-darkice.sh		\
   lens-dhclient.sh		\



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]