[augeas-devel] [PATCH] Modprobe: lens and tests for modprobe.conf

David Lutterkort lutter at redhat.com
Fri Mar 13 00:01:21 UTC 2009


---
 doc/naturaldocs/conf/lenses/Menu.txt |    1 +
 lenses/modprobe.aug                  |   49 +++++++++++++++++++++++
 lenses/tests/test_modprobe.aug       |   73 ++++++++++++++++++++++++++++++++++
 3 files changed, 123 insertions(+), 0 deletions(-)
 create mode 100644 lenses/modprobe.aug
 create mode 100644 lenses/tests/test_modprobe.aug

diff --git a/doc/naturaldocs/conf/lenses/Menu.txt b/doc/naturaldocs/conf/lenses/Menu.txt
index 4ac51f1..926b0af 100644
--- a/doc/naturaldocs/conf/lenses/Menu.txt
+++ b/doc/naturaldocs/conf/lenses/Menu.txt
@@ -55,6 +55,7 @@ Group: Specific Modules  {
 
    File: Dpkg  (dpkg.aug)
    File: Exports  (exports.aug)
+   File: Modprobe  (modprobe.aug)
    File: Services  (services.aug)
    File: Sshd  (sshd.aug)
    File: Sudoers  (sudoers.aug)
diff --git a/lenses/modprobe.aug b/lenses/modprobe.aug
new file mode 100644
index 0000000..d61b7a0
--- /dev/null
+++ b/lenses/modprobe.aug
@@ -0,0 +1,49 @@
+(*
+Module: Modprobe
+  Parses /etc/modprobe.conf and /etc/modprobe.d/*
+*)
+module Modprobe =
+autoload xfm
+
+let comment = Util.comment
+let empty = Util.empty
+let eol = Util.eol
+
+(* modprobe.conf allows continuing a line by ending it with backslash +
+   newline; the backslash + newline token is suppressed We handle an
+   approximation of that by classifying backslash + newline as a
+   separator.
+*)
+
+(* A separator is either whitespace or \ followed by newline *)
+let sep_ch = /[ \t]|\\\\\n/
+(* Anything that's not a separator is part of a token *)
+let tok_ch = /[^ \t\n\\]|\\\\[^ \t\n]/
+
+let spc = del sep_ch+ " "
+let token = store tok_ch+
+let indent = Util.del_opt_ws ""
+
+let cmd (n:regexp) = key n . spc
+let arg (n:string) = [ label n . token ]
+let token_to_eol = store (tok_ch . /([^\n\\]|\\\\\n)*/ . tok_ch | tok_ch)
+
+let options =
+  let opt_ch = /[A-Za-z0-9_]/ in
+  let option = [ spc . key opt_ch+ . (del /=/ "=" . token)? ] in
+    [ cmd "options" . token . option* . eol ]
+
+let entry = [ cmd "alias" . token . spc . arg "modulename" . eol ]
+  | [ cmd "include" . token . eol ]
+  | options
+  | [ cmd /install|remove/ . token_to_eol . eol ]
+  | [ cmd "blacklist" . token . eol ]
+  | [ cmd "config" . store /binary_indexes|yes|no/ ]
+
+let lns = (comment|empty|entry)*
+
+let filter = (incl "/etc/modprobe.conf") .
+  (incl "/etc/modprobe.d/*").
+  Util.stdexcl
+
+let xfm = transform lns filter
diff --git a/lenses/tests/test_modprobe.aug b/lenses/tests/test_modprobe.aug
new file mode 100644
index 0000000..e358d61
--- /dev/null
+++ b/lenses/tests/test_modprobe.aug
@@ -0,0 +1,73 @@
+module Test_modprobe =
+
+(* Based on 04config.sh from module-init-tools *)
+
+let conf = "# Various aliases
+alias alias_to_foo foo
+alias alias_to_bar bar
+alias alias_to_export_dep-$BITNESS export_dep-$BITNESS
+
+# Various options, including options to aliases.
+options alias_to_export_dep-$BITNESS I am alias to export_dep
+options alias_to_noexport_nodep-$BITNESS_with_tabbed_options index=0 id=\"Thinkpad\" isapnp=0 \\
+\tport=0x530 cport=0x538 fm_port=0x388 \\
+\tmpu_port=-1 mpu_irq=-1 \\
+\tirq=9 dma1=1 dma2=3 \\
+\tenable=1 isapnp=0
+
+# Blacklist
+blacklist watchdog_drivers  \t
+
+# Install commands
+install bar echo Installing bar
+install foo echo Installing foo
+install export_nodep-$BITNESS echo Installing export_nodep
+
+# Remove commands
+remove bar echo Removing bar
+remove foo echo Removing foo
+remove export_nodep-$BITNESS echo Removing export_nodep\n"
+
+test Modprobe.lns get conf =
+  { "#comment" = "Various aliases" }
+  { "alias" = "alias_to_foo"
+    { "modulename" = "foo" } }
+  { "alias" = "alias_to_bar"
+    { "modulename" = "bar" } }
+  { "alias" = "alias_to_export_dep-$BITNESS"
+    { "modulename" = "export_dep-$BITNESS" } }
+  { }
+  { "#comment" = "Various options, including options to aliases." }
+  { "options" = "alias_to_export_dep-$BITNESS"
+    { "I" }
+    { "am" }
+    { "alias" }
+    { "to" }
+    { "export_dep" } }
+  { "options" = "alias_to_noexport_nodep-$BITNESS_with_tabbed_options"
+    { "index" = "0" }
+    { "id" = "\"Thinkpad\"" }
+    { "isapnp" = "0" }
+    { "port" = "0x530" }
+    { "cport" = "0x538" }
+    { "fm_port" = "0x388" }
+    { "mpu_port" = "-1" }
+    { "mpu_irq" = "-1" }
+    { "irq" = "9" }
+    { "dma1" = "1" }
+    { "dma2" = "3" }
+    { "enable" = "1" }
+    { "isapnp" = "0" } }
+  { }
+  { "#comment" = "Blacklist" }
+  { "blacklist" = "watchdog_drivers" }
+  { }
+  { "#comment" = "Install commands" }
+  { "install" = "bar echo Installing bar" }
+  { "install" = "foo echo Installing foo" }
+  { "install" = "export_nodep-$BITNESS echo Installing export_nodep" }
+  { }
+  { "#comment" = "Remove commands" }
+  { "remove" = "bar echo Removing bar" }
+  { "remove" = "foo echo Removing foo" }
+  { "remove" = "export_nodep-$BITNESS echo Removing export_nodep" }
-- 
1.6.0.6




More information about the augeas-devel mailing list