From 189a2ab696e5a2616175f06936ca025ba63365ee Mon Sep 17 00:00:00 2001 From: sanjayk03-dev Date: Fri, 26 Jan 2024 14:07:00 +0530 Subject: [PATCH] added condition for key --- src/py/bbctrl/Config.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/py/bbctrl/Config.py b/src/py/bbctrl/Config.py index 52f3597..aac5961 100644 --- a/src/py/bbctrl/Config.py +++ b/src/py/bbctrl/Config.py @@ -132,13 +132,14 @@ class Config(object): config[name] = template['min'] if template['type'] == 'list': - config = config[name] + if 'index' in template: + config = config[name] - for i in range(len(template['index'])): - if len(config) <= i: config.append({}) + for i in range(len(template['index'])): + if len(config) <= i: config.append({}) - for name, tmpl in template['template'].items(): - self.__defaults(config[i], name, tmpl) + for name, tmpl in template['template'].items(): + self.__defaults(config[i], name, tmpl) else: for name, tmpl in template.items(): @@ -214,11 +215,14 @@ class Config(object): # Handle list if tmpl['type'] == 'list': - for i in range(len(tmpl['index'])): - if config is not None and i < len(config): conf = config[i] - else: conf = None - self._encode(name, index + tmpl['index'][i], conf, - tmpl['template'], with_defaults) + if 'index' in tmpl: + for i in range(len(tmpl['index'])): + if config is not None and i < len(config): conf = config[i] + else: conf = None + self._encode(name, index + tmpl['index'][i], conf, + tmpl['template'], with_defaults) + else: + self.values[name]=value; return # Update config values