Adding getcfg() core method
Turned out to be trivial addition with current search method.
Needed for autodoc generator, but could be useful for others as well.
@@ -626,6 +626,22 @@ class Chip:
return keys
+ ###########################################################################
+ def getcfg(self, *args, cfg=None):
+ """
+ Returns sub-dictionary from SC schema based on key-sequence provided.
+ """
+
+ if cfg is None:
+ cfg = self.cfg
+
+ if len(list(args)) > 0:
+ keypath = ','.join(args[:-1])
+ self.logger.debug('Getting cfg for: %s', args)
+ localcfg = self._search(cfg, keypath, *args, mode='getcfg')
+
+ return copy.deepcopy(localcfg)
+
###########################################################################
def set(self, *args, cfg=None, clobber=True, field='value'):
'''
@@ -715,6 +731,8 @@ class Chip:
self.logger.debug(f'Appending value {args[-1]} to [{keypath}]')
return self._search(cfg, keypath, *all_args, field='value', mode='add')
+
+
###########################################################################
def _allkeys(self, cfg, keys=None, keylist=None):
'''
@@ -828,6 +846,8 @@ class Chip:
if not param in cfg:
self.error = 1
self.logger.error(f"Get keypath [{keypath}] does not exist.")
+ elif mode == 'getcfg':
+ return cfg[param]
elif mode == 'getkeys':
return cfg[param].keys()
else:
@@ -1078,7 +1098,7 @@ class Chip:
prefix=prefix)
###########################################################################
- def merge(self, cfg1, cfg2, append=False, path=None):
+ def merge(self, cfg1, cfg2, append=False):
"""
Merges the SC configuration dict cfg2 into cfg1.
@@ -1094,8 +1114,6 @@ class Chip:
and only d2 with identical keylists are merged.
append (bool): If True, for list variables,the new config valuse
are appended to the old values.
- path (sring): Temporary variable tracking key path
-
"""
#creating local copy of original dict to be overwritten
@@ -1119,6 +1137,8 @@ class Chip:
#returning dict
return localcfg
+
+
###########################################################################
def _keypath_empty(self, key, cfg):
emptylist = ("null", None, [])
