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 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_updates(self): content = """<plist version="1.0"> <dict> <key>key1</key> <string>before</string> <key>key2</key> <integer>10</integer> </dict> </plist>""" self.fp.setContent(PREAMBLE + content) config = ConfigDict() writable = WritableConfig(config, self.configFile) writable.read() writable.set({"key1": "after"}) writable.set({"key2": 15}) writable.set({"key2": 20}) # override previous set writable.set({"key3": ["a", "b", "c"]}) self.assertEquals(writable.currentConfigSubset, { "key1": "after", "key2": 20, "key3": ["a", "b", "c"] }) writable.save() writable2 = WritableConfig(config, self.configFile) writable2.read() self.assertEquals(writable2.currentConfigSubset, { "key1": "after", "key2": 20, "key3": ["a", "b", "c"] })
def test_updates(self): content = """<plist version="1.0"> <dict> <key>key1</key> <string>before</string> <key>key2</key> <integer>10</integer> </dict> </plist>""" self.fp.setContent(PREAMBLE + content) config = ConfigDict() writable = WritableConfig(config, self.configFile) writable.read() writable.set({"key1": "after"}) writable.set({"key2": 15}) writable.set({"key2": 20}) # override previous set writable.set({"key3": ["a", "b", "c"]}) self.assertEquals(writable.currentConfigSubset, {"key1": "after", "key2": 20, "key3": ["a", "b", "c"]}) writable.save() writable2 = WritableConfig(config, self.configFile) writable2.read() self.assertEquals(writable2.currentConfigSubset, {"key1": "after", "key2": 20, "key3": ["a", "b", "c"]})