monsterwell/classes/config.py

25 lines
589 B
Python
Raw Normal View History

2022-12-23 13:18:32 +00:00
from configparser import ConfigParser
2023-01-09 17:18:59 +00:00
from .directory import Directory
from .server import Server
2022-12-23 13:18:32 +00:00
class Config:
def __init__(self):
self._parser = ConfigParser()
@classmethod
def from_file(cls, path):
o = cls()
o._parser.read(path)
return o
@property
2023-01-09 17:18:59 +00:00
def directories(self):
2023-01-09 17:41:18 +00:00
for section in self._parser.sections():
2023-01-09 17:18:59 +00:00
if section.startswith("Directory "):
2023-01-09 17:41:18 +00:00
yield Directory.from_config(self._parser[section])
2022-12-23 13:18:32 +00:00
@property
2023-01-09 17:18:59 +00:00
def server(self):
2023-01-09 17:41:18 +00:00
return Server.from_config(self._parser["Server"])