added config for paths
This commit is contained in:
parent
4f964fd5ba
commit
27d23180b9
@ -2,6 +2,7 @@ from .logging import LOGGING_SECTION
|
|||||||
from .audio import AUDIO_SECTION
|
from .audio import AUDIO_SECTION
|
||||||
from .connection import CONNECTION_SECTION
|
from .connection import CONNECTION_SECTION
|
||||||
from .misc import MISC_SECTION
|
from .misc import MISC_SECTION
|
||||||
|
from .paths import PATHS_SECTION
|
||||||
|
|
||||||
from .config import read, write, config
|
from .config import read, write, config
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ from .audio import AUDIO_SECTION
|
|||||||
from .logging import LOGGING_SECTION
|
from .logging import LOGGING_SECTION
|
||||||
from .connection import CONNECTION_SECTION
|
from .connection import CONNECTION_SECTION
|
||||||
from .misc import MISC_SECTION
|
from .misc import MISC_SECTION
|
||||||
|
from .paths import PATHS_SECTION
|
||||||
|
|
||||||
|
|
||||||
LOGGER = logging.getLogger("config")
|
LOGGER = logging.getLogger("config")
|
||||||
@ -26,6 +27,8 @@ class Config:
|
|||||||
AUDIO_SECTION,
|
AUDIO_SECTION,
|
||||||
Description("Modify how Music-Kraken connects to the internet:"),
|
Description("Modify how Music-Kraken connects to the internet:"),
|
||||||
CONNECTION_SECTION,
|
CONNECTION_SECTION,
|
||||||
|
Description("Modify all your paths, except your config file..."),
|
||||||
|
PATHS_SECTION,
|
||||||
Description("For all your Logging needs.\n"
|
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"
|
"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^"),
|
"reproduce the bug, and attach the logfile in the bugreport. ^w^"),
|
||||||
|
52
src/music_kraken/utils/config/paths.py
Normal file
52
src/music_kraken/utils/config/paths.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from ..path_manager import LOCATIONS
|
||||||
|
from .base_classes import Section, StringAttribute, ListAttribute
|
||||||
|
|
||||||
|
|
||||||
|
class PathAttribute(StringAttribute):
|
||||||
|
@property
|
||||||
|
def object_from_value(self) -> Path:
|
||||||
|
return Path(self.value.strip())
|
||||||
|
|
||||||
|
|
||||||
|
class PathsSection(Section):
|
||||||
|
def __init__(self):
|
||||||
|
self.MUSIC_DIRECTORY = PathAttribute(
|
||||||
|
name="music_directory",
|
||||||
|
description="The directory, all the music will be downloaded to.",
|
||||||
|
value=str(LOCATIONS.MUSIC_DIRECTORY)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.TEMP_DIRECTORY = PathAttribute(
|
||||||
|
name="temp_directory",
|
||||||
|
description="All temporary stuff is gonna be dumped in this directory.",
|
||||||
|
value=str(LOCATIONS.TEMP_DIRECTORY)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.LOG_PATH = PathAttribute(
|
||||||
|
name="log_file",
|
||||||
|
description="The path to the logging file",
|
||||||
|
value=str(LOCATIONS.get_log_file("download_logs.log"))
|
||||||
|
)
|
||||||
|
|
||||||
|
self.NOT_A_GENRE_REGEX = ListAttribute(
|
||||||
|
name="not_a_genre_regex",
|
||||||
|
description="These regular expressions tell music-kraken, which sub-folders of the music-directory\n"
|
||||||
|
"it should ignore, and not count to genres",
|
||||||
|
value=[
|
||||||
|
r'^\.' # is hidden/starts with a "."
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
self.attribute_list = [
|
||||||
|
self.MUSIC_DIRECTORY,
|
||||||
|
self.TEMP_DIRECTORY,
|
||||||
|
self.LOG_PATH,
|
||||||
|
self.NOT_A_GENRE_REGEX
|
||||||
|
]
|
||||||
|
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
|
||||||
|
PATHS_SECTION = PathsSection()
|
@ -4,7 +4,7 @@ from pathlib import Path
|
|||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
from .path_manager import LOCATIONS
|
from .path_manager import LOCATIONS
|
||||||
from .config import LOGGING_SECTION, AUDIO_SECTION, CONNECTION_SECTION, MISC_SECTION
|
from .config import LOGGING_SECTION, AUDIO_SECTION, CONNECTION_SECTION, MISC_SECTION, PATHS_SECTION
|
||||||
|
|
||||||
# modifies the garbage collector to speed up the program
|
# modifies the garbage collector to speed up the program
|
||||||
# https://mkennedy.codes/posts/python-gc-settings-change-this-and-make-your-app-go-20pc-faster/
|
# https://mkennedy.codes/posts/python-gc-settings-change-this-and-make-your-app-go-20pc-faster/
|
||||||
@ -29,13 +29,11 @@ def get_random_message() -> str:
|
|||||||
return random.choice(HAPPY_MESSAGES)
|
return random.choice(HAPPY_MESSAGES)
|
||||||
|
|
||||||
|
|
||||||
TEMP_DIR = LOCATIONS.TEMP_DIRECTORY
|
TEMP_DIR = PATHS_SECTION.TEMP_DIRECTORY.object_from_value
|
||||||
LOG_PATH = LOCATIONS.get_log_file("download_logs.log")
|
LOG_PATH = PATHS_SECTION.LOG_PATH.object_from_value
|
||||||
MUSIC_DIR: Path = LOCATIONS.MUSIC_DIRECTORY
|
MUSIC_DIR: Path = PATHS_SECTION.MUSIC_DIRECTORY.object_from_value
|
||||||
|
|
||||||
NOT_A_GENRE_REGEX: Tuple[str] = (
|
NOT_A_GENRE_REGEX: Tuple[str] = PATHS_SECTION.NOT_A_GENRE_REGEX.object_from_value
|
||||||
r'^\.', # is hidden/starts with a "."
|
|
||||||
)
|
|
||||||
|
|
||||||
# configure logger default
|
# configure logger default
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
|
Loading…
Reference in New Issue
Block a user