Mailinglist Archive: zypp-devel (102 mails)

< Previous Next >
Re: [zypp-devel] Augeas for libzypp and zypper?
  • From: Stanislav Visnovsky <visnov@xxxxxxx>
  • Date: Thu, 5 Mar 2009 15:39:40 +0100
  • Message-id: <200903051539.41282.visnov@xxxxxxx>
On Streda 04 March 2009 23:04:31 Jan Kupec wrote:
(orignal text at
http://jniq.blogspot.com/2009/03/augeas-for-libzypp-and-zypper.html
reposting for discussion)

------copy------
The need for a configuration file for zypper (plus my wish for a nice
CLI for handling it) and a visit to Raphaƫl Pinson's presentation at
FOSDEM made me look at Augeas closely.

Augeas enables you to read and edit your config files in a way which
preserves comments and formatting details, allowing humans and programs
coexist peacefully when it comes to editing configuration files. More
than that, you can map some special structures of the file to special
parts of the augeas tree, rather than using the generic INI file parser.
See the zypp.conf for example (zypper.conf will have the same structure):


[main]
## Option description.
## Default: etc.
##
# disabledoption = value

## Another option description
##

another.option = value



With Augeas you can write a lens (the file contents description) which
will map such file into a tree like this:


/files/etc/zypp/zypp.conf/main/1
/files/etc/zypp/zypp.conf/main/1/description[1] = "Option description."
/files/etc/zypp/zypp.conf/main/1/description[2] = "Default: etc."
/files/etc/zypp/zypp.conf/main/1/description[3]
/files/etc/zypp/zypp.conf/main/1/commented
/files/etc/zypp/zypp.conf/main/1/disabledoption = "value"
/files/etc/zypp/zypp.conf/main/2
/files/etc/zypp/zypp.conf/main/2/description[1] = "Another option
description."
/files/etc/zypp/zypp.conf/main/2/description[2]
/files/etc/zypp/zypp.conf/main/2/another.option = "value"



Note the commented node. Augeas has an API for looking for the nodes,
getting values from them, setting the values, and finally saving the
tree back to the config file.

What does this mean for zypper? Implementing zypper conf --list is a
piece of cake, as well as zypper conf --set another.option value.
Commenting or uncommenting the option is a matter of adding or removing
the commented node. Getting the option description for zypper conf
--help some.option is easy (and maybe it is possible to map the
multi-line ## description to a single 'description' node!).

Here is a draft of lens for zypper (it will need comments and further
improvements). To try it out you can crete a /etc/zypp/zypper.conf file
with contents like the above example, and use the augtool like this:

$ augtool -I /the/dir/with/the/zypper.aug/file
augtool> print /files/etc/zypp/zypper.conf/
/files/etc/zypp/zypper.conf
/files/etc/zypp/zypper.conf/anon
/files/etc/zypp/zypper.conf/anon/description[1] = "Configuration file
for zypper"
/files/etc/zypp/zypper.conf/anon/description[2]
/files/etc/zypp/zypper.conf/anon/description[3] = "Boolean values are 0
1 yes no on off true false"
/files/etc/zypp/zypper.conf/main
/files/etc/zypp/zypper.conf/main/1
/files/etc/zypp/zypper.conf/main/1/description[1] = "Whether to use colors"
/files/etc/zypp/zypper.conf/main/1/description[2]
/files/etc/zypp/zypper.conf/main/1/description[3] = "Default value:
autodetected"
/files/etc/zypp/zypper.conf/main/1/description[4]
/files/etc/zypp/zypper.conf/main/1/description[5]
/files/etc/zypp/zypper.conf/main/1/colors = "yes"
augtool>



Type help for other commands, use TAB key for completion, and check also
the Augeas home page for more info.

What does this mean for libzypp? Basically the above, with respect to
libzypp's files. Currently, you either edit your repos.d/*.repo, locks,
credentials, and other files by hand or you leave it to libzypp's
frontends, or you at least take care not to write comments in those
files, because they will all get removed upon the next change done by
libzypp (what we do there is to rewrite the entire files from in-memory
data upon saving). This can be easily avoided using Augeas and we can
add an editing API for zypp.conf. Plus the bonuses described above.

The library package (libaugeas0) would add 300 kiB of installed size to
libzypp's/zypper's dependencies, (which is not little), plus an optional
200 kiB of the official lenses (augeas-lenses), if we decide to use them.

todo: Look at Augeas' error reporting. The user can of course break the
structure of the file in a way that the lens can't map it to the tree
anymore. If parsing of the file will fail, we need to report why, so
that the user can fix it.
------copy------

I also have some code using the draft lens for zypper ready, so unless
somebody is very much against zypper depending on libaugeas0, i will
soon push it. BTW, can i place system-wide zypper.conf to /etc/zypp (the
user's will be ~/.zypper.conf). Also, i plan to put the zypper.aug to
/usr/share/zypper, so that zypper can tell augeas to read only this .aug
file and parse only the zypper.conf files so that it is quick.

I'm still not sure if 300kiB of a library for reading a INI file is worth it.

Stano

--
To unsubscribe, e-mail: zypp-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-devel+help@xxxxxxxxxxxx

< Previous Next >
References