probably fixed encoding error on windows

This commit is contained in:
Hellow2 2023-04-18 09:13:04 +02:00
parent 1eb2301a23
commit 66fb904f95
2 changed files with 6 additions and 2 deletions

View File

@ -1,4 +1,5 @@
from typing import Union, Tuple, Dict, Iterable, List from typing import Union, Tuple, Dict, Iterable, List
from datetime import datetime
import logging import logging
import os 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" 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. " "The changes you make to the comments, will be discarded, next time you run music-kraken. "
"Have fun!"), "Have fun!"),
Description(f"Latest reset: {datetime.now()}"),
Description("Those are all Settings for the audio codec.\n" 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" "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. :)"), "feel free to tinker with the Bitrate or smth. :)"),
@ -105,7 +107,7 @@ class Config:
self.set_name_to_value(name, value) self.set_name_to_value(name, value)
def read_from_config_file(self, path: os.PathLike): 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: for section in self._section_list:
section.reset_list_attribute() section.reset_list_attribute()
@ -113,7 +115,7 @@ class Config:
self._parse_conf_line(line, i+1) self._parse_conf_line(line, i+1)
def write_to_config_file(self, path: os.PathLike): 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) conf_file.write(self.config_string)
def __iter__(self) -> Iterable[Attribute]: def __iter__(self) -> Iterable[Attribute]:

View File

@ -9,6 +9,8 @@ from .config_directory import get_config_directory
class Locations: class Locations:
def __init__(self, application_name: os.PathLike = "music-kraken"): 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 = Path(tempfile.gettempdir(), application_name)
self.TEMP_DIRECTORY.mkdir(exist_ok=True, parents=True) self.TEMP_DIRECTORY.mkdir(exist_ok=True, parents=True)