[augeas-devel] Avoiding wheel reinvention with dpkg.cfg, and setting empty things.
Robin Lee Powell
rlpowell at digitalkingdom.org
Thu Jan 15 22:43:39 UTC 2009
On Wed, Dec 31, 2008 at 11:32:41AM +0100, Raphaël Pinson wrote:
> Hi Robin,
>
>
> Thank you for this nice lens. I see you've been putting quite a
> lot of info in comments in there. It would be nice if you could
> document using the standards described on [0], so your module can
> be included in [1].
Attached.
Also attached is my modifications to exports.aug for the same
purpose.
-Robin
--
They say: "The first AIs will be built by the military as weapons."
And I'm thinking: "Does it even occur to you to try for something
other than the default outcome?" -- http://shorl.com/tydruhedufogre
http://www.digitalkingdom.org/~rlpowell/ *** http://www.lojban.org/
-------------- next part --------------
(*
Module: Dpkg
Parses /etc/dpkg/dpkg.cfg
Author: Robin Lee Powell <rlpowell at digitalkingdom.org>
About: License
This file, and the attendant test_dpgk.aug, are explicitely
placed in the public domain.
About: Description
dpkg.cfg is a simple list of options, the same ones as the
command line options, with or without a value.
The tree is a list of either comments or option/value pairs by
name. Use "set" to set an option with a value, and "clear" for a
bare option.
About: Usage Example
$ augtool -n
augtool> ls /files/etc/dpkg/dpkg.cfg
#comment[1] = dpkg configuration file
#comment[2] = This file can contain default options for dpkg. All command-line
#comment[3] = options are allowed. Values can be specified by putting them after
#comment[4] = the option, separated by whitespace and/or an `=' sign.
#comment[5] = Do not enable debsig-verify by default; since the distribution is not using
#comment[6] = embedded signatures, debsig-verify would reject all packages.
no-debsig = (none)
#comment[7] = Log status changes and actions to a file.
log = /var/log/dpkg.log
augtool> get /files/etc/dpkg/dpkg.cfg/no-debsig
/files/etc/dpkg/dpkg.cfg/no-debsig (none)
augtool> get /files/etc/dpkg/dpkg.cfg/log
/files/etc/dpkg/dpkg.cfg/log = /var/log/dpkg.log
augtool> clear /files/etc/dpkg/dpkg.cfg/testopt
augtool> set /files/etc/dpkg/dpkg.cfg/testopt2 test
augtool> save
Saved 1 file(s)
augtool>
$ cat /etc/dpkg/dpkg.cfg.augnew
# dpkg configuration file
#
# This file can contain default options for dpkg. All command-line
# options are allowed. Values can be specified by putting them after
# the option, separated by whitespace and/or an `=' sign.
#
# Do not enable debsig-verify by default; since the distribution is not using
# embedded signatures, debsig-verify would reject all packages.
no-debsig
# Log status changes and actions to a file.
log /var/log/dpkg.log
testopt
testopt2 test
*)
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 keyword = /[^,# \n\t\/]+/
(* View: record
Keyword, followed by optional whitespace and value, followed
by EOL.
The actual file specification doesn't require EOL, but the
likelyhood of the file not having one is pretty slim, and
this way things we add have EOL.
*)
let record = [ key keyword . (sep_spc . store word)? . eol ]
(* View: lns
Any number of empty lines, comments, and records.
*)
let lns = ( empty | comment | record ) *
let xfm = transform lns (incl "/etc/dpkg/dpkg.cfg")
-------------- next part --------------
(* Lens for Linux syntax of NFS exports(5) *)
(*
Module: Exports
Parses /etc/exports
Author: Unknown
About: License
Unknown
About: Description
/etc/exports contains lines associating a directory with one or
more hosts, and NFS options for each host.
About: Usage Example
$ augtool
augtool> ls /files/etc/exports/
comment[1] = /etc/exports: the access control list for filesystems which may be exported
comment[2] = to NFS clients. See exports(5).
comment[3] = sample /etc/exports file
dir[1]/ = /
dir[2]/ = /projects
dir[3]/ = /usr
dir[4]/ = /home/joe
augtool> ls /files/etc/exports/dir[1]
client[1]/ = master
client[2]/ = trusty
The corresponding line in the file is:
/ master(rw) trusty(rw,no_root_squash)
Digging further:
augtool> ls /files/etc/exports/dir[1]/client[1]
option = rw
To add a new entry, you'd do something like this:
augtool> set /files/etc/exports/dir[10000] /foo
augtool> set /files/etc/exports/dir[last()]/client[1] weeble
augtool> set /files/etc/exports/dir[last()]/client[1]/option[1] ro
augtool> set /files/etc/exports/dir[last()]/client[1]/option[2] all_squash
augtool> save
Saved 1 file(s)
Which creates the line:
/foo weeble(ro,all_squash)
About: Limitations
This lens cannot handle options without a host, as with the last
example line in "man 5 exports":
/pub (ro,insecure,all_squash)
In this case, though, you can just do:
/pub *(ro,insecure,all_squash)
It also can't handle whitespace before the directory name.
*)
module Exports =
autoload xfm
let client_re = /[a-zA-Z0-9\-\.@\*\?\/]+/
let eol = del /[ \t]*\n/ "\n"
let option = [ label "option" . store /[^,)]+/ ]
let client = [ label "client" . store client_re .
( Util.del_str "(" .
option .
( Util.del_str "," . option ) * .
Util.del_str ")" )? ]
let entry = [ label "dir" . store /\/[^ \t]*/ .
Util.del_ws_spc .
client . (Util.del_ws_spc . client)* . eol ]
let lns = (Hosts.empty | Hosts.comment | entry)*
let xfm = transform lns (incl "/etc/exports")
More information about the augeas-devel
mailing list