Hello Matthew,
> Matthew Brett wrote:
>
> >Hi,
> >
> >I am very sorry if I missed something simple, but is there an easy way
> >to get a list of informative validation error messages from the
> >ConfigObj.validate interface?
> >
> >I have run:
> >
> >res = config_obj.validate(vtor)
> >
> >and have a nested list of boolean values - but I want to be able to
res is a nested *dictionary*. It has the same structure as your configobj.
> >print out a list of items that failed validation and why. I am just
So how do you want the failures represented ?
You want your nested dictionary of True/False flattened to a list of failures ?
Simple enough... *but*, how do you want nested keys represented in this list ?
Suppose you have a config file that looks like :
Key1 = value1
Key2 = value2
[section]
Key1 = value1
Key2 = value2
[sub-section]
Key1 = value1
Key2 = value2
Suppose Key1 in the top level section *and* Key1 in 'sub-section' fail, how do you want to show that ?
I can suggest two options :
['Key1', 'section/sub-section/Key1']
[['Key1'], [['section', ['sub-section'], ['Key1']] ]
The first is 'flatter', the second is arguably more 'accurate'.
It should be easy enough to write a function that iterates over either the res dictionary or your ConfigObj *and* the res dictionary - flattening it to a list.
Would this do what you want ?
All the best,
Fuzzyman
Http://www.voidspace.org.uk/python/index.shtml
> >thinking about reiterating through the option dictionary, running the
> >validation by hand (.check) for each False in the 'res' dictionary,
> >but this seems very cludgy - is there a better way?
> >
> >Thanks a lot,
> >
> >Matthew
|