|
From: Matthew B. <mat...@gm...> - 2005-12-05 09:05:45
|
Hi,
> You would still have to produce your own error messages from these of
> course - would it be useful if I showed you a (recursive) function to
> produce a list like this ?
I ended up with something like this:
# Check / processing functions for options
def check_result(sct, res, err_strs=3D[], levels=3D['[root]']):
if res is True: return
if res is False: res =3D dict(zip(sct.keys(), [res]*len(sct)))
for (k, v) in sct.items():
if res[k] is True: continue
if isinstance(v, dict):
# Go down one level
levels.append(k)
check_result(v, res[k], err_strs, levels)
continue
try:
vtor.check(sct.configspec[k], v)
except validate.ValidateError, err:
err_strs.append("%s, %s: %s" % (", ".join(levels), k, err))
# Go up one level
if levels: levels.pop()
return err_strs
# Run checks
val_res =3D opts.validate(vtor)
if val_res is not True:
print "\n".join(check_result(opts, val_res))
I hope this is efficient, I am rather new to python. Of course I was
wondering if I was missing some way of avoiding redoing the error
checks, but it sounds like I haven't, and this works fine for me. I
wonder if there is any interest in a patch to the configobj.py
funciton, on the lines of:
def validate(self, validator, section=3DNone, error_strs=3D[], levels=3D['b=
ase'])
then
val_res =3D opts.validate(vtor, errror_strs =3D my_list)?
Thanks a lot.
Matthew
|