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_flattenDictionary(self): dictionary = { "one": "A", "two": { "one": "D", "two": "E", }, "three": { "one": { "one": "F", "two": "G", }, }, } self.assertEquals( set(list(flattenDictionary(dictionary))), set([("one", "A"), ("three.one.one", "F"), ("three.one.two", "G"), ("two.one", "D"), ("two.two", "E")]))
def test_flattenDictionary(self): dictionary = { "one" : "A", "two" : { "one" : "D", "two" : "E", }, "three" : { "one" : { "one" : "F", "two" : "G", }, }, } self.assertEquals( set(list(flattenDictionary(dictionary))), set([("one", "A"), ("three.one.one", "F"), ("three.one.two", "G"), ("two.one", "D"), ("two.two", "E")]) )