[augeas-devel] augeas: master - Inittab: simplified schema, map comments

David Lutterkort lutter at fedoraproject.org
Tue Jun 16 18:40:45 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=4b8fa56ed53e5a7fd96682c5cd9f86c1b2912ab8
Commit:        4b8fa56ed53e5a7fd96682c5cd9f86c1b2912ab8
Parent:        bad876776fd6c30ea23f07eaea281e91770728c7
Author:        Matt Palmer <matt at anchor.net.au>
AuthorDate:    Fri Jun 12 14:49:32 2009 +1000
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Tue Jun 16 11:39:53 2009 -0700

Inittab: simplified schema, map comments

Change the structure of the inittab lens so that the 'id' field is used
as the name of the subtree for that line in /etc/inittab.

Map comments as '#comment' nodes
---
 lenses/inittab.aug            |   14 +++++++-------
 lenses/tests/test_inittab.aug |   20 ++++++++++++--------
 tests/rec-initdefault.rb      |    9 +--------
 3 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/lenses/inittab.aug b/lenses/inittab.aug
index 0aa7baf..8d65cd5 100644
--- a/lenses/inittab.aug
+++ b/lenses/inittab.aug
@@ -5,17 +5,17 @@ module Inittab =
    let sep = Util.del_str ":"
    let eol = Util.del_str "\n"
 
+   let id = /[^\/#:\n]{1,4}/
    let value = /[^#:\n]*/
 
-   let comment = [ del /[ \t]*(#.*)?\n/ "# \n" ]
+   let comment = Util.comment|Util.empty
 
    let field (name:string) = [ label name . store value ]
-   let record = [ seq "record" .
-                    field("id") . sep .
-                    field("runlevels") . sep .
-                    field("action") . sep .
-                    field("process") .
-                    eol
+   let record = [ key id . sep .
+                  field("runlevels") . sep .
+                  field("action") . sep .
+                  field("process") .
+                  eol
                 ]
 
    let lns = ( comment | record ) *
diff --git a/lenses/tests/test_inittab.aug b/lenses/tests/test_inittab.aug
index 6ac4ce3..61d8d21 100644
--- a/lenses/tests/test_inittab.aug
+++ b/lenses/tests/test_inittab.aug
@@ -5,34 +5,38 @@ module Test_inittab =
   let inittab = "id:5:initdefault:
 # System initialization.
 si::sysinit:/etc/rc.d/rc.sysinit
+
 # Trap CTRL-ALT-DELETE
 ca::ctrlaltdel:/sbin/shutdown -t3 -r now
+
 l0:0:wait:/etc/rc.d/rc 0
 "
 
  test Inittab.lns get inittab =
-    { "1" { "id" = "id" }
+    { "id"
           { "runlevels" = "5" }
           { "action" = "initdefault" }
           { "process" = "" } }
-    {}
-    { "2" { "id" = "si" }
+    { "#comment" = "System initialization." }
+    { "si"
           { "runlevels" = "" }
           { "action" = "sysinit" }
           { "process" = "/etc/rc.d/rc.sysinit" } }
-    {}
-    { "3" { "id" = "ca" }
+    { }
+    { "#comment" = "Trap CTRL-ALT-DELETE" }
+    { "ca"
           { "runlevels" = "" }
           { "action" = "ctrlaltdel" }
           { "process" = "/sbin/shutdown -t3 -r now" } }
-    { "4" { "id" = "l0" }
+    { }
+    { "l0"
           { "runlevels" = "0" }
           { "action" = "wait" }
           { "process" = "/etc/rc.d/rc 0" } }
 
-  test Inittab.lns put simple after rm "/1/process" = *
+  test Inittab.lns put simple after rm "/id/process" = *
 
-  test Inittab.lns put simple after set "/1/runlevels" "3" =
+  test Inittab.lns put simple after set "/id/runlevels" "3" =
     "id:3:initdefault:\n"
 
 (* Local Variables: *)
diff --git a/tests/rec-initdefault.rb b/tests/rec-initdefault.rb
index 8861992..300d9b1 100644
--- a/tests/rec-initdefault.rb
+++ b/tests/rec-initdefault.rb
@@ -5,15 +5,8 @@
 # mostly because the testing framework and augtool are too simplistic to do
 # that. Would be easy with a shell script
 
-# Query for the record that holds the initdefault
-record=""
-`augtool -n match '/files/etc/inittab/*/action' initdefault`.each do |l|
-    if l =~ %r{^(/files/etc/inittab/[0-9]+)}
-        record = $1
-    end
-end
 commands="
-set #{record}/runlevels 3
+set /files/etc/inittab/id/runlevels 3
 save
 "
 




More information about the augeas-devel mailing list