Skip to main content

A central configuration service for Zope 2/3-based applications based on a pseudo-hierarchical INI-file format with model support for defining the configuration schema

Project description

Introduction

haufe.hrs.configuration provides a central configuration service for Zope-based application with a pseudo-hierarchical configuration mechanism.

Features

  • configurations based on INI files

  • configurations are pseudo-hierarchical (section names can be dotted-names (like ‘cms.somepath’, ‘foo.bat.something.else’)

  • all valid configuration options are defined through a model (an INI-style file defining sections, their options, their types and default values). The model is used for performing type-checking and providing defaults

  • models and configuration files can be loaded all-in-one or incremental into the configuration service

  • optional supervision of changes to the configuration file (a change of a configuration file can trigger an immediate reload of the configuration)

  • very simple API

  • ZCML directives for defining the location of models and configuration files

  • integrates easily with Zope 2 and Zope 3

  • can be used outside Zope (pure Python applications) - the package has only a minor number of dependencies to other zope.* packages

  • good test coverage

Defining a model

A model definition may look like this:

[cms]
HRSCheckoutPath=string,default=42
HRSCheckoutURL=string
HRSImportPath=string
HRSImportClientPath=string
HRSPreviewPath=string
HRSPreviewClientPath=string
CvtSGMLtoRtfPath=string
CvtSGMLtoRtfMaxWait=int
ADB2StartURLbase=string
ADB2Version=int
ToolboxStartURLbase=string
NormenDBStartURLbase=string
VADBStartURLbase=string
LauflistenStartURL=string
HRS2UIStartURLbase=string
MedienStartURLbase=string

[cms.db]
datenbank1=
datenbank2=
datenbank3=

You see that the syntax is pretty simple. The syntax is always:

<optionname> = <type>, [default=<default-value>]

<optionname> is mandatory. <type> defaults to ‘string’ and can be omitted (other types are ‘int’, ‘list’, ‘float’, ‘complex’). The ‘=’ is mandatory (otherwise Python’s configuration parser will spit out an error. An optional default can be defined (otherwise None will be used).

A related configuration file may look like this:

[cms]
HRSCheckout = /foo/bar
adb2version = 44
hrscheckoutpath = 12
port = 22


[toolbox]
partition_id = Toolbox
nginx_baseurl = http://weiss.nix.de/

For values of the configuration are accessible through dotted-names like:

cms.ADB2Version
CMS.HRSCheckoutURL
cms.db.datenbank

Usage

From Python:

from haufe.hrs.configuration import ConfigurationService

service = ConfigurationService(watch=True)
service.registerModel('example/model')
service.loadConfiguration('example/sample_config/all-in-one.ini')
print service.getConfigurations()
print service.get('cms.ADB2Version')
print service.get('datenbank', prefix='cms.db')

ZCML integration

haufe.hrs.configuration provides two ZCML directives hrs:registerConfigurationModel and hrs:registerConfiguration:

<configure xmlns="http://namespaces.zope.org/zope"
           xmlns:hrs="http://namespaces.haufe.de/hrs">

  <hrs:registerConfigurationModel
      configuration="haufe/hrs/configuration/tests/model"
  />

  <hrs:registerConfiguration
      configuration="haufe/hrs/configuration/tests/example-config.ini"
  />

</configure>

Credits

The implementation is based on the cfgparse module by Dann Gass

Author

haufe.hrs.configuration was written by Andreas Jung for Haufe Mediengruppe, Freiburg, Germany and ZOPYX Ltd. & Co. KG, Tuebingen, Germany.

License

haufe.hrs.configuration is licensed under the Zope Public License 2.1. See the included ZPL.txt file.

Contact

ZOPYX Ltd. & Co. KG
Andreas Jung
Charlottenstr. 37/1
D-72070 Tuebingen, Germany
E-mail: info at zopyx dot com

Changelog

0.4.0 (2008-11-03)

  • first public release

  • updated documentation and tests

  • some internal cleanup in order to fix race-conditions

0.3.0 (2008-11-02)

  • added pyinotify dependency

  • watching configuration file changes

  • sending ConfigurationChangedEvent upon reload()

0.2.0 (2008-11-01)

  • added service implementation

  • added zcml implementation

  • more tests

0.1.0 (2008-10-31)

  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

haufe.hrs.configuration-0.4.0.tar.gz (11.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page