put settings in dict
This commit is contained in:
@@ -7,19 +7,7 @@ from .sections.paths import PATHS_SECTION
|
||||
from .sections.paths import LOCATIONS
|
||||
from .config import Config
|
||||
|
||||
|
||||
config = Config()
|
||||
from .settings import read_config, write_config, load, set_name_to_value
|
||||
|
||||
|
||||
def read_config():
|
||||
if not LOCATIONS.CONFIG_FILE.is_file():
|
||||
write_config()
|
||||
config.read_from_config_file(LOCATIONS.CONFIG_FILE)
|
||||
|
||||
|
||||
def write_config():
|
||||
config.write_to_config_file(LOCATIONS.CONFIG_FILE)
|
||||
|
||||
set_name_to_value = config.set_name_to_value
|
||||
|
||||
read_config()
|
||||
load()
|
||||
|
@@ -42,7 +42,7 @@ class Config:
|
||||
|
||||
self._length = 0
|
||||
self._section_list: List[Section] = []
|
||||
self._name_section_map: Dict[str, Section] = dict()
|
||||
self.name_section_map: Dict[str, Section] = dict()
|
||||
|
||||
for element in self.config_elements:
|
||||
if not isinstance(element, Section):
|
||||
@@ -50,12 +50,12 @@ class Config:
|
||||
|
||||
self._section_list.append(element)
|
||||
for name in element.name_attribute_map:
|
||||
if name in self._name_section_map:
|
||||
if name in self.name_section_map:
|
||||
raise ValueError(f"Two sections have the same name: "
|
||||
f"{name}: "
|
||||
f"{element.__class__.__name__} {self._name_section_map[name].__class__.__name__}")
|
||||
f"{element.__class__.__name__} {self.name_section_map[name].__class__.__name__}")
|
||||
|
||||
self._name_section_map[name] = element
|
||||
self.name_section_map[name] = element
|
||||
self._length += 1
|
||||
|
||||
def set_name_to_value(self, name: str, value: str, silent: bool = True):
|
||||
@@ -65,7 +65,7 @@ class Config:
|
||||
:param value:
|
||||
:return:
|
||||
"""
|
||||
if name not in self._name_section_map:
|
||||
if name not in self.name_section_map:
|
||||
if silent:
|
||||
LOGGER.warning(f"The setting \"{name}\" is either deprecated, or doesn't exist.")
|
||||
return
|
||||
@@ -73,7 +73,7 @@ class Config:
|
||||
|
||||
LOGGER.debug(f"setting: {name} value: {value}")
|
||||
|
||||
self._name_section_map[name].modify_setting(setting_name=name, new_value=value)
|
||||
self.name_section_map[name].modify_setting(setting_name=name, new_value=value)
|
||||
|
||||
def __len__(self):
|
||||
return self._length
|
||||
|
95
src/music_kraken/utils/config/settings.py
Normal file
95
src/music_kraken/utils/config/settings.py
Normal file
@@ -0,0 +1,95 @@
|
||||
from typing import TypedDict, List
|
||||
|
||||
from urllib.parse import ParseResult
|
||||
from logging import Logger
|
||||
from pathlib import Path
|
||||
|
||||
from .sections.paths import LOCATIONS
|
||||
from .config import Config
|
||||
from .base_classes import Section, Attribute
|
||||
|
||||
|
||||
class SettingsStructure(TypedDict):
|
||||
hasnt_yet_started: bool
|
||||
result_history: bool
|
||||
history_length: int
|
||||
happy_messages: List[str]
|
||||
modify_gc: bool
|
||||
id_bits: int
|
||||
|
||||
# audio
|
||||
bitrate: int
|
||||
audio_format: str
|
||||
sort_by_date: bool
|
||||
sort_album_by_type: bool
|
||||
download_path: str
|
||||
download_file: str
|
||||
album_type_blacklist: List[str]
|
||||
|
||||
# connection
|
||||
proxies: List[str]
|
||||
tor: bool
|
||||
tor_port: int
|
||||
chunk_size: int
|
||||
show_download_errors_threshold: float
|
||||
|
||||
# youtube
|
||||
invidious_instance: ParseResult
|
||||
piped_instance: ParseResult
|
||||
sleep_after_youtube_403: float
|
||||
youtube_music_api_key: str
|
||||
youtube_music_clean_data: bool
|
||||
youtube_url: List[ParseResult]
|
||||
use_sponsor_block: bool
|
||||
|
||||
# logging
|
||||
logging_format: str
|
||||
log_level: int
|
||||
download_logger: Logger
|
||||
tagging_logger: Logger
|
||||
codex_logger: Logger
|
||||
object_logger: Logger
|
||||
database_logger: Logger
|
||||
musify_logger: Logger
|
||||
youtube_logger: Logger
|
||||
youtube_music_logger: Logger
|
||||
metal_archives_logger: Logger
|
||||
genius_logger: Logger
|
||||
|
||||
# paths
|
||||
music_directory: Path
|
||||
temp_directory: Path
|
||||
log_file: Path
|
||||
not_a_genre_regex: List[str]
|
||||
ffmpeg_binary: Path
|
||||
|
||||
|
||||
settings: SettingsStructure = {}
|
||||
|
||||
|
||||
config = Config()
|
||||
set_name_to_value = config.set_name_to_value
|
||||
|
||||
|
||||
def read_config():
|
||||
if not LOCATIONS.CONFIG_FILE.is_file():
|
||||
write_config()
|
||||
config.read_from_config_file(LOCATIONS.CONFIG_FILE)
|
||||
|
||||
|
||||
def write_config():
|
||||
config.write_to_config_file(LOCATIONS.CONFIG_FILE)
|
||||
|
||||
|
||||
def load():
|
||||
read_config()
|
||||
|
||||
for section in config.config_elements:
|
||||
if not isinstance(section, Section):
|
||||
continue
|
||||
|
||||
for attribute in section.attribute_list:
|
||||
if not isinstance(attribute, Attribute):
|
||||
continue
|
||||
|
||||
settings[attribute.name] = attribute.object_from_value
|
Reference in New Issue
Block a user