contentmonster/classes/config.py

28 lines
783 B
Python
Raw Normal View History

2021-11-20 14:40:07 +00:00
import configparser
from classes.vessel import Vessel
from classes.directory import Directory
class MonsterConfig:
@classmethod
def fromFile(cls, path):
parser = configparser.ConfigParser()
parser.read(path)
if not "MONSTER" in parser.sections():
raise ValueError("Config file does not contain a MONSTER section!")
2021-11-22 10:14:38 +00:00
config = cls()
2021-11-20 14:40:07 +00:00
for section in parser.sections():
if section.startswith("Directory"):
2021-11-22 10:14:38 +00:00
config.directories.append(Directory.fromConfig(parser[section]))
2021-11-20 14:40:07 +00:00
elif section.startswith("Vessel"):
2021-11-22 10:14:38 +00:00
config.vessels.append(Vessel.fromConfig(parser[section]))
return config
2021-11-20 14:40:07 +00:00
def __init__(self):
2021-11-22 10:14:38 +00:00
self.directories = []
self.vessels = []