Skip to content

Commit

Permalink
Updated config command
Browse files Browse the repository at this point in the history
  • Loading branch information
Aperture32GLaDOS authored Jan 25, 2022
1 parent 3611e79 commit 23843be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 3 additions & 5 deletions config.json
Original file line number Diff line number Diff line change
@@ -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-----"
}
}
9 changes: 7 additions & 2 deletions parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()


Expand Down

0 comments on commit 23843be

Please sign in to comment.