config (version 4.0.1)
index
/raid1/home/rj/src/github/Python-config-module/config_moxad/config.py

human readable config files
 
This module reads human-readable config files with sections comprised
of keyword = values, where the values can be a simple scalar (by default)
or arrays, or associative arrays (dicts).
 
You can supply an optional definitions file providing value types, allowed
values, different separators, etc.  It can recursively include other config
files.

 
Modules
       
re
sys

 
Classes
       
builtins.object
Config

 
class Config(builtins.object)
    Config(config_file, defs_file='', **options)
 
Read a config file.
 
The format of the config file will be:
    section1:
        keyword1    = value1, value2, value3    # for array
        keyword2    = value1                    # for scalar
        keyword3    = key1=val1, key2=val2      # for hash
 
    section2:
        keyword4    = ...
 
Continuation lines can be done with a backslash at the end of a line.
It is recursive, using '#include file' to read in other config files.
 
A optional definitions file can be given to tell it if the
type of data above for the keywords is different than the
default type of 'scalar'.   The definitions file is of format:
    keyword         = string
    type            = scalar | array | hash
    allowed-values  = value1, value2, ...
    separator       = string (default = ,)
Each block of definitions are separated by at least 1 blank line.
A blank line signifies the end of a definition block.
 
The 'keyword' string value given can be specific to a section, such as:
    keyword  = some-section:some-keyword
If the section name is not given then it applies to the keyword of that
name in all sections.  A section specific definition over-rides a generic
one.
 
The 'separator' given in the definitions file applies to the
values the config file, and not the definitions file itself.  
ie: the separator used in the definitions file to separate values in
'allowed-values' is always a comma.
 
If you want the literal separator character in your data, or
you change it, be sure to escape your data in the config file
appropriately with the backslash character.
 
If the definitions file is given, then only keywords specified in the
definitions file can used in the configuration file.  Unless the
'AcceptUndefinedKeywords' option is used and set to a true value.
 
if there is no definitions file to specify different data types, you
can specify the type in the config file surrounded by brackets, such as:
    section1:
        keyword1 (array)  = value1, value2, value3    # for array
        keyword2 (scalar) = value1                    # for scalar
        keyword3 (hash)   = key1=val1, key2=val2      # for hash
 
Note that a 'section' is just a way of grouping and organizing
keywords.  Whatever the type of a keyword (scalar, array or hash),
it is the same if that keyword is used in multiple 'section's.
 
Use single or double quotes around a value if you need leading or
trailing whitespace on a value.
 
To see debug output:  config.Config.set_debug( True )
 
  Methods defined here:
__init__(self, config_file, defs_file='', **options)
Initialization function.
Not user callable.  Ignore this.  Go away.
get_keywords(self, section)
Return a list of the keywords used in a section in a config file
 
keywords = conf.get_keywords( section )
 
eg:
    sections = conf.get_sections()
    for section in sections:
        keywords = conf.get_keywords( section )
        for keyword in keywords:
            ...
get_sections(self)
Return a list of the section names in a config file
 
sections = conf.get_sections()
get_type(self, *args)
Get the type of a keyword.
 
type = conf.get_type( keyword )
type = conf.get_type( section, keyword )
 
type can be any of 'scalar', 'array' or 'hash'.
The config format could be any of:
    keyword1 = value1   (scalar)
    keyword2 = value2, value3, value4  (array)
    keyword3 = key5 = value5, key6 = value6, key7 = value7 (hash)
 
If the keyword is not found, the default type of 'scalar' is returned
get_values(self, section, keyword)
Return values of a keyword in a section
 
values = conf.get_values( section, keyword )
eg:
    sections = conf.get_sections()
    for section in sections:
        print( section )
        keywords = conf.get_keywords( section )
        for keyword in keywords:
            print( "\t" + keyword )
            values = conf.get_values( section, keyword )
            print( "\t\t", values )
 
The data-type of the return value depends on the 'type' of
the data.  By default it is a scalar, so a string would be 
returned.  But the type can be changed via the optional
definitions file, which can specify either a scalar, array
or hash for a keyword.  The return value of get_values() 
is the appropriate type.
 
If the type is unknown to the program for a specific keyword,
it can find out with a call to get_type().

Class methods defined here:
set_debug(value) from builtins.type

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)