def command_readConfig(self, command): """ Return current configuration @param command: the dictionary parsed from the plist read from stdin @type command: C{dict} """ config.reload() # config.Memcached.Pools.Default.ClientEnabled = False result = {} for keyPath in WRITABLE_CONFIG_KEYS: value = getKeyPath(config, keyPath) if value is not None: # Note: config contains utf-8 encoded strings, but plistlib # wants unicode, so decode here: if isinstance(value, str): value = value.decode("utf-8") setKeyPath(result, keyPath, value) self.respond(command, result)
def command_writeConfig(self, command): """ Write config to secondary, writable plist @param command: the dictionary parsed from the plist read from stdin @type command: C{dict} """ writable = WritableConfig(config, config.WritableConfigFile) writable.read() valuesToWrite = command.get("Values", {}) # Note: values are unicode if they contain non-ascii for keyPath, value in flattenDictionary(valuesToWrite): if keyPath in WRITABLE_CONFIG_KEYS: writable.set(setKeyPath(ConfigDict(), keyPath, value)) try: writable.save(restart=False) except Exception, e: self.respond(command, {"error": str(e)})
def test_keyPath(self): d = ConfigDict() setKeyPath(d, "one", "A") setKeyPath(d, "one", "B") setKeyPath(d, "two.one", "C") setKeyPath(d, "two.one", "D") setKeyPath(d, "two.two", "E") setKeyPath(d, "three.one.one", "F") setKeyPath(d, "three.one.two", "G") self.assertEquals(d.one, "B") self.assertEquals(d.two.one, "D") self.assertEquals(d.two.two, "E") self.assertEquals(d.three.one.one, "F") self.assertEquals(d.three.one.two, "G") self.assertEquals(getKeyPath(d, "one"), "B") self.assertEquals(getKeyPath(d, "two.one"), "D") self.assertEquals(getKeyPath(d, "two.two"), "E") self.assertEquals(getKeyPath(d, "three.one.one"), "F") self.assertEquals(getKeyPath(d, "three.one.two"), "G")