implemented misc settings
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
from .logging import LOGGING_SECTION
|
||||
from .audio import AUDIO_SECTION
|
||||
from .connection import CONNECTION_SECTION
|
||||
from .misc import MISC_SECTION
|
||||
|
||||
from .config import read, write, config
|
||||
|
||||
|
||||
read()
|
||||
|
@@ -4,6 +4,9 @@ from typing import Optional, List, Union, Dict
|
||||
|
||||
from ..exception.config import SettingNotFound, SettingValueError
|
||||
|
||||
|
||||
LOGGER = logging.getLogger("config")
|
||||
|
||||
COMMENT_PREFIX = "#"
|
||||
|
||||
|
||||
@@ -83,7 +86,7 @@ class IntAttribute(SingleAttribute):
|
||||
|
||||
@property
|
||||
def object_from_value(self) -> int:
|
||||
if not self.value.isdigit():
|
||||
if self.value.isdigit():
|
||||
return int(self.value)
|
||||
|
||||
|
||||
@@ -123,6 +126,9 @@ class ListAttribute(Attribute):
|
||||
|
||||
has_default_values: bool = True
|
||||
|
||||
def __len__(self):
|
||||
return len(self.value)
|
||||
|
||||
def set_value(self, value: str):
|
||||
"""
|
||||
Due to lists being represented as multiple lines with the same key,
|
||||
@@ -137,6 +143,7 @@ class ListAttribute(Attribute):
|
||||
# resetting the list to an empty list, if this is the first config line to load
|
||||
if self.has_default_values:
|
||||
self.value = []
|
||||
self.has_default_values = False
|
||||
|
||||
self.value.append(value)
|
||||
|
||||
@@ -150,8 +157,8 @@ class ListAttribute(Attribute):
|
||||
@property
|
||||
def object_from_value(self) -> list:
|
||||
"""
|
||||
THIS IS NOT THE PROPERTY TO OVERRIDE WHEN INHERETING ListAttribute
|
||||
|
||||
THIS IS NOT THE PROPERTY TO OVERRIDE WHEN INHERITING ListAttribute
|
||||
single_object_from_element
|
||||
:return:
|
||||
"""
|
||||
|
||||
@@ -216,3 +223,10 @@ class Section:
|
||||
)
|
||||
|
||||
self.name_attribute_map[setting_name].set_value(new_value)
|
||||
|
||||
def reset_list_attribute(self):
|
||||
for attribute in self.attribute_list:
|
||||
if not isinstance(attribute, ListAttribute):
|
||||
continue
|
||||
|
||||
attribute.has_default_values = True
|
||||
|
@@ -8,6 +8,10 @@ from .base_classes import Description, Attribute, Section, EmptyLine, COMMENT_PR
|
||||
from .audio import AUDIO_SECTION
|
||||
from .logging import LOGGING_SECTION
|
||||
from .connection import CONNECTION_SECTION
|
||||
from .misc import MISC_SECTION
|
||||
|
||||
|
||||
LOGGER = logging.getLogger("config")
|
||||
|
||||
|
||||
class Config:
|
||||
@@ -26,6 +30,8 @@ class Config:
|
||||
"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^"),
|
||||
LOGGING_SECTION,
|
||||
Description("If there are stupid settings, they are here."),
|
||||
MISC_SECTION,
|
||||
Description("🏳️⚧️🏳️⚧️ Protect trans youth. 🏳️⚧️🏳️⚧️\n"),
|
||||
)
|
||||
|
||||
@@ -57,6 +63,8 @@ class Config:
|
||||
if name not in self._name_section_map:
|
||||
raise SettingNotFound(setting_name=name)
|
||||
|
||||
print(f"setting: {name} value: {value}")
|
||||
|
||||
self._name_section_map[name].modify_setting(setting_name=name, new_value=value)
|
||||
|
||||
def __len__(self):
|
||||
@@ -81,6 +89,10 @@ class Config:
|
||||
return
|
||||
|
||||
if "=" not in line:
|
||||
"""
|
||||
TODO
|
||||
No value error but custom conf error
|
||||
"""
|
||||
raise ValueError(f"Couldn't find the '=' in line {index}.")
|
||||
|
||||
line_segments = line.split("=")
|
||||
@@ -91,6 +103,9 @@ class Config:
|
||||
|
||||
def read_from_config_file(self, path: os.PathLike):
|
||||
with open(path, "r") as conf_file:
|
||||
for section in self._section_list:
|
||||
section.reset_list_attribute()
|
||||
|
||||
for i, line in enumerate(conf_file):
|
||||
self._parse_conf_line(line, i+1)
|
||||
|
||||
|
@@ -1,16 +1,36 @@
|
||||
import logging
|
||||
from typing import Callable
|
||||
from .base_classes import Section, FloatAttribute, IntAttribute, BoolAttribute, ListAttribute
|
||||
|
||||
from .base_classes import SingleAttribute, StringAttribute, Section, FloatAttribute, Description, IntAttribute, EmptyLine, BoolAttribute
|
||||
|
||||
class ProxAttribute(ListAttribute):
|
||||
def single_object_from_element(self, value) -> dict:
|
||||
return {
|
||||
'http': value,
|
||||
'https': value,
|
||||
'ftp': value
|
||||
}
|
||||
|
||||
|
||||
class ConnectionSection(Section):
|
||||
def __init__(self):
|
||||
self.PROXIES = ProxAttribute(
|
||||
name="proxies",
|
||||
description="Set your proxies.\n"
|
||||
"Must be valid for http, as well as https.",
|
||||
value=[]
|
||||
)
|
||||
|
||||
self.USE_TOR = BoolAttribute(
|
||||
name="tor",
|
||||
description="Route ALL traffic through Tor.\nNo guarantee though!",
|
||||
description="Route ALL traffic through Tor.\n"
|
||||
"If you use Tor, make sure the Tor browser is installed, and running."
|
||||
"I can't guarantee maximum security though!",
|
||||
value="false"
|
||||
)
|
||||
self.TOR_PORT = IntAttribute(
|
||||
name="tor_port",
|
||||
description="The port, tor is listening. If tor is already working, don't change it.",
|
||||
value="9150"
|
||||
)
|
||||
self.CHUNK_SIZE = IntAttribute(
|
||||
name="chunk_size",
|
||||
description="Size of the chunks that are streamed.",
|
||||
@@ -25,6 +45,7 @@ class ConnectionSection(Section):
|
||||
|
||||
self.attribute_list = [
|
||||
self.USE_TOR,
|
||||
self.TOR_PORT,
|
||||
self.CHUNK_SIZE,
|
||||
self.SHOW_DOWNLOAD_ERRORS_THRESHOLD
|
||||
]
|
||||
|
@@ -0,0 +1,48 @@
|
||||
from .base_classes import Section, IntAttribute, ListAttribute, BoolAttribute
|
||||
|
||||
|
||||
class MiscSection(Section):
|
||||
def __init__(self):
|
||||
self.HAPPY_MESSAGES = ListAttribute(
|
||||
name="happy_messages",
|
||||
description="Just some nice and wholesome messages.\n"
|
||||
"If your mindset has traits of a [file corruption], you might not agree.\n"
|
||||
"But anyways... Freedom of thought, so go ahead and change the messages.",
|
||||
value=[
|
||||
"Support the artist.",
|
||||
"Star Me: https://github.com/HeIIow2/music-downloader",
|
||||
"🏳️⚧️🏳️⚧️ Trans rights are human rights. 🏳️⚧️🏳️⚧️",
|
||||
"🏳️⚧️🏳️⚧️ Trans women are women, trans men are men. 🏳️⚧️🏳️⚧️",
|
||||
"🏴☠️🏴☠️ Unite under one flag, fuck borders. 🏴☠️🏴☠️",
|
||||
"Join my Matrix Space: https://matrix.to/#/#music-kraken:matrix.org",
|
||||
"Gotta love the BPJM!! >:(",
|
||||
"🏳️⚧️🏳️⚧️ Protect trans youth. 🏳️⚧️🏳️⚧️"
|
||||
]
|
||||
)
|
||||
|
||||
self.MODIFY_GC = BoolAttribute(
|
||||
name="modify_gc",
|
||||
description="If set to true, it will modify the gc for the sake of performance.\n"
|
||||
"This should not drive up ram usage, but if it is, then turn it of.\n"
|
||||
"Here a blog post about that matter:\n"
|
||||
"https://mkennedy.codes/posts/python-gc-settings-change-this-and-make-your-app-go-20pc-faster/\n"
|
||||
"https://web.archive.org/web/20221124122222/https://mkennedy.codes/posts/python-gc-settings-change-this-and-make-your-app-go-20pc-faster/",
|
||||
value="true"
|
||||
)
|
||||
|
||||
self.ID_BITS = IntAttribute(
|
||||
name="id_bits",
|
||||
description="I really dunno why I even made this a setting.. Modifying this is a REALLY dumb idea.",
|
||||
value="64"
|
||||
)
|
||||
|
||||
self.attribute_list = [
|
||||
self.HAPPY_MESSAGES,
|
||||
self.MODIFY_GC,
|
||||
self.ID_BITS
|
||||
]
|
||||
|
||||
super().__init__()
|
||||
|
||||
|
||||
MISC_SECTION = MiscSection()
|
||||
|
Reference in New Issue
Block a user