Module zcfg_addon
[frames | no frames]

Module zcfg_addon

ZConfig extension that allows one to modify and save the configuration.

The ZConfig library parses a config file, validating it against a schema, and returns a hierarchy of objects with matching keys and values.

There are a number of use cases where the config values have to be modified, and the resulting config has to be saved to file. In addition, it is sometimes convenient to convert the hierarchy of objects representing the config, to and from a hierarchy of nested dictionaries.

This extension implements such functionality by adding, at runtime, five methods, one function and one class to the imported ZConfig modules and classes, avoiding changes to the ZConfig source code.

It has been tested using ZConfig v.2.2 and Python v.2.3.

See the test function source code for examples of usage of the methods, function and class.


Version:

0.2

Author:

Nicola Larosa

Contact:

<nico@tekNico.net>

License:

MIT license; see LICENSE file

Classes
ZConfigGenerator ZConfig config file generator extension.

Function Summary
  addSectionToMultisection(self, typeName, valDict)
Add a flat section (no subsections) to a Multisection object.
  addValueToMultikey(self, name, val)
Add one value to a Multikey object.
  delSectionFromMultisection(self, typeName, idx)
Delete a section from a Multisection object.
  delValueFromMultikey(self, name, idx)
Delete a value from a Multikey object.

SectionValue

fromDict(schema, cfgDict)
Build a SectionValue config object from a conforming dictionary.
  modSingleValue(self, name, val)
Modify a simple value.
  test()
Main testing function, invoked when the script is launched.

dict

toDict(self, sectName)
Convert a SectionValue object to a dictionary.

Variable Summary
str __revision__: summary of metadata from the Subversion repository
str __version__: string computed from the versionInfo value
str FALSE_STR: False bool value in generated text, may be no, off, false
str TRUE_STR: True bool value in generated text, may be yes, on, true
tuple versionInfo: tuple with current major and minor version numbers

Function Details

addSectionToMultisection(self, typeName, valDict)

Add a flat section (no subsections) to a Multisection object.

Method added to the ZConfig.matcher.SectionValue class.

Parameters:
typeName -

name of the type of the Multisection

valDict -

dict of values to be used in the section to be added

Returns:

None

Raises:
AssertionError -

raised if typeName is not an attribute of self, or if its childInfo is not a Multisection

addValueToMultikey(self, name, val)

Add one value to a Multikey object.

Method added to the ZConfig.matcher.SectionValue class.

Parameters:
name -

name of the Multikey

val -

value to be added

Returns:

None

Raises:
AssertionError -

raised if name is not an attribute of self, or if its childInfo is not a Multikey

delSectionFromMultisection(self, typeName, idx)

Delete a section from a Multisection object.

Method added to the ZConfig.matcher.SectionValue class.

Parameters:
typeName -

name of the type of the Multisection

idx -

index of the section to be deleted

Returns:

None

Raises:
AssertionError -

raised if typeName is not an attribute of self, or if its childInfo is not a Multisection

delValueFromMultikey(self, name, idx)

Delete a value from a Multikey object.

Method added to the ZConfig.matcher.SectionValue class.

Parameters:
name -

name of the Multikey

idx -

index of value to be deleted

Returns:

None

Raises:
AssertionError -

raised if name is not an attribute of self, or if its childInfo is not a Multikey

fromDict(schema, cfgDict)

Build a SectionValue config object from a conforming dictionary.

Factory function added to the ZConfig.loader module.

Parameters:
schema -

a SchemaType object

cfgDict -

a dictionary tree, as returned by the toDict method

Returns:

a SectionValue object with the same values as cfgDict


           (type=

SectionValue

)

modSingleValue(self, name, val)

Modify a simple value.

Method added to the ZConfig.matcher.SectionValue class.

Parameters:
name -

name of the Key

val -

value to be modified

Returns:

None

Raises:
AssertionError -

raised if name is not an attribute of self, or if its childInfo is not a simple Key

test()

Main testing function, invoked when the script is launched.

Contains usage examples of the added methods, class and function.

toDict(self, sectName=None)

Convert a SectionValue object to a dictionary.

Recursive method added to the ZConfig.matcher.SectionValue class.

Parameters:
sectName -

optional, name of the section if different from the type name

Returns:

a tree of dictionaries containing the section values


           (type=

dict

)

Variable Details

__revision__

summary of metadata from the Subversion repository

Type:
str
Value:
'$Id: zcfg_addon.py 10 2005-03-07 22:05:31Z nl $'                      

__version__

string computed from the versionInfo value

Type:
str
Value:
'0.2'                                                                  

FALSE_STR

False bool value in generated text, may be no, off, false

Type:
str
Value:
'no'                                                                   

TRUE_STR

True bool value in generated text, may be yes, on, true

Type:
str
Value:
'yes'                                                                  

versionInfo

tuple with current major and minor version numbers

Type:
tuple
Value:
(0, 2)                                                                 

Generated by Epydoc 2.1 on Mon Mar 7 23:23:19 2005 http://epydoc.sf.net