From 23843beec0ef70d7ee825da5001136bef3c9f8aa Mon Sep 17 00:00:00 2001 From: Aperture32GLaDOS <66212752+Aperture32GLaDOS@users.noreply.github.com> Date: Tue, 25 Jan 2022 16:46:26 +0000 Subject: [PATCH] Updated config command --- config.json | 8 +++----- parsing.py | 9 +++++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/config.json b/config.json index 7ed8ef4..09fc913 100644 --- a/config.json +++ b/config.json @@ -1,7 +1,5 @@ { - "servers": - { - "127.0.0.1": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsuD9U5W/xYsFFExVwvNE\noopQQ2Cqu0zlM95qrndO/We+UiZ2twbCYu4bzJu48yP0JdYbZZ3MqoEI6ZFrwTFx\n2arP3AeF8OODaECRybX/EkcMrvVUzJae5+4uVP6srKHHvNQLXuCwaQURac/hctQF\nJFv9/ulR9VSFLAJa1JU8TWN2JhjxHDjBUt1yW2a+BIx2FELA56IteC8Pci4vDX2J\n8Qos8GeKAQE7kmJYFGt/YomFjrntCRjqhO9tpnljB62FIc+ipUyE2jjnIyfvQYv/\n9L+XiYAeU5STC5GlS9v5Zu59lIj6xncgvQdK18Lc5rsrYAc0iKSaNBK40FBw5akF\ncQIDAQAB\n-----END PUBLIC KEY-----" - }, - "test": "Hello world!" + "servers": { + "127.0.0.1": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsuD9U5W/xYsFFExVwvNE\noopQQ2Cqu0zlM95qrndO/We+UiZ2twbCYu4bzJu48yP0JdYbZZ3MqoEI6ZFrwTFx\n2arP3AeF8OODaECRybX/EkcMrvVUzJae5+4uVP6srKHHvNQLXuCwaQURac/hctQF\nJFv9/ulR9VSFLAJa1JU8TWN2JhjxHDjBUt1yW2a+BIx2FELA56IteC8Pci4vDX2J\n8Qos8GeKAQE7kmJYFGt/YomFjrntCRjqhO9tpnljB62FIc+ipUyE2jjnIyfvQYv/\n9L+XiYAeU5STC5GlS9v5Zu59lIj6xncgvQdK18Lc5rsrYAc0iKSaNBK40FBw5akF\ncQIDAQAB\n-----END PUBLIC KEY-----" + } } \ No newline at end of file diff --git a/parsing.py b/parsing.py index a64389f..9273287 100644 --- a/parsing.py +++ b/parsing.py @@ -51,7 +51,12 @@ def setConfig(config, keys, newValue): # Given a dictionary, an array of keys and a value, change what the value of the nested # keys are. Equivalent to something like config[key1][key2][key3]... = newVal if len(keys) > 1: - return setConfig(config[keys[0]], keys[1:], newValue) + try: + config[keys[0]] = setConfig(config[keys[0]], keys[1:], newValue) + except KeyError: # If part of the key isn't assigned, + config[keys[0]] = {} # Assign it a blank dictionary + setConfig(config[keys[0]], keys[1:], newValue) # And continue + return config else: config[keys[0]] = newValue return config @@ -219,7 +224,7 @@ def handle(self, client): elif self.type == "set": config = setConfig(config, self.index, self.newVal) configFile = open("config.json", "w") - json.dump(config, configFile) + json.dump(config, configFile, indent=4) configFile.close()