Post details: Parsing inifiles the easy way

08/13/08

Permalink 12:01:06 pm, Categories: Programming, Configuration management, Augeas, 105 words  

Parsing inifiles the easy way

Raphael has been doing a lot of work to make processing of INI-style files in Augeas easy and painless. It's now at the point that you can describe /etc/php.ini in a few lines:

module PHP =
  autoload xfm

let entry  = IniFile.entry /[a-z][a-z0-9\._-]+/
let record = IniFile.record "section" entry
let lns    = IniFile.lns record

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

let xfm = transform lns filter

That's all you need to have Augeas suck PHP ini files into its tree — turning on safe mode requires exactly two commands in augtool:

  set /files/etc/php.ini/PHP/safe_mode On
  save

Comments:

Comment from: Raphaël Pinson [Visitor]
The new format for inifile.aug might make it a bit more complicated... but not so much.



module PHP =
autoload xfm

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

let entry_re = ( /[A-Za-z][A-Za-z0-9\._-]+/ - /#comment/ - /section/ )
let entry = IniFile.entry entry_re sep comment

let title = IniFile.title_label "section" IniFile.record_label_re
let record = IniFile.record title entry

let lns = IniFile.lns record entry

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

let xfm = transform lns filter



However,


set /files/etc/php.ini/PHP/safe_mode On
save



won't be available because PHP allows key/value pairs outside of the sections (it actually ignores the sections completely) and we can't predict what keys will be used, since every PHP module can add variables in php.ini.

Hopefully, the xpath implementation should allow us to do something like


set /files/etc/php.ini/section[safe_mode]/safe_mode "On"
save



sometime soon?







Permalink 08/14/08 @ 07:27

Comments are closed for this post.

Search

Syndicate this blog XML

What is RSS?

Misc

powered by
b2evolution