ANN: config module v0.3.4 released

V

Vinay Sajip

A new version of the Python config module has been released.

What Does It Do?
================
The config module allows you to implement a hierarchical configuration
scheme with support for mappings and sequences, cross-references
between one part of the configuration and another, the ability to
flexibly access real Python objects, facilities for configurations to
include and cross-reference one another, simple expression evaluation
and the ability to change, save, cascade and merge configurations. You
can easily integrate with command line options using optparse.

This module has been developed on python 2.3 but should work on
version 2.2 or greater. A test suite using unittest is included in the
distribution.

A very simple configuration file (simple.cfg):

# starts here
message: Hello, world!
#ends here

a very simple program to use it:

from config import Config

cfg = Config(file('simple.cfg'))
print cfg.message

results in:

Hello, world!

Configuration files are key-value pairs, but the values can be
containers that contain further values.

A simple example - with the example configuration file:

messages:
[
{
stream : `sys.stderr`
message: 'Welcome'
name: 'Harry'
}
{
stream : `sys.stdout`
message: 'Welkom'
name: 'Ruud'
}
{
stream : $messages[0].stream
message: 'Bienvenue'
name: Yves
}
]

a program to read the configuration would be:

from config import Config

f = file('simple.cfg')
cfg = Config(f)
for m in cfg.messages:
s = '%s, %s' % (m.message, m.name)
try:
print >> m.stream, s
except IOError, e:
print e

which, when run, would yield the console output:

Welcome, Harry
Welkom, Ruud
Bienvenue, Yves

The above example just scratches the surface. There's more information
about this module available at

http://www.red-dove.com/python_config.html

Comprehensive API documentation is available at

http://www.red-dove.com/config/index.html

As always, your feedback is most welcome (especially bug reports,
patches and suggestions for improvement). Enjoy!

Cheers

Vinay Sajip
Red Dove Consultants Ltd.

Changes since the last release posted on comp.lang.python:
==========================================================
Added ConfigInputStream to provide better Unicode support.
Added ConfigReader.setStream().
Renamed config.get() to getByPath(), and likewise for ConfigList.
Added Mapping.get() to work like dict.get().
Added logconfig.py and logconfig.cfg to distribution.
Simplified parseMapping().
Allowed Config.__init__ to accept a string as well as a stream. If a
string is passed in, streamOpener is used to obtain the stream to be
used.
Changed addNamespace/removeNamespace to make name specification
easier.
Refactored save(), added Container.writeToStream and
Container.writeValue() to help with this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top