[augeas-devel] [PATCH] Refactor ifcfg.aug
David Lutterkort
dlutter at redhat.com
Wed Apr 30 22:20:26 UTC 2008
# HG changeset patch
# User David Lutterkort <dlutter at redhat.com>
# Date 1209591849 25200
# Node ID 00e0e76f8ac19c3e2e1603149752ee3be36fe16b
# Parent 50e29b6a0120aa4c6c57108b1ce5fe86ae58673c
Refactor ifcfg.aug
This puts the bits that are generally useful for processing /etc/sysconfig
files into shell.aug
diff -r 50e29b6a0120 -r 00e0e76f8ac1 lenses/ifcfg.aug
--- a/lenses/ifcfg.aug Wed Apr 30 19:03:54 2008 +0200
+++ b/lenses/ifcfg.aug Wed Apr 30 14:44:09 2008 -0700
@@ -2,22 +2,10 @@ module Ifcfg =
module Ifcfg =
autoload xfm
- let eol = Util.del_str "\n"
-
- let key_re = /[][A-Z0-9_]+/
- let eq = Util.del_str "="
- let value = /[^\n]*/
-
- let comment = [ del /(#.*)?[ \t]*\n/ "# \n" ]
-
- let kv = [ key key_re . eq . store value . eol ]
-
- let lns = (comment | kv) *
-
let filter = (incl "/etc/sysconfig/network-scripts/ifcfg-*")
. Util.stdexcl
- let xfm = transform lns filter
+ let xfm = transform Shellvars.lns filter
(* Local Variables: *)
(* mode: caml *)
diff -r 50e29b6a0120 -r 00e0e76f8ac1 lenses/shellvars.aug
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lenses/shellvars.aug Wed Apr 30 14:44:09 2008 -0700
@@ -0,0 +1,19 @@
+(* Generic lens for shell-script config files like the ones found *)
+(* in /etc/sysconfig *)
+module Shellvars =
+
+ let eol = Util.del_str "\n"
+
+ let key_re = /[][A-Z0-9_]+/
+ let eq = Util.del_str "="
+ let value = /[^\n]*/
+
+ let comment = [ del /(#.*)?[ \t]*\n/ "# \n" ]
+
+ let kv = [ key key_re . eq . store value . eol ]
+
+ let lns = (comment | kv) *
+
+(* Local Variables: *)
+(* mode: caml *)
+(* End: *)
diff -r 50e29b6a0120 -r 00e0e76f8ac1 lenses/tests/test_ifcfg.aug
--- a/lenses/tests/test_ifcfg.aug Wed Apr 30 19:03:54 2008 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-(* Test for Ifcfg module *)
-module Test_ifcfg =
- let eth_static = "# Intel Corporation PRO/100 VE Network Connection
-DEVICE=eth0
-BOOTPROTO=static
-BROADCAST=172.31.0.255
-HWADDR=ab:cd:ef:12:34:56
-IPADDR=172.31.0.31
-#DHCP_HOSTNAME=host.example.com
-NETMASK=255.255.255.0
-NETWORK=172.31.0.0
-ONBOOT=yes
-"
- let empty_val = "EMPTY=\nDEVICE=eth0\n"
-
- let key_brack = "SOME_KEY[1]=\nDEVICE=eth0\n"
-
- test Ifcfg.lns get eth_static =
- { }
- { "DEVICE" = "eth0" }
- { "BOOTPROTO" = "static" }
- { "BROADCAST" = "172.31.0.255" }
- { "HWADDR" = "ab:cd:ef:12:34:56" }
- { "IPADDR" = "172.31.0.31" }
- { }
- { "NETMASK" = "255.255.255.0" }
- { "NETWORK" = "172.31.0.0" }
- { "ONBOOT" = "yes" }
-
- test Ifcfg.lns put eth_static after
- set "BOOTPROTO" "dhcp" ;
- rm "IPADDR" ;
- rm "BROADCAST" ;
- rm "NETMASK" ;
- rm "NETWORK"
- = "# Intel Corporation PRO/100 VE Network Connection
-DEVICE=eth0
-BOOTPROTO=dhcp
-HWADDR=ab:cd:ef:12:34:56
-#DHCP_HOSTNAME=host.example.com
-ONBOOT=yes
-"
- test Ifcfg.lns get empty_val =
- { "EMPTY" = "" } { "DEVICE" = "eth0" }
-
- test Ifcfg.lns get key_brack =
- { "SOME_KEY[1]" = "" } { "DEVICE" = "eth0" }
-
-(* Local Variables: *)
-(* mode: caml *)
-(* End: *)
diff -r 50e29b6a0120 -r 00e0e76f8ac1 lenses/tests/test_shellvars.aug
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lenses/tests/test_shellvars.aug Wed Apr 30 14:44:09 2008 -0700
@@ -0,0 +1,52 @@
+(* Test for shell lens *)
+module Test_shellvars =
+
+ let eth_static = "# Intel Corporation PRO/100 VE Network Connection
+DEVICE=eth0
+BOOTPROTO=static
+BROADCAST=172.31.0.255
+HWADDR=ab:cd:ef:12:34:56
+IPADDR=172.31.0.31
+#DHCP_HOSTNAME=host.example.com
+NETMASK=255.255.255.0
+NETWORK=172.31.0.0
+ONBOOT=yes
+"
+ let empty_val = "EMPTY=\nDEVICE=eth0\n"
+
+ let key_brack = "SOME_KEY[1]=\nDEVICE=eth0\n"
+
+ test Shellvars.lns get eth_static =
+ { }
+ { "DEVICE" = "eth0" }
+ { "BOOTPROTO" = "static" }
+ { "BROADCAST" = "172.31.0.255" }
+ { "HWADDR" = "ab:cd:ef:12:34:56" }
+ { "IPADDR" = "172.31.0.31" }
+ { }
+ { "NETMASK" = "255.255.255.0" }
+ { "NETWORK" = "172.31.0.0" }
+ { "ONBOOT" = "yes" }
+
+ test Shellvars.lns put eth_static after
+ set "BOOTPROTO" "dhcp" ;
+ rm "IPADDR" ;
+ rm "BROADCAST" ;
+ rm "NETMASK" ;
+ rm "NETWORK"
+ = "# Intel Corporation PRO/100 VE Network Connection
+DEVICE=eth0
+BOOTPROTO=dhcp
+HWADDR=ab:cd:ef:12:34:56
+#DHCP_HOSTNAME=host.example.com
+ONBOOT=yes
+"
+ test Shellvars.lns get empty_val =
+ { "EMPTY" = "" } { "DEVICE" = "eth0" }
+
+ test Shellvars.lns get key_brack =
+ { "SOME_KEY[1]" = "" } { "DEVICE" = "eth0" }
+
+(* Local Variables: *)
+(* mode: caml *)
+(* End: *)
More information about the augeas-devel
mailing list