added connection settings

This commit is contained in:
Hellow
2023-04-15 13:01:20 +02:00
parent 4516e40268
commit 4f12dcbc78
6 changed files with 62 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
from .logging import LOGGING_SECTION
from .audio import AUDIO_SECTION
from .connection import CONNECTION_SECTION
from .config import read, write, config

View File

@@ -87,9 +87,25 @@ class IntAttribute(SingleAttribute):
return int(self.value)
class BoolAttribute(SingleAttribute):
def validate(self, value: str):
if value.lower().strip() not in {"true", "false"}:
raise SettingValueError(
setting_name=self.name,
setting_value=value,
rule="has to be a bool (true/false)"
)
@property
def object_from_value(self) -> bool:
return self.value.lower().strip() in {"yes", "y", "t", "true"}
class FloatAttribute(SingleAttribute):
def validate(self, value: str):
if not value.isnumeric():
try:
float(value)
except ValueError:
raise SettingValueError(
setting_name=self.name,
setting_value=value,

View File

@@ -7,6 +7,7 @@ from ..path_manager import LOCATIONS
from .base_classes import Description, Attribute, Section, EmptyLine, COMMENT_PREFIX
from .audio import AUDIO_SECTION
from .logging import LOGGING_SECTION
from .connection import CONNECTION_SECTION
class Config:
@@ -19,6 +20,8 @@ class Config:
"If you, for some reason wanna fill your drive real quickly, I mean enjoy HIFI music,\n"
"feel free to tinker with the Bitrate or smth. :)"),
AUDIO_SECTION,
Description("Modify how Music-Kraken connects to the internet:"),
CONNECTION_SECTION,
Description("For all your Logging needs.\n"
"If you found a bug, and wan't to report it, please set the Logging level to 0,\n"
"reproduce the bug, and attach the logfile in the bugreport. ^w^"),

View File

@@ -0,0 +1,35 @@
import logging
from typing import Callable
from .base_classes import SingleAttribute, StringAttribute, Section, FloatAttribute, Description, IntAttribute, EmptyLine, BoolAttribute
class ConnectionSection(Section):
def __init__(self):
self.USE_TOR = BoolAttribute(
name="tor",
description="Route ALL traffic through Tor.\nNo guarantee though!",
value="false"
)
self.CHUNK_SIZE = IntAttribute(
name="chunk_size",
description="Size of the chunks that are streamed.",
value="1024"
)
self.SHOW_DOWNLOAD_ERRORS_THRESHOLD = FloatAttribute(
name="show_download_errors_threshold",
description="If the percentage of failed downloads goes over this threshold,\n"
"all the error messages are shown.",
value="0.3"
)
self.attribute_list = [
self.USE_TOR,
self.CHUNK_SIZE,
self.SHOW_DOWNLOAD_ERRORS_THRESHOLD
]
super().__init__()
CONNECTION_SECTION = ConnectionSection()