Skip to content

Commit 134c97e

Browse files
authored
Merge pull request CloudBotIRC#107 from linuxdaemon/gonzobot+config-fix
Switch config object to OrderedDict to retain data order
2 parents 8cdee3c + d370361 commit 134c97e

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

cloudbot/config.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import os
44
import sys
55
import time
6+
from collections import OrderedDict
67

78
logger = logging.getLogger("cloudbot")
89

910

10-
class Config(dict):
11+
class Config(OrderedDict):
1112
"""
1213
:type filename: str
1314
:type path: str
@@ -41,8 +42,10 @@ def load_config(self):
4142
sys.exit()
4243

4344
with open(self.path) as f:
44-
self.update(json.load(f))
45-
logger.debug("Config loaded from file.")
45+
data = json.load(f, object_pairs_hook=OrderedDict)
46+
47+
self.update(data)
48+
logger.debug("Config loaded from file.")
4649

4750
# reload permissions
4851
if self.bot.connections:
@@ -51,5 +54,7 @@ def load_config(self):
5154

5255
def save_config(self):
5356
"""saves the contents of the config dict to the config file"""
54-
json.dump(self, open(self.path, 'w'), sort_keys=True, indent=4)
57+
with open(self.path, 'w') as f:
58+
json.dump(self, f, indent=4)
59+
5560
logger.info("Config saved to file.")

0 commit comments

Comments
 (0)