From 1ad62df0abad47baf8df2e36892ecbc5ac9b08fa Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Mon, 29 Apr 2024 13:43:34 +0200 Subject: [PATCH] feat: default implementation for options that should be sufficient --- .vscode/settings.json | 1 + music_kraken/objects/parents.py | 23 ++++++++++++++++++----- music_kraken/objects/song.py | 4 ++-- music_kraken/utils/__init__.py | 6 ++++++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 662ba25..fa0b6f7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,6 +16,7 @@ }, "python.formatting.provider": "none", "cSpell.words": [ + "albumsort", "APIC", "Bandcamp", "dotenv", diff --git a/music_kraken/objects/parents.py b/music_kraken/objects/parents.py index 59a3d10..2f04b45 100644 --- a/music_kraken/objects/parents.py +++ b/music_kraken/objects/parents.py @@ -9,7 +9,7 @@ from pathlib import Path import inspect from .metadata import Metadata -from ..utils import get_unix_time, object_trace +from ..utils import get_unix_time, object_trace, generate_id from ..utils.config import logging_settings, main_settings from ..utils.shared import HIGHEST_ID from ..utils.hacking import MetaClass @@ -29,6 +29,10 @@ class InnerData: """ _refers_to_instances: set = None + """ + Attribute versions keep track, of if the attribute has been changed. + """ + _attribute_versions: Dict[str, int] = None def __init__(self, object_type, **kwargs): self._refers_to_instances = set() @@ -84,8 +88,6 @@ class OuterProxy: DOWNWARDS_COLLECTION_STRING_ATTRIBUTES = tuple() UPWARDS_COLLECTION_STRING_ATTRIBUTES = tuple() - TITEL = "id" - def __init__(self, _id: int = None, dynamic: bool = False, **kwargs): _automatic_id: bool = False @@ -94,7 +96,7 @@ class OuterProxy: generates a random integer id the range is defined in the config """ - _id = random.randint(0, HIGHEST_ID) + _id = generate_id() _automatic_id = True kwargs["automatic_id"] = _automatic_id @@ -235,7 +237,17 @@ class OuterProxy: @property def options(self) -> List[P]: - return [self] + r = [] + + for collection_string_attribute in self.UPWARDS_COLLECTION_STRING_ATTRIBUTES: + r.extend(self.__getattribute__(collection_string_attribute)) + + r.append(self) + + for collection_string_attribute in self.DOWNWARDS_COLLECTION_STRING_ATTRIBUTES: + r.extend(self.__getattribute__(collection_string_attribute)) + + return r @property def indexing_values(self) -> List[Tuple[str, object]]: @@ -267,6 +279,7 @@ class OuterProxy: return r + TITEL = "id" @property def title_string(self) -> str: return str(self.__getattribute__(self.TITEL)) diff --git a/music_kraken/objects/song.py b/music_kraken/objects/song.py index be6d751..4b4abce 100644 --- a/music_kraken/objects/song.py +++ b/music_kraken/objects/song.py @@ -117,7 +117,7 @@ class Song(Base): Base.__init__(**locals()) - UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("album_collection", "main_artist_collection", "feature_artist_collection") + UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("main_artist_collection", "feature_artist_collection", "album_collection") TITEL = "title" def __init_collections__(self) -> None: @@ -269,7 +269,7 @@ class Album(Base): **kwargs) DOWNWARDS_COLLECTION_STRING_ATTRIBUTES = ("song_collection",) - UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("artist_collection", "label_collection") + UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("label_collection", "artist_collection") def __init_collections__(self): self.song_collection.append_object_to_attribute = { diff --git a/music_kraken/utils/__init__.py b/music_kraken/utils/__init__.py index 9226441..fcfb9a5 100644 --- a/music_kraken/utils/__init__.py +++ b/music_kraken/utils/__init__.py @@ -71,6 +71,12 @@ def object_trace(obj): misc functions """ +_auto_increment = 0 +def generate_id() -> int: + global _auto_increment + _auto_increment += 1 + return _auto_increment + def get_current_millis() -> int: dt = datetime.now() return int(dt.microsecond / 1_000)