mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
fix: importlib import bugs :sigh!
This commit is contained in:
@@ -2,12 +2,11 @@ import sys
|
|||||||
import pathlib
|
import pathlib
|
||||||
import argparse
|
import argparse
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
from importlib.metadata import version
|
|
||||||
|
|
||||||
from swingmusic import settings
|
from swingmusic import settings
|
||||||
from swingmusic.logger import setup_logger
|
from swingmusic.logger import setup_logger
|
||||||
from swingmusic import tools as swing_tools
|
from swingmusic import tools as swing_tools
|
||||||
from swingmusic.settings import AssetHandler
|
from swingmusic.settings import AssetHandler, Metadata
|
||||||
from swingmusic.start_swingmusic import start_swingmusic
|
from swingmusic.start_swingmusic import start_swingmusic
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
@@ -17,7 +16,7 @@ parser = argparse.ArgumentParser(
|
|||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-v", "--version", action="version", version=f"swingmusic v{version('swingmusic')}"
|
"-v", "--version", action="version", version=f"swingmusic v{Metadata.version}"
|
||||||
)
|
)
|
||||||
parser.add_argument("--host", default="0.0.0.0", help="Host to run the app on.")
|
parser.add_argument("--host", default="0.0.0.0", help="Host to run the app on.")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import importlib.resources
|
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from dataclasses import dataclass, asdict, field, InitVar
|
from dataclasses import dataclass, asdict, field, InitVar
|
||||||
|
from swingmusic.data import ARTIST_SPLIT_IGNORE_LIST
|
||||||
from swingmusic.settings import Paths, Singleton
|
from swingmusic.settings import Paths, Singleton
|
||||||
|
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ def load_artist_ignore_list_from_file(filepath: Path) -> set[str]:
|
|||||||
"""
|
"""
|
||||||
if filepath.exists():
|
if filepath.exists():
|
||||||
text = filepath.read_text()
|
text = filepath.read_text()
|
||||||
return set([ line.strip() for line in text.splitlines() if line.strip() ])
|
return set([line.strip() for line in text.splitlines() if line.strip()])
|
||||||
else:
|
else:
|
||||||
return set()
|
return set()
|
||||||
|
|
||||||
@@ -25,10 +25,7 @@ def load_default_artist_ignore_list() -> set[str]:
|
|||||||
Loads the default artist-ignore-list from the text file.
|
Loads the default artist-ignore-list from the text file.
|
||||||
Returns an empty set if the file doesn't exist.
|
Returns an empty set if the file doesn't exist.
|
||||||
"""
|
"""
|
||||||
text = importlib.resources.read_text("swingmusic.data","artist_split_ignore.txt")
|
return ARTIST_SPLIT_IGNORE_LIST
|
||||||
# only return unique and not empty lines
|
|
||||||
lines = text.splitlines()
|
|
||||||
return set([ line.strip() for line in lines if line.strip() ])
|
|
||||||
|
|
||||||
|
|
||||||
def load_user_artist_ignore_list() -> set[str]:
|
def load_user_artist_ignore_list() -> set[str]:
|
||||||
@@ -39,14 +36,14 @@ def load_user_artist_ignore_list() -> set[str]:
|
|||||||
user_file = Paths().config_dir / "artist_split_ignore.txt"
|
user_file = Paths().config_dir / "artist_split_ignore.txt"
|
||||||
if user_file.exists():
|
if user_file.exists():
|
||||||
lines = user_file.read_text().splitlines()
|
lines = user_file.read_text().splitlines()
|
||||||
return set([ line.strip() for line in lines if line.strip()])
|
return set([line.strip() for line in lines if line.strip()])
|
||||||
else:
|
else:
|
||||||
return set()
|
return set()
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class UserConfig(metaclass=Singleton):
|
class UserConfig(metaclass=Singleton):
|
||||||
_finished: bool = field(default=False, init=False) # if post init succesfully
|
_finished: bool = field(default=False, init=False) # if post init succesfully
|
||||||
_config_path: InitVar[Path] = Path("")
|
_config_path: InitVar[Path] = Path("")
|
||||||
_artist_split_ignore_file_name: InitVar[str] = "artist_split_ignore.txt"
|
_artist_split_ignore_file_name: InitVar[str] = "artist_split_ignore.txt"
|
||||||
# NOTE: only auth stuff are used (the others are still reading/writing to db)
|
# NOTE: only auth stuff are used (the others are still reading/writing to db)
|
||||||
@@ -91,7 +88,6 @@ class UserConfig(metaclass=Singleton):
|
|||||||
lastfmApiSecret: str = "5e5306fbf3e8e3bc92f039b6c6c4bd4e"
|
lastfmApiSecret: str = "5e5306fbf3e8e3bc92f039b6c6c4bd4e"
|
||||||
lastfmSessionKeys: dict[str, str] = field(default_factory=dict)
|
lastfmSessionKeys: dict[str, str] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
def __post_init__(self, _config_path, _artist_split_ignore_file_name):
|
def __post_init__(self, _config_path, _artist_split_ignore_file_name):
|
||||||
"""
|
"""
|
||||||
Loads the config file and sets the values to this instance
|
Loads the config file and sets the values to this instance
|
||||||
@@ -119,7 +115,6 @@ class UserConfig(metaclass=Singleton):
|
|||||||
self._config_path = config_path
|
self._config_path = config_path
|
||||||
self._finished = True
|
self._finished = True
|
||||||
|
|
||||||
|
|
||||||
def setup_config_file(self) -> None:
|
def setup_config_file(self) -> None:
|
||||||
"""
|
"""
|
||||||
Creates the config file with the default settings
|
Creates the config file with the default settings
|
||||||
@@ -130,7 +125,6 @@ class UserConfig(metaclass=Singleton):
|
|||||||
if not config.exists():
|
if not config.exists():
|
||||||
self.write_to_file(asdict(self))
|
self.write_to_file(asdict(self))
|
||||||
|
|
||||||
|
|
||||||
def load_config(self, path: Path) -> dict[str, Any]:
|
def load_config(self, path: Path) -> dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Reads the settings from the config file.
|
Reads the settings from the config file.
|
||||||
@@ -138,7 +132,6 @@ class UserConfig(metaclass=Singleton):
|
|||||||
"""
|
"""
|
||||||
return json.loads(path.read_text())
|
return json.loads(path.read_text())
|
||||||
|
|
||||||
|
|
||||||
def write_to_file(self, settings: dict[str, Any]):
|
def write_to_file(self, settings: dict[str, Any]):
|
||||||
"""
|
"""
|
||||||
Writes the settings to the config file
|
Writes the settings to the config file
|
||||||
@@ -149,7 +142,6 @@ class UserConfig(metaclass=Singleton):
|
|||||||
with self._config_path.open(mode="w") as f:
|
with self._config_path.open(mode="w") as f:
|
||||||
json.dump(settings, f, indent=4, default=list)
|
json.dump(settings, f, indent=4, default=list)
|
||||||
|
|
||||||
|
|
||||||
def __setattr__(self, key: str, value: Any) -> None:
|
def __setattr__(self, key: str, value: Any) -> None:
|
||||||
"""
|
"""
|
||||||
Writes to the config file whenever a value is set
|
Writes to the config file whenever a value is set
|
||||||
@@ -167,4 +159,4 @@ class UserConfig(metaclass=Singleton):
|
|||||||
if key.startswith("_") or not self._config_path:
|
if key.startswith("_") or not self._config_path:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.write_to_file(asdict(self))
|
self.write_to_file(asdict(self))
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
ARTIST_SPLIT_IGNORE_LIST = {
|
||||||
|
"AC/DC",
|
||||||
|
"Bob marley & the wailers",
|
||||||
|
"Crosby, Stills, Nash & Young",
|
||||||
|
"Smith & Thell",
|
||||||
|
"Peter, Paul & Mary",
|
||||||
|
"Simon & Garfunkel",
|
||||||
|
"Judy & Mary",
|
||||||
|
"Florence & The Machine",
|
||||||
|
"Belle & Sebastian",
|
||||||
|
"C&C Music Factory",
|
||||||
|
"C & C Music Factory",
|
||||||
|
"FO&O",
|
||||||
|
"The Product G&B",
|
||||||
|
}
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
AC/DC
|
|
||||||
Bob marley & the wailers
|
|
||||||
Crosby, Stills, Nash & Young
|
|
||||||
Smith & Thell
|
|
||||||
Peter, Paul & Mary
|
|
||||||
Simon & Garfunkel
|
|
||||||
Judy & Mary
|
|
||||||
Florence & The Machine
|
|
||||||
Belle & Sebastian
|
|
||||||
C&C Music Factory
|
|
||||||
C & C Music Factory
|
|
||||||
FO&O
|
|
||||||
The Product G&B
|
|
||||||
@@ -90,7 +90,6 @@ class AssetHandler:
|
|||||||
if (path / "index.html").exists():
|
if (path / "index.html").exists():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
log.error("Client zip could not be found. Please provide a valid path.")
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
with zipfile.ZipFile(client_zip_path, "r") as zip_ref:
|
with zipfile.ZipFile(client_zip_path, "r") as zip_ref:
|
||||||
|
|||||||
Reference in New Issue
Block a user