aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar jesopo2019-12-07 10:42:43 +0000
committerGravatar jesopo2019-12-07 10:42:43 +0000
commit7274d1bf28d2a2282bcdb6a89c9612f1e30b45f0 (patch)
tree6c327281006e47b7fce57cf39398880c578ff49b /src
parentremove -m/-M and BaseModule.command_line - it doesn't work any more (diff)
signature
add ability to save config file
Diffstat (limited to 'src')
-rw-r--r--src/Config.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/Config.py b/src/Config.py
index e9209d2c..6d80b1ca 100644
--- a/src/Config.py
+++ b/src/Config.py
@@ -1,17 +1,28 @@
-import configparser, os, typing
+import collections, configparser, os, typing
class Config(object):
def __init__(self, location: str):
self.location = location
- self._config = {} # type: typing.Dict[str, str]
- self.load()
+ self._config = collections.OrderedDict()
+
+ def _parser(self) -> configparser.ConfigParser:
+ return configparser.ConfigParser(dict_type=collections.OrderedDict)
def load(self):
if os.path.isfile(self.location):
with open(self.location) as config_file:
- parser = configparser.ConfigParser()
+ parser = self._parser()
parser.read_string(config_file.read())
- self._config = {k: v for k, v in parser["bot"].items() if v}
+ self._config.clear()
+ for k, v in parser["bot"].items():
+ if v:
+ self._config[k] = v
+
+ def save(self):
+ with open(self.location, "w") as config_file:
+ parser = self._parser()
+ parser["bot"] = self._config.copy()
+ parser.write(config_file)
def __getitem__(self, key: str) -> typing.Any:
return self._config[key]