[augeas-devel] Avoiding wheel reinvention with dpkg.cfg, and setting empty things.
David Lutterkort
lutter at redhat.com
Tue Dec 30 05:54:13 UTC 2008
On Mon, 2008-12-29 at 11:56 -0800, Robin Lee Powell wrote:
> On Sun, Dec 28, 2008 at 08:52:14PM -0800, Robin Lee Powell wrote:
> >
> > So I'm trying to work with debian's /etc/dpkg/dpkg.cfg. It's
> > incredibly simple: # comments, real lines are command-line options
> > names, possibly with a space-seperated single argument, i.e.:
>
> Ended up writing it myself.
That's the spirit.
> I'm pasting it below because I hit a segfault in Augeas:
Before I can commit this, could you also please write a unit test or two
that checks that your lens does what it's intended to do ? That would go
into a file lenses/tests/test_dpkg.aug - that directory also contains
examples of tests for existing lenses.
> - ----------------
>
> (* Parsing /etc/dpkg/dpkg.cfg *)
>
> module Dpkg =
> autoload xfm
>
> let sep_tab = Util.del_ws_tab
> let sep_spc = Util.del_ws_spc
> let eol = del /[ \t]*\n/ "\n"
>
> let comment = Util.comment
> let empty = Util.empty
>
> let word = /[^,# \n\t]+/
>
> let bare_option = [ label "bare_option" . store word ]
>
> let valued_option = [ label "value_option" . store word ] . sep_spc .
> [ label "value" . store word ]
> let record = [ seq "option" . ( bare_option | valued_option ) . eol ]
Why don't you use the name of the option as a key and store the value
for that option as the value of the tree node ? Something along the
lines of (untested):
let record = [ key word . (sep_spc . store word)? . eol ]
That would producea much more compact and readable tree.
> let lns = ( empty | comment | record ) *
>
> let xfm = transform lns (incl "/etc/dpkg/dpkg.cfg")
>
> (* Local Variables: *)
> (* mode: caml *)
> (* End: *)
>
> - ----------------
>
> I'm sure I could have done things better, but the docs are a bit
> lacking. :)
One obvious improvement, assuming that dpkg.cfg uses a fixed set of
option names, is to use those instead of 'word' - that would also let
you distinguish more cleanly between options that take values and those
that don't.
> I have no idea what the "seq" keyword actually *does*,
> for example.
Does [1] not provide enough info ? There's also some more docs on the
Wiki, e.g. [2] ... suggestions for improving the docs are of course
always welcome.
> Anyways, if you replace the record line with:
>
> let record = [ seq "option" . bare_option | valued_option . eol ]
>
> Then Augeas segfaults.
Nice find. I've posted a patch that fixes that.
David
[1] http://www.augeas.net/docs/lenses.html
[2] http://www.augeas.net/page/Creating_a_lens_step_by_step
More information about the augeas-devel
mailing list