[augeas-devel] Re: Rewriting inifile.aug

Raphaël Pinson raphink at gmail.com
Thu Aug 14 13:47:11 UTC 2008


I've been trying to implement my proposal already.

Here is the new inifile.aug:

=========================================================
(* IniFile generic module for Augeas          *)
(* Author: Raphael Pinson <raphink at gmail.com> *)
(*                                            *)
(* TODO: Support double quotes in value       *)

module IniFile  =


(************************************************************************
 *                           USEFUL PRIMITIVES
 *************************************************************************)

(* Internal primitives *)
let eol                = Util.eol
let empty              = [ eol ]


(* Define sep and defaults *)
let sep (pat:regexp) (default:string)
                       = Util.del_opt_ws "" . del pat default
let sep_re             = /[=:]/
let sep_default        = "="


(* Define sto_*  *)
let sto_to_eol         = Util.del_opt_ws ""
                         . store /([^ \t\n].*[^ \t\n]|[^ \t\n])/
let sto_to_comment     = Util.del_opt_ws ""
                         . store /[^;# \t\n][^;#\n]*[^;# \t\n]|[^;# \t\n]/


(* Define comment and defaults *)
let comment (pat:regexp) (default:string)
                       = [ label "#comment" . sep pat default
                 . sto_to_eol . eol ]
let comment_re         = /[;#]/
let comment_default    = ";"


(************************************************************************
 *                             ENTRY
 *************************************************************************)

(* entry includes comments *)

let entry (kw:regexp) (sep:lens) (comment:lens)
                       = [ key kw . sep . sto_to_comment? . (comment|eol) ]
| comment
let entry_re           = ( /[A-Za-z][A-Za-z0-9\._-]+/ - /#comment/ )


(************************************************************************
 *                             RECORD
 *************************************************************************)

let title (kw:regexp)
                       = Util.del_str "[" . key kw
                         . Util.del_str "]". eol
let title_label (name:string) (kw:regexp)
                       = label name
                         . Util.del_str "[" . store kw
                         . Util.del_str "]". eol

let record_noempty (title:lens) (entry:lens)
                       = [ title
               . entry* ]
let record (title:lens) (entry:lens)
                       = record_noempty title ( entry | empty )
let record_re          = ( /[^]\n\/]+/ - /#comment/ )
let record_label_re    = /[^]\n]+/


(************************************************************************
 *                              LENS
 *************************************************************************)

let lns_noempty (record:lens) (comment:lens)
                       = comment* . record*
let lns (record:lens) (comment:lens)
                       = lns_noempty record (comment|empty)

=========================================================


dput became


=========================================================
(* Dput module for Augeas
   Author: Raphael Pinson <raphink at gmail.com>


   Reference: dput uses Python's ConfigParser:
     http://docs.python.org/lib/module-ConfigParser.html
*)


module Dput =
  autoload xfm


(************************************************************************
 * INI File settings
 *************************************************************************)
let comment  = IniFile.comment IniFile.comment_re IniFile.comment_default

let sep      = IniFile.sep IniFile.sep_re IniFile.sep_default


let setting = "allow_non-us_software"
            | "allow_unsigned_uploads"
            | "check_version"
            | "default_host_main"
            | "default_host_non-us"
            | "fqdn"
            | "hash"
            | "incoming"
            | "login"
            | "method"
            | "passive_ftp"
            | "post_upload_command"
            | "pre_upload_command"
            | "progress_indicator"
            | "run_dinstall"
            | "run_lintian"
            | "scp_compress"
            | "ssh_config_options"

(************************************************************************
 * "name: value" entries, with continuations in the style of RFC 822;
 * "name=value" is also accepted
 * leading whitespace is removed from values
 *************************************************************************)
let entry = IniFile.entry setting sep comment


(************************************************************************
 * sections, led by a "[section]" header
 * We can't use titles as node names here since they could contain "/"
 * We remove #comment from possible keys
 * since it is used as label for comments
 * We also remove / as first character
 * because augeas doesn't like '/' keys (although it is legal in INI Files)
 *************************************************************************)
let title   = IniFile.title_label "target" IniFile.record_label_re
let record  = IniFile.record title entry

let lns    = IniFile.lns record comment

let filter = (incl "/etc/dput.cf")
           . (incl "~/.dput.cf")
           . Util.stdexcl

let xfm = transform lns filter
=========================================================


php.aug:

=========================================================
(* PHP module for Augeas                      *)
(* Author: Raphael Pinson <raphink at gmail.com> *)
(*                                            *)

module PHP =
  autoload xfm

(************************************************************************
 * INI File settings
 *************************************************************************)

let comment  = IniFile.comment IniFile.comment_re IniFile.comment_default
let sep      = IniFile.sep IniFile.sep_re IniFile.sep_default


(************************************************************************
 *                        ENTRY
 *
 * We have to remove the keyword "section" from possible entry keywords
 * otherwise it would lead to an ambiguity with the "section" label
 * since PHP allows entries outside of sections.
 *************************************************************************)
let entry_re = ( /[A-Za-z][A-Za-z0-9\._-]+/ - /#comment/ - /section/ )
let entry    = IniFile.entry entry_re sep comment


(************************************************************************
 *                         TITLE
 *
 * We use IniFile.title_label because there can be entries
 * outside of sections whose labels would conflict with section names
 *************************************************************************)
let title   = IniFile.title_label "section" IniFile.record_label_re
let record  = IniFile.record title entry


(************************************************************************
 *                         LENS & FILTER
 * There can be entries before any section
 * IniFile.entry includes comment management, so we just pass entry to lns
 *************************************************************************)
let lns    = IniFile.lns record entry

let filter = (incl "/etc/php*/*/php.ini")
             . Util.stdexcl

let xfm = transform lns filter
=========================================================

and puppet.aug

=========================================================
(* Puppet module for Augeas
 Author: Raphael Pinson <raphink at gmail.com>

 puppet.conf is a standard INI File.
*)


module Puppet =
  autoload xfm

(************************************************************************
 * INI File settings
 *
 * puppet.conf only supports "# as commentary and "=" as separator
 *************************************************************************)
let comment    = IniFile.comment "#" "#"
let sep        = IniFile.sep "=" "="


(************************************************************************
 *                        ENTRY
 * puppet.conf uses standard INI File entries
 *************************************************************************)
let entry   = IniFile.entry IniFile.entry_re sep comment


(************************************************************************
 *                        RECORD
 * puppet.conf uses standard INI File records
 *************************************************************************)
let title   = IniFile.title IniFile.record_re
let record  = IniFile.record title entry


(************************************************************************
 *                        LENS & FILTER
 * puppet.conf uses standard INI File records
 *************************************************************************)
let lns     = IniFile.lns record comment

let filter = (incl "/etc/puppet/puppet.conf")

let xfm = transform lns filter
=========================================================


Raphaël



On Thu, Aug 14, 2008 at 12:07 PM, Raphaël Pinson <raphink at gmail.com> wrote:

>
>
> On Thu, Aug 14, 2008 at 11:56 AM, Raphaël Pinson <raphink at gmail.com>wrote:
>
>> Hi there,
>>
>>
>> As I'm playing with inifile.aug and applying it to php.aug, mysql.aug and
>> dput.aug, I find so many different configurations that inifile.aug gets very
>> complicated to my taste. Since functions in lenses cannot take defaults, I
>> end up defining lots of them to set more or less variables. I would like to
>> really simplify inifile.aug. This might mean making the lenses that use it a
>> bit more complicated, but also clearer.
>>
>> Here is my proposal. Comments are very welcome:
>>
>> Writing a generic INI file using inifile.aug would look like this :
>>
>> =========================================================
>> let comment_re      = /[;#]/
>> let comment_default = ";"
>> let comment         = IniFile.comment comment_re comment_default
>>
>> let empty           = IniFile.empty comment_re
>>
>> let sep_re          = /[:=]/
>> let sep_default     = "="
>> let sep             = IniFile.sep sep_re sep_default
>>
>> (* IniFile.entry_re  = ( /[A-Za-z][A-Za-z0-9\._-]+/ - /#comment/ ) *)
>> let entry_re        = IniFile.entry_re
>> let entry            = IniFile.entry entry_re sep comment
>>
>> (* IniFile.record_re = ( /[^]\n\/]+/ - /#comment/ ) *)
>> let record_re      = IniFile.record_re
>> let record          = IniFile.record record_re entry comment empty
>>
>>
>> let lns             = IniFile.lns record comment
>> =========================================================
>>
>>
>> This would be a bit longer than it is currently, but much clearer, too.
>>
>> The values taken by the setting fields would be:
>>
>> comment_re        := ";"| "#" | /[;#]/
>> comment_default := ";" | "#"
>>
>> sep_re                 := ":" | "=" | /[:=]/
>> sep_default          := ";" | "="
>>
>> entry_re               := IniFile.entry_re | your_own_re
>>
>> record_re             := IniFile.record_re | your_own_re
>>
>> Other values for these fields could not be certified to work properly.
>>
>>
>> Default values provided:
>>
>> IniFile.comment_re        = /[;#]/
>> IniFile.comment_default = ";"
>> IniFile.sep_re                = /[:=]/
>> IniFile.sep_default         = "="
>> IniFile.entry_re              = ( /[A-Za-z][A-Za-z0-9\._-]+/ - /#comment/
>> )
>> IniFile.record_re            = ( /[^]\n\/]+/ - /#comment/ )
>>
>>
>> Additionally, IniFile.record_noempty and IniFile.lns_noempty would be
>> provided, since I don't know how to deal with these.
>>
>>
>> Another example, with dput.aug :
>>
>> =========================================================
>>
>> let comment  = IniFile.comment IniFile.comment_re IniFile.comment_default
>> let empty      = IniFile.empty IniFile.comment_re
>>
>> let sep          = IniFile.sep IniFile.sep_re IniFile.set_default
>>
>> let setting = "allow_non-us_software"
>>                | "allow_unsigned_uploads"
>>                | "check_version"
>>                | "default_host_main"
>>                | "default_host_non-us"
>>                | "fqdn"
>>                | "hash"
>>                | "incoming"
>>                | "login"
>>                | "method"
>>                | "passive_ftp"
>>                | "post_upload_command"
>>                | "pre_upload_command"
>>                | "progress_indicator"
>>                | "run_dinstall"
>>                | "run_lintian"
>>                | "scp_compress"
>>                | "ssh_config_options"
>> let entry = IniFile.entry setting sep comment
>>
>> let record  = IniFile.record IniFile.record_re entry comment empty
>>
>> let lns    = IniFile.lns record comment
>> =========================================================
>>
>>
>> It is obviously longer than the current format, but also much clearer on
>> what is accepted and what is not. Alternatively, this is php.aug:
>>
>> =========================================================
>>
>> let comment  = IniFile.comment IniFile.comment_re IniFile.comment_default
>> let empty      = IniFile.empty IniFile.comment_re
>> let eol          = IniFile.eol
>>
>> let sep          = IniFile.sep IniFile.sep_re IniFile.set_default
>>
>> (*
>>   We have to remove the keyword "section" from possible entry keywords
>>   otherwise it would lead to an ambiguity with the "section" label
>>   since PHP allows entries outside of sections.
>> *)
>> let entry_re  = ( /[A-Za-z][A-Za-z0-9\._-]+/ - /#comment/ - /section/ )
>> let entry = IniFile.entry entry_re sep comment
>>
>> let title
>>            = label "section"
>>              .Util.del_str "[" . store /[^]]+/
>>              . Util.del_str "]". eol
>>
>> let record = [ title_label
>>              . (entry | comment | empty)* ]
>>
>> let lns    = ( comment | empty | entry )* . record*
>> =========================================================
>>
>>
>
> Alternatively, PHP.lns could be
>
> let lns = IniFile.lns record (comment|entry)
>
> This trick would send (comment|entry) as the comment lens for IniFile.lns,
> so lns would be equivalent to:
>
> let lns =  ( (comment|entry) | empty )* . record*
>
>
>
> Raphaël
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20080814/ebe91549/attachment.htm>


More information about the augeas-devel mailing list