[augeas-devel] [PATCH] Modules: Add new lens for modules.conf

Matthew Booth mbooth at redhat.com
Wed May 12 16:47:13 UTC 2010


---
 lenses/modules.aug            |   61 ++++++++++++++++++++++++++
 lenses/tests/test_modules.aug |   96 +++++++++++++++++++++++++++++++++++++++++
 tests/Makefile.am             |    1 +
 3 files changed, 158 insertions(+), 0 deletions(-)
 create mode 100644 lenses/modules.aug
 create mode 100644 lenses/tests/test_modules.aug

diff --git a/lenses/modules.aug b/lenses/modules.aug
new file mode 100644
index 0000000..620fa56
--- /dev/null
+++ b/lenses/modules.aug
@@ -0,0 +1,61 @@
+(*
+Module: Modules
+  Parses /etc/modules.conf and /etc/conf.modules
+
+  Based on the similar Modprobe lens
+
+  Not all directives currently listed in modules.conf(5) are currently
+  supported.
+*)
+module Modules =
+autoload xfm
+
+let comment = Util.comment
+let empty = Util.empty
+let eol = Util.eol | Util.comment
+
+(* modules.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 path =
+  [ key "path" . del "=" "=" . token_to_eol . eol ]
+
+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 ]
+  | [ cmd /install|pre-install|post-install/ . token_to_eol . eol ]
+  | [ key "keep" . eol ]
+  | [ cmd /remove|pre-remove|post-remove/ . token_to_eol . eol ]
+  | options
+  | path
+  | [ cmd "probeall" . token_to_eol . eol ]
+  
+
+let lns = (comment|empty|entry)*
+
+let filter = (incl "/etc/modules.conf") .
+  (incl "/etc/conf.modules").
+  Util.stdexcl
+
+let xfm = transform lns filter
diff --git a/lenses/tests/test_modules.aug b/lenses/tests/test_modules.aug
new file mode 100644
index 0000000..bdbbf28
--- /dev/null
+++ b/lenses/tests/test_modules.aug
@@ -0,0 +1,96 @@
+module Test_modules =
+
+(* 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
+
+# Install commands
+install bar echo Installing bar
+install foo echo Installing foo
+install export_nodep-$BITNESS echo Installing export_nodep
+
+# Pre- and post- install something
+pre-install ide-scsi modprobe ide-cd # load ide-cd before ide-scsi
+post-install serial /etc/init.d/setserial modload > /dev/null 2> /dev/null
+
+# Remove commands
+remove bar echo Removing bar
+remove foo echo Removing foo
+remove export_nodep-$BITNESS echo Removing export_nodep
+
+#Pre- and post- remove something
+pre-remove serial /etc/init.d/setserial modsave  > /dev/null 2> /dev/null
+post-remove bttv rmmod tuner
+
+# Misc other directives
+probeall /dev/cdroms
+keep
+path=/lib/modules/`uname -r`/alsa
+"
+
+test Modules.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" = "Install commands" }
+  { "install" = "bar echo Installing bar" }
+  { "install" = "foo echo Installing foo" }
+  { "install" = "export_nodep-$BITNESS echo Installing export_nodep" }
+  { }
+  { "#comment" = "Pre- and post- install something" }
+  { "pre-install" = "ide-scsi modprobe ide-cd"
+    { "#comment" = "load ide-cd before ide-scsi" }
+  }
+  { "post-install" = "serial /etc/init.d/setserial modload > /dev/null 2> /dev/null" }
+  { }
+  { "#comment" = "Remove commands" }
+  { "remove" = "bar echo Removing bar" }
+  { "remove" = "foo echo Removing foo" }
+  { "remove" = "export_nodep-$BITNESS echo Removing export_nodep" }
+  { }
+  { "#comment" = "Pre- and post- remove something" }
+  { "pre-remove" = "serial /etc/init.d/setserial modsave  > /dev/null 2> /dev/null" }
+  { "post-remove" = "bttv rmmod tuner" }
+  { }
+  { "#comment" = "Misc other directives" }
+  { "probeall" = "/dev/cdroms" }
+  { "keep" }
+  { "path" = "/lib/modules/`uname -r`/alsa" }
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3375ee9..5ea889d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -45,6 +45,7 @@ lens_tests =			\
   lens-logrotate.sh		\
   lens-lokkit.sh		\
   lens-modprobe.sh		\
+  lens-modules.sh		\
   lens-monit.sh			\
   lens-multipath.sh     \
   lens-nagioscfg.sh     \
-- 
1.6.6.1




More information about the augeas-devel mailing list