feat: added id possibility to output
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
8e1dfd0be6
commit
3737e0dc81
@ -7,7 +7,7 @@ logging.getLogger().setLevel(logging.DEBUG)
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
commands = [
|
commands = [
|
||||||
"s: #a Ghost Bath",
|
"s: #a Ghost Bath",
|
||||||
"d: 4",
|
"d: 14",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@ class Collection(Generic[T]):
|
|||||||
|
|
||||||
_data: List[T]
|
_data: List[T]
|
||||||
|
|
||||||
_indexed_values: Dict[str, set]
|
_indexed_from_id: Dict[int, Dict[str, Any]]
|
||||||
_indexed_to_objects: Dict[any, list]
|
_indexed_values: Dict[str, Dict[Any, T]]
|
||||||
|
|
||||||
shallow_list = property(fget=lambda self: self.data)
|
shallow_list = property(fget=lambda self: self.data)
|
||||||
|
|
||||||
@ -74,6 +74,10 @@ class Collection(Generic[T]):
|
|||||||
|
|
||||||
del self._indexed_from_id[obj_id]
|
del self._indexed_from_id[obj_id]
|
||||||
|
|
||||||
|
def _remap(self):
|
||||||
|
for e in self:
|
||||||
|
self._map_element(e)
|
||||||
|
|
||||||
def _find_object(self, __object: T) -> Optional[T]:
|
def _find_object(self, __object: T) -> Optional[T]:
|
||||||
for name, value in __object.indexing_values:
|
for name, value in __object.indexing_values:
|
||||||
if value in self._indexed_values[name]:
|
if value in self._indexed_values[name]:
|
||||||
@ -94,6 +98,7 @@ class Collection(Generic[T]):
|
|||||||
if __object is None:
|
if __object is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self._remap()
|
||||||
existing_object = self._find_object(__object)
|
existing_object = self._find_object(__object)
|
||||||
|
|
||||||
if existing_object is None:
|
if existing_object is None:
|
||||||
@ -112,15 +117,10 @@ class Collection(Generic[T]):
|
|||||||
b = __object.__getattribute__(attribute)
|
b = __object.__getattribute__(attribute)
|
||||||
object_trace(f"Syncing [{a}{id(a)}] = [{b}{id(b)}]")
|
object_trace(f"Syncing [{a}{id(a)}] = [{b}{id(b)}]")
|
||||||
|
|
||||||
data_to_extend = b.data
|
|
||||||
|
|
||||||
a._collection_for.update(b._collection_for)
|
a._collection_for.update(b._collection_for)
|
||||||
for synced_with, key in b._collection_for.items():
|
for synced_with, key in b._collection_for.items():
|
||||||
synced_with.__setattr__(key, a)
|
synced_with.__setattr__(key, a)
|
||||||
|
|
||||||
a.extend(data_to_extend)
|
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# merge only if the two objects are not the same
|
# merge only if the two objects are not the same
|
||||||
if existing_object.id == __object.id:
|
if existing_object.id == __object.id:
|
||||||
|
@ -32,7 +32,6 @@ class InnerData:
|
|||||||
"""
|
"""
|
||||||
Attribute versions keep track, of if the attribute has been changed.
|
Attribute versions keep track, of if the attribute has been changed.
|
||||||
"""
|
"""
|
||||||
_attribute_versions: Dict[str, int] = None
|
|
||||||
|
|
||||||
def __init__(self, object_type, **kwargs):
|
def __init__(self, object_type, **kwargs):
|
||||||
self._refers_to_instances = set()
|
self._refers_to_instances = set()
|
||||||
@ -249,6 +248,8 @@ class OuterProxy:
|
|||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
INDEX_DEPENDS_ON: List[str] = []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def indexing_values(self) -> List[Tuple[str, object]]:
|
def indexing_values(self) -> List[Tuple[str, object]]:
|
||||||
"""
|
"""
|
||||||
|
@ -43,7 +43,8 @@ def get_collection_string(
|
|||||||
template: str,
|
template: str,
|
||||||
ignore_titles: Set[str] = None,
|
ignore_titles: Set[str] = None,
|
||||||
background: BColors = OPTION_BACKGROUND,
|
background: BColors = OPTION_BACKGROUND,
|
||||||
foreground: BColors = OPTION_FOREGROUND
|
foreground: BColors = OPTION_FOREGROUND,
|
||||||
|
add_id: bool = False,
|
||||||
) -> str:
|
) -> str:
|
||||||
if collection.empty:
|
if collection.empty:
|
||||||
return ""
|
return ""
|
||||||
@ -55,8 +56,15 @@ def get_collection_string(
|
|||||||
|
|
||||||
r = background
|
r = background
|
||||||
|
|
||||||
|
def get_element_str(element) -> str:
|
||||||
|
nonlocal add_id
|
||||||
|
r = element.title_string.strip()
|
||||||
|
if add_id:
|
||||||
|
r += " " + str(element.id)
|
||||||
|
return r
|
||||||
|
|
||||||
element: Base
|
element: Base
|
||||||
titel_list: List[str] = [element.title_string.strip() for element in collection if element.title_string not in ignore_titles]
|
titel_list: List[str] = [get_element_str(element) for element in collection if element.title_string not in ignore_titles]
|
||||||
|
|
||||||
for i, titel in enumerate(titel_list):
|
for i, titel in enumerate(titel_list):
|
||||||
delimiter = ", "
|
delimiter = ", "
|
||||||
@ -151,13 +159,14 @@ class Song(Base):
|
|||||||
self.album_collection.extend(object_list)
|
self.album_collection.extend(object_list)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
INDEX_DEPENDS_ON = ("title", "isrc", "source_collection")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def indexing_values(self) -> List[Tuple[str, object]]:
|
def indexing_values(self) -> List[Tuple[str, object]]:
|
||||||
return [
|
return [
|
||||||
('id', self.id),
|
|
||||||
('title', unify(self.title)),
|
('title', unify(self.title)),
|
||||||
('isrc', self.isrc),
|
('isrc', self.isrc),
|
||||||
*[('url', source.url) for source in self.source_collection]
|
*self.source_collection.indexing_values(),
|
||||||
]
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -304,13 +313,14 @@ class Album(Base):
|
|||||||
self.label_collection.extend(object_list)
|
self.label_collection.extend(object_list)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
INDEX_DEPENDS_ON = ("title", "barcode", "source_collection")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def indexing_values(self) -> List[Tuple[str, object]]:
|
def indexing_values(self) -> List[Tuple[str, object]]:
|
||||||
return [
|
return [
|
||||||
('id', self.id),
|
|
||||||
('title', unify(self.title)),
|
('title', unify(self.title)),
|
||||||
('barcode', self.barcode),
|
('barcode', self.barcode),
|
||||||
*[('url', source.url) for source in self.source_collection]
|
*self.source_collection.indexing_values(),
|
||||||
]
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -545,13 +555,13 @@ class Artist(Base):
|
|||||||
# replace the old collection with the new one
|
# replace the old collection with the new one
|
||||||
self.main_album_collection: Collection = Collection(data=album_list, element_type=Album)
|
self.main_album_collection: Collection = Collection(data=album_list, element_type=Album)
|
||||||
|
|
||||||
|
INDEX_DEPENDS_ON = ("name", "source_collection", "contact_collection")
|
||||||
@property
|
@property
|
||||||
def indexing_values(self) -> List[Tuple[str, object]]:
|
def indexing_values(self) -> List[Tuple[str, object]]:
|
||||||
return [
|
return [
|
||||||
('id', self.id),
|
|
||||||
('name', unify(self.name)),
|
('name', unify(self.name)),
|
||||||
*[('url', source.url) for source in self.source_collection],
|
*[('contact', contact.value) for contact in self.contact_collection],
|
||||||
*[('contact', contact.value) for contact in self.contact_collection]
|
*self.source_collection.indexing_values(),
|
||||||
]
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -168,3 +168,7 @@ class SourceCollection:
|
|||||||
@property
|
@property
|
||||||
def homepage_list(self) -> List[str]:
|
def homepage_list(self) -> List[str]:
|
||||||
return [source.homepage for source in self.source_pages]
|
return [source.homepage for source in self.source_pages]
|
||||||
|
|
||||||
|
def indexing_values(self) -> Generator[Tuple[str, str], None, None]:
|
||||||
|
for index in self._indexed_sources:
|
||||||
|
yield "url", index
|
Loading…
Reference in New Issue
Block a user