|
From: Mario A. <ma...@se...> - 2014-04-28 04:22:20
|
I'm trying to use 'configobj' but not having much success:
(1) It appears that validate() ALWAYS returns True, even if my config
file does not conform to spec.
(2) If I repeat one of the sub-sections in the "many" section I get:
Traceback (most recent call last):
File "./config.py", line 7, in <module>
config = ConfigObj(infile="foo.cfg", configspec="foo.spec")
File "/home/glarms/python/site-packages/configobj.py", line 1229, in
__init__
self._load(infile, configspec)
File "/home/glarms/python/site-packages/configobj.py", line 1318, in
_load
raise error
configobj.ConfigObjError: Parsing failed with several errors.
First error at line 14.
Attached is my (simple) example program, config and spec files.
Any help would be much appreciated.
::::::::::::::
config.py
::::::::::::::
#!/usr/bin/python
import os, sys
from configobj import ConfigObj, ConfigObjError, flatten_errors
from validate import Validator, ValidateError
config = ConfigObj(infile="foo.cfg", configspec="foo.spec")
vtor = Validator()
results = config.validate(vtor, preserve_errors=True)
print "results=", results
::::::::::::::
foo.cfg
::::::::::::::
#
# example config file
#
# global options
[DEFAULT]
FOOBAR = 1
JUNK = 0
# baseline options
[CHANNELS]
[[SRB1-BRIB]]
instance = 0
[[OHLN-BRIB]]
instance = 0
::::::::::::::
foo.spec
::::::::::::::
#
# config spec file for G-larnS
#
[DEFAULT]
FOOBAR = string
JUNK = integer
[CHANNELS]
[[__many__]]
instance = integer(default=0)
off = boolean(default=False)
--
Mario Aranha University of California, Berkeley
ma...@se... Berkeley Seismological Laboratory
Office: 510-643-3898 215 McCone Hall # 4760
Fax: 510-643-5811 Berkeley, CA 94720-4760
|