|
From: Sumit's M. L. <li...@ba...> - 2015-08-01 00:34:32
|
I've been looking through the docs and StackOverflow and I'm still a
little stumped on this. Can I have an optional section in my config
specification? For example, say I had this as my configspec:
config_specification = """
[General]
sample_rate = float
[Data]
[[__many__]]
type = option('sense.xml')
[[[Identifier]]]
type = option("name", "mac", "uuid")
adapter = string(default='')
id = string(default='')
file = string(default='')
[[[Location]]]
type = option("virtual", "gps")
longitude = string(default='')
latitude = string(default='')
altitude = string(default='')
speed = string(default='')
climb = string(default='')
track = string(default='')
longutide_error = string(default='')
latitude_error = string(default='')
altitude_error = string(default='')
speed_error = string(default='')
climb_track = string(default='')
track_error = string(default='')
"""
Is there a way to make [[[Locaiton]]] optional, so it can be missing and
still pass validation (assuming that I do validation like so):
cfg = ConfigObj(filename,
configspec=BootStrap.config_specification.split('\n'))
test = cfg.validate(Validator())
valid = True
for (section_list, key, _) in flatten_errors(cfg, test):
if key is not None:
logging.error('Invalid value for key {0} in section
{1}'.format(key, ', '.join(section_list)))
valid = False
else:
logging.error('Section {0} failed validation'.format(',
'.join(section_list)))
valid = False
if not valid:
exit(3)
Thanks
Sumit
|