[augeas-devel] [PATCH] Add mke2fs.aug and associated test

Raphaël Pinson raphink at gmail.com
Tue Nov 2 23:20:49 UTC 2010


Committed as 43d8ec120e42190eebbd9165a215cb573164255e

On Mon, Nov 1, 2010 at 1:58 PM, Raphael Pinson <raphink at gmail.com> wrote:

> This patch adds a lens for /etc/mke2fs.conf.
>
> ---
>  lenses/mke2fs.aug            |  140
> ++++++++++++++++++++++++++++++++++++++++++
>  lenses/tests/test_mke2fs.aug |   76 +++++++++++++++++++++++
>  2 files changed, 216 insertions(+), 0 deletions(-)
>  create mode 100644 lenses/mke2fs.aug
>  create mode 100644 lenses/tests/test_mke2fs.aug
>
> diff --git a/lenses/mke2fs.aug b/lenses/mke2fs.aug
> new file mode 100644
> index 0000000..6d1bdc6
> --- /dev/null
> +++ b/lenses/mke2fs.aug
> @@ -0,0 +1,140 @@
> +(*
> +Module: Mke2fs
> +  Parses /etc/mke2fs.conf
> +
> +Author: Raphael Pinson <raphink at gmail.com>
> +
> +About: Reference
> +  This lens tries to keep as close as possible to `man 5 mke2fs.conf`
> where possible.
> +
> +About: License
> +   This file is licenced under the LGPLv2+, like the rest of Augeas.
> +
> +About: Lens Usage
> +   To be documented
> +
> +About: Configuration files
> +   This lens applies to /etc/mke2fs.conf. See <filter>.
> +*)
> +
> +
> +module Mke2fs =
> +  autoload xfm
> +
> +(************************************************************************
> + * Group:                 USEFUL PRIMITIVES
> +
> *************************************************************************)
> +
> +(* View: comment *)
> +let comment = IniFile.comment IniFile.comment_re IniFile.comment_default
> +
> +(* View: sep *)
> +let sep = IniFile.sep /=[ \t]*/ "="
> +
> +(* View: empty *)
> +let empty = IniFile.empty
> +
> +
> +(************************************************************************
> + * Group:                 RECORD TYPES
> +
> *************************************************************************)
> +
> +
> +(* View: entry
> +    A generic entry for lens lns *)
> +let entry (kw:regexp) (lns:lens) = Build.key_value_line kw sep lns
> +
> +
> +(* View: list_sto
> +    A list of values with given lens *)
> +let list_sto (kw:regexp) (lns:lens) = counter "item" .
> +                                          entry kw
> +                                            (Build.opt_list
> +                                              [lns]
> +                                              Sep.comma)
> +
> +(* View: entry_sto
> +    Store a regexp as entry value *)
> +let entry_sto (kw:regexp) (val:regexp) = entry kw (store val)
> +
> +
> +(************************************************************************
> + * Group:                 COMMON ENTRIES
> +
> *************************************************************************)
> +(* View: common_entry
> +     Entries shared between <defaults> and <fs_types> sections *)
> +let common_entry   = list_sto ("base_features"|"default_features")
> +                        (key Rx.word)
> +                   | entry_sto "blocksize" ("-"? . Rx.integer)
> +                   | entry_sto "hash_alg" ("legacy"|"half_md4"|"tea")
> +                   | entry_sto ("inode_ratio"|"inode_size") Rx.integer
> +
> +(************************************************************************
> + * Group:                 DEFAULTS SECTION
> +
> *************************************************************************)
> +
> +(* View: defaults_entry
> +    Possible entries under the <defaults> section *)
> +let defaults_entry = entry_sto "force_undo" ("true"|"false")
> +                   | entry_sto "fs_type" Rx.word
> +                   | entry_sto "undo_dir" Rx.fspath
> +
> +(* View: defaults_title
> +    Title for the <defaults> section *)
> +let defaults_title  = IniFile.title "defaults"
> +
> +(* View: defaults
> +    A defaults section *)
> +let defaults = IniFile.record defaults_title
> +                  ((Util.indent . (defaults_entry|common_entry)) |
> comment)
> +
> +
> +(************************************************************************
> + * Group:                 FS_TYPES SECTION
> +
> *************************************************************************)
> +
> +(* View: fs_types_entry
> +    Possible entries under a <fs_types_record> group *)
> +let fs_types_entry =list_sto "features"
> +                        ([del /\^/ "^" . label "disable"]?
> +                                           . key Rx.word)
> +                   | list_sto "options"
> +                        (key Rx.word . Util.del_str "="
> +                       . store Rx.word)
> +                   | entry_sto "lazy_itable_init" ("true"|"false")
> +                   | entry_sto "flex_bg_size" Rx.integer
> +
> +(* View: fs_types_record
> +     Fs group records under the <fs_types> section *)
> +let fs_types_record = [ label "filesystem"
> +                     . Util.indent . store Rx.word
> +                     . del /[ \t]*=[ \t]*\{[ \t]*\n/ " = {\n"
> +                     . ((Util.indent . (fs_types_entry|common_entry)) |
> empty | comment)*
> +                     . del /[ \t]*\}[ \t]*\n/ " }\n" ]
> +
> +(* View: fs_types_title
> +    Title for the <fs_types> section *)
> +let fs_types_title = IniFile.title "fs_types"
> +
> +(* View: fs_types
> +    A fs_types section *)
> +let fs_types = IniFile.record fs_types_title
> +                  (fs_types_record | comment)
> +
> +
> +(************************************************************************
> + * Group:                 LENS AND FILTER
> +
> *************************************************************************)
> +
> +(* View: lns
> +     The mke2fs lens
> +*)
> +let lns = (empty|comment)* . (defaults|fs_types)*
> +
> +(* Variable: filter *)
> +let filter = incl "/etc/mke2fs.conf"
> +    . Util.stdexcl
> +
> +let xfm = transform lns filter
> +
> +
> diff --git a/lenses/tests/test_mke2fs.aug b/lenses/tests/test_mke2fs.aug
> new file mode 100644
> index 0000000..39ac9e2
> --- /dev/null
> +++ b/lenses/tests/test_mke2fs.aug
> @@ -0,0 +1,76 @@
> +(* Test for keepalived lens *)
> +
> +module Test_mke2fs =
> +
> +   let conf = "# This is a comment
> +; and another comment
> +
> +[defaults]
> +       base_features =
> sparse_super,filetype,resize_inode,dir_index,ext_attr
> +       blocksize = 4096
> +       inode_size = 256
> +        ; here goes inode_ratio
> +       inode_ratio = 16384
> +
> +[fs_types]
> + ; here we have fs_types
> +       ext4dev = {
> +                # this is ext4dev conf
> +
> +               features = has_journal,^extent
> +               inode_size = 256
> +               options = test_fs=1
> +       }
> +       small = {
> +               blocksize = 1024
> +               inode_size = 128
> +               inode_ratio = 4096
> +       }
> +       largefile = {
> +               inode_ratio = 1048576
> +               blocksize = -1
> +       }
> +"
> +
> +   test Mke2fs.lns get conf =
> +     { "#comment" = "This is a comment" }
> +     { "#comment" = "and another comment" }
> +     {}
> +     { "defaults"
> +        { "base_features"
> +             { "sparse_super" }
> +             { "filetype" }
> +             { "resize_inode" }
> +             { "dir_index" }
> +             { "ext_attr" } }
> +        { "blocksize" = "4096" }
> +        { "inode_size" = "256" }
> +        { "#comment" = "here goes inode_ratio" }
> +        { "inode_ratio" = "16384" }
> +        {} }
> +     { "fs_types"
> +        { "#comment" = "here we have fs_types" }
> +        { "filesystem" = "ext4dev"
> +             { "#comment" = "this is ext4dev conf" }
> +             {}
> +             { "features"
> +                { "has_journal" }
> +                { "extent"
> +                   { "disable" } } }
> +             { "inode_size" = "256" }
> +             { "options"
> +                { "test_fs" = "1" } } }
> +        { "filesystem" = "small"
> +             { "blocksize" = "1024" }
> +             { "inode_size" = "128" }
> +             { "inode_ratio" = "4096" } }
> +        { "filesystem" = "largefile"
> +             { "inode_ratio" = "1048576" }
> +             { "blocksize" = "-1" } } }
> +
> +
> +test Mke2fs.fs_types_entry
> +   put "features = has_journal,^extent\n"
> +   after set "/features/has_journal/disable" "";
> +   rm "/features/extent/disable" = "features = ^has_journal,extent\n"
> +
> --
> 1.7.0.4
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20101103/492c0c9a/attachment.htm>


More information about the augeas-devel mailing list