diff --git a/src/music_kraken/utils/config/__init__.py b/src/music_kraken/utils/config/__init__.py index 59f8f5c..0313788 100644 --- a/src/music_kraken/utils/config/__init__.py +++ b/src/music_kraken/utils/config/__init__.py @@ -2,6 +2,7 @@ from .logging import LOGGING_SECTION from .audio import AUDIO_SECTION from .connection import CONNECTION_SECTION from .misc import MISC_SECTION +from .paths import PATHS_SECTION from .config import read, write, config diff --git a/src/music_kraken/utils/config/config.py b/src/music_kraken/utils/config/config.py index bd53c8e..e207479 100644 --- a/src/music_kraken/utils/config/config.py +++ b/src/music_kraken/utils/config/config.py @@ -9,6 +9,7 @@ from .audio import AUDIO_SECTION from .logging import LOGGING_SECTION from .connection import CONNECTION_SECTION from .misc import MISC_SECTION +from .paths import PATHS_SECTION LOGGER = logging.getLogger("config") @@ -26,6 +27,8 @@ class Config: AUDIO_SECTION, Description("Modify how Music-Kraken connects to the internet:"), CONNECTION_SECTION, + Description("Modify all your paths, except your config file..."), + PATHS_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^"), diff --git a/src/music_kraken/utils/config/paths.py b/src/music_kraken/utils/config/paths.py new file mode 100644 index 0000000..32e781c --- /dev/null +++ b/src/music_kraken/utils/config/paths.py @@ -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() diff --git a/src/music_kraken/utils/shared.py b/src/music_kraken/utils/shared.py index ce4b929..0ea757d 100644 --- a/src/music_kraken/utils/shared.py +++ b/src/music_kraken/utils/shared.py @@ -4,7 +4,7 @@ from pathlib import Path from typing import List, Tuple 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 # 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) -TEMP_DIR = LOCATIONS.TEMP_DIRECTORY -LOG_PATH = LOCATIONS.get_log_file("download_logs.log") -MUSIC_DIR: Path = LOCATIONS.MUSIC_DIRECTORY +TEMP_DIR = PATHS_SECTION.TEMP_DIRECTORY.object_from_value +LOG_PATH = PATHS_SECTION.LOG_PATH.object_from_value +MUSIC_DIR: Path = PATHS_SECTION.MUSIC_DIRECTORY.object_from_value -NOT_A_GENRE_REGEX: Tuple[str] = ( - r'^\.', # is hidden/starts with a "." -) +NOT_A_GENRE_REGEX: Tuple[str] = PATHS_SECTION.NOT_A_GENRE_REGEX.object_from_value # configure logger default logging.basicConfig(