def getconfigval(self, key): """Returns the value for a given key in the config. Key is expressed as: key.subkey.subsubkey """ # sanitize inputs key = sanitize.cfgkey(key) if not key: raise KeyNotFound(key) keys = key.split('.') config = self.wallet.wallet_config # traverse the path until we get the value for key in keys: config = config[key] return _print(config)
def setconfigval(self, key, value): # FIXME behaviour ok? """Sets a value in the configuration. Key is expressed as: key.subkey.subsubkey """ # sanitize inputs key = sanitize.cfgkey(key) value = sanitize.cfgvalue(value) kpath = key.split('.') value = json.loads(value) # traverse the path until we get to the value we need to set if len(kpath) > 1: branch = self.wallet.wallet_config[kpath[0]] cdict = branch for k in kpath[1:-1]: cdict = cdict[k] cdict[kpath[-1]] = value value = branch if kpath[0] in self.wallet.wallet_config: self.wallet.wallet_config[kpath[0]] = value else: raise KeyNotFound(key)