From cae25fb05369661e0db1981453b317fad120d89d Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Tue, 18 Apr 2023 08:30:56 +0200 Subject: [PATCH 1/3] fixed stupid crash --- src/music_kraken/utils/path_manager/locations.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/music_kraken/utils/path_manager/locations.py b/src/music_kraken/utils/path_manager/locations.py index 54e982d..7c5a798 100644 --- a/src/music_kraken/utils/path_manager/locations.py +++ b/src/music_kraken/utils/path_manager/locations.py @@ -10,12 +10,12 @@ from .config_directory import get_config_directory class Locations: def __init__(self, application_name: os.PathLike = "music-kraken"): self.TEMP_DIRECTORY = Path(tempfile.gettempdir(), application_name) - self.TEMP_DIRECTORY.mkdir(exist_ok=True) + self.TEMP_DIRECTORY.mkdirs(exist_ok=True) self.MUSIC_DIRECTORY = get_music_directory() self.CONFIG_DIRECTORY = get_config_directory(str(application_name)) - self.CONFIG_DIRECTORY.mkdir(exist_ok=True) + self.CONFIG_DIRECTORY.mkdirs(exist_ok=True) self.CONFIG_FILE = Path(self.CONFIG_DIRECTORY, f"{application_name}.conf") def get_log_file(self, file_name: os.PathLike) -> Path: From 1eb2301a23a83a94bb41699e8a3b4cb6bd559d87 Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Tue, 18 Apr 2023 09:02:03 +0200 Subject: [PATCH 2/3] fixed dumb fuck up --- src/music_kraken/__init__.py | 3 ++- src/music_kraken/__main__.py | 12 ++++++++++++ src/music_kraken/utils/path_manager/locations.py | 4 ++-- src/music_kraken/utils/shared.py | 3 +++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/music_kraken/__init__.py b/src/music_kraken/__init__.py index a65156c..b549f8c 100644 --- a/src/music_kraken/__init__.py +++ b/src/music_kraken/__init__.py @@ -7,11 +7,12 @@ import gc import musicbrainzngs from . import objects, pages -from .utils import exception, shared +from .utils import exception, shared, path_manager from .utils.config import config, read, write, PATHS_SECTION from .utils.shared import MUSIC_DIR, MODIFY_GC, NOT_A_GENRE_REGEX, get_random_message from .utils.string_processing import fit_to_file_system + if MODIFY_GC: """ At the start I modify the garbage collector to run a bit fewer times. diff --git a/src/music_kraken/__main__.py b/src/music_kraken/__main__.py index 29d0d2f..6ba0cff 100644 --- a/src/music_kraken/__main__.py +++ b/src/music_kraken/__main__.py @@ -59,6 +59,12 @@ if __name__ == "__main__": help="Prints an overview over all music-kraken paths.", action="store_true" ) + + parser.add_argument( + "-r", + help="Resets the config file to the default one.", + action="store_true" + ) arguments = parser.parse_args() @@ -83,6 +89,12 @@ if __name__ == "__main__": music_kraken.paths() exit() + if arguments.r: + import os + if os.path.exists(music_kraken.shared.CONFIG_FILE): + os.remove(music_kraken.shared.CONFIG_FILE) + music_kraken.read() + # getting the genre genre: str = arguments.genre if arguments.test: diff --git a/src/music_kraken/utils/path_manager/locations.py b/src/music_kraken/utils/path_manager/locations.py index 7c5a798..9c4880b 100644 --- a/src/music_kraken/utils/path_manager/locations.py +++ b/src/music_kraken/utils/path_manager/locations.py @@ -10,12 +10,12 @@ from .config_directory import get_config_directory class Locations: def __init__(self, application_name: os.PathLike = "music-kraken"): self.TEMP_DIRECTORY = Path(tempfile.gettempdir(), application_name) - self.TEMP_DIRECTORY.mkdirs(exist_ok=True) + self.TEMP_DIRECTORY.mkdir(exist_ok=True, parents=True) self.MUSIC_DIRECTORY = get_music_directory() self.CONFIG_DIRECTORY = get_config_directory(str(application_name)) - self.CONFIG_DIRECTORY.mkdirs(exist_ok=True) + self.CONFIG_DIRECTORY.mkdir(exist_ok=True, parents=True) self.CONFIG_FILE = Path(self.CONFIG_DIRECTORY, f"{application_name}.conf") def get_log_file(self, file_name: os.PathLike) -> Path: diff --git a/src/music_kraken/utils/shared.py b/src/music_kraken/utils/shared.py index 9e4a6ef..0dffa5d 100644 --- a/src/music_kraken/utils/shared.py +++ b/src/music_kraken/utils/shared.py @@ -6,6 +6,9 @@ from typing import List, Tuple from .path_manager import LOCATIONS from .config import LOGGING_SECTION, AUDIO_SECTION, CONNECTION_SECTION, MISC_SECTION, PATHS_SECTION + +CONFIG_FILE = LOCATIONS.CONFIG_FILE + # 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://web.archive.org/web/20221124122222/https://mkennedy.codes/posts/python-gc-settings-change-this-and-make-your-app-go-20pc-faster/ From 66fb904f95664d452642e148f4d31f37243ea1ca Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Tue, 18 Apr 2023 09:13:04 +0200 Subject: [PATCH 3/3] probably fixed encoding error on windows --- src/music_kraken/utils/config/config.py | 6 ++++-- src/music_kraken/utils/path_manager/locations.py | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/music_kraken/utils/config/config.py b/src/music_kraken/utils/config/config.py index e207479..f4e7282 100644 --- a/src/music_kraken/utils/config/config.py +++ b/src/music_kraken/utils/config/config.py @@ -1,4 +1,5 @@ from typing import Union, Tuple, Dict, Iterable, List +from datetime import datetime import logging import os @@ -21,6 +22,7 @@ class Config: Description("IMPORTANT: If you modify this file, the changes for the actual setting, will be kept as is.\n" "The changes you make to the comments, will be discarded, next time you run music-kraken. " "Have fun!"), + Description(f"Latest reset: {datetime.now()}"), Description("Those are all Settings for the audio codec.\n" "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. :)"), @@ -105,7 +107,7 @@ class Config: self.set_name_to_value(name, value) def read_from_config_file(self, path: os.PathLike): - with open(path, "r") as conf_file: + with open(path, "r", encoding=LOCATIONS.FILE_ENCODING) as conf_file: for section in self._section_list: section.reset_list_attribute() @@ -113,7 +115,7 @@ class Config: self._parse_conf_line(line, i+1) def write_to_config_file(self, path: os.PathLike): - with open(path, "w") as conf_file: + with open(path, "w", encoding=LOCATIONS.FILE_ENCODING) as conf_file: conf_file.write(self.config_string) def __iter__(self) -> Iterable[Attribute]: diff --git a/src/music_kraken/utils/path_manager/locations.py b/src/music_kraken/utils/path_manager/locations.py index 9c4880b..7f7c754 100644 --- a/src/music_kraken/utils/path_manager/locations.py +++ b/src/music_kraken/utils/path_manager/locations.py @@ -9,6 +9,8 @@ from .config_directory import get_config_directory class Locations: def __init__(self, application_name: os.PathLike = "music-kraken"): + self.FILE_ENCODING: str = "utf-8" + self.TEMP_DIRECTORY = Path(tempfile.gettempdir(), application_name) self.TEMP_DIRECTORY.mkdir(exist_ok=True, parents=True)