Project Home

turfig.py

Abstract

Turfig configuration system. It does not get any simpler. My turf, your turf, we configure our turf as we like it.

Table of Contents

Description

Turfig configuration system. It does not get any simpler. My turf, your turf, we configure our turf as we like it.

Turfig is a library for configuration files written in the form of Python classes. This basically adds support for declaration and validation of the configuration variables and is a very flexible and simple configuration system for any kind of thing.

This module provides a system of validation for configuration information defined as class variables. You write classes to define configuration settings, all within glorious Python. You put them in a file, something like this:

class BaseConfig(Config):

   __vars__ = (
      ConfigVar('Extension', str, 'Extension to use.'),
      ConfigVar('Compression', bool, 'Enable compression.'),
   )

   # Set default values
   Extension = 'asp'
   Compression = False
   Encoding = 'latin-1'

And then maybe in another module, if desired:

class HomeConfig(BaseConfig):

   # Override compression value.
   Compression = True

To validate a configuration, simply call the validate() function of this module. All the configuration variables defined in __vars__ will be cross-checked against the attributes of the given object.

You can inherit and share the configuration data, they are just contained by Python classes. You can also instantiate those classes to do some initializations dynamically in the constructor.

Please Donate!

Important

This computer program or library is provided for free. I am aware that some of the programs that I provide for free allow people to get their work done faster or better, save them time and money. If you are using this program for benefit, especially if you are using it within a commercial environment and it saves you time or work, please consider making a donation by sending me a book from my Amazon Wishlist or by a direct donation to my company's PayPal account by clicking on the link below.

Download

Download program here.