support different Config names

This commit is contained in:
jesopo 2020-01-30 11:50:40 +00:00
parent e6d0cba63b
commit 49f14caf42
2 changed files with 5 additions and 5 deletions

View file

@ -46,7 +46,7 @@ if args.version:
print("BitBot %s" % IRCBot.VERSION) print("BitBot %s" % IRCBot.VERSION)
sys.exit(0) sys.exit(0)
config = Config.Config(args.config) config = Config.Config("bot", args.config)
config.load() config.load()
DATA_DIR = os.path.expanduser(config.get("data-directory", "~/.bitbot")) DATA_DIR = os.path.expanduser(config.get("data-directory", "~/.bitbot"))

View file

@ -1,8 +1,8 @@
import collections, configparser, os, typing import collections, configparser, os, typing
class Config(object): class Config(object):
def __init__(self, name: str, location: str):
def __init__(self, location: str): self._name = name
self.location = location self.location = location
self._config: typing.Dict[str, str] = collections.OrderedDict() self._config: typing.Dict[str, str] = collections.OrderedDict()
@ -15,14 +15,14 @@ class Config(object):
parser = self._parser() parser = self._parser()
parser.read_string(config_file.read()) parser.read_string(config_file.read())
self._config.clear() self._config.clear()
for k, v in parser["bot"].items(): for k, v in parser[self._name].items():
if v: if v:
self._config[k] = v self._config[k] = v
def save(self): def save(self):
with open(self.location, "w") as config_file: with open(self.location, "w") as config_file:
parser = self._parser() parser = self._parser()
parser["bot"] = self._config.copy() parser[self._name] = self._config.copy()
parser.write(config_file) parser.write(config_file)
def __getitem__(self, key: str) -> typing.Any: def __getitem__(self, key: str) -> typing.Any: