music-kraken-core/src/music_kraken/utils/config/config.py

69 lines
1.3 KiB
Python
Raw Normal View History

2023-04-13 21:45:50 +00:00
from dataclasses import dataclass
from typing import Optional, List, Union
2023-04-14 09:22:47 +00:00
COMMENT_PREFIX = "// "
2023-04-13 21:45:50 +00:00
@dataclass
class Attribute:
name: str
description: Optional[str]
value: Union[str, List[str]]
2023-04-14 09:22:47 +00:00
@property
def description_as_comment(self):
lines = self.description.split("\n")
return "\n".join(f"{COMMENT_PREFIX}{line}" for line in lines)
2023-04-13 21:45:50 +00:00
@property
def object_from_value(self):
return self.value
2023-04-14 09:22:47 +00:00
def __str__(self):
return f"{self.description_as_comment}\n{self.name}={self.value}"
2023-04-13 21:45:50 +00:00
class SingleAttribute(Attribute):
value: str
2023-04-14 09:22:47 +00:00
class StringAttribute(SingleAttribute):
2023-04-13 21:45:50 +00:00
@property
def object_from_value(self) -> str:
return self.value
class ListAttribute(Attribute):
value: List[str]
2023-04-14 09:22:47 +00:00
def __str__(self):
return f"{self.description_as_comment}\n" + \
"\n".join(f"{self.name}={element}" for element in self.value)
@dataclass
class Description:
description: str
def __str__(self):
return f"\n{self.description}"
class EmptyLine(Description):
def __init__(self):
self.description = "\n"
2023-04-13 21:45:50 +00:00
class Section:
"""
A placeholder class
"""
2023-04-14 09:22:47 +00:00
attribute_list: List[Union[
Attribute,
Description
]]
def __str__(self):
return "\n".join(attribute.__str__() for attribute in self.attribute_list)