Skip to content

Commit

Permalink
get_sources_metadata_images(): move at module level as it doesn't dep…
Browse files Browse the repository at this point in the history
…end on ImageListState
  • Loading branch information
zas committed May 23, 2024
1 parent 2c61644 commit d3fc321
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
12 changes: 7 additions & 5 deletions picard/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,12 @@ def remove_metadata_images(self, removed_sources):
Args:
removed_sources: List of child objects (`Track` or `File`) which's metadata images should be removed from
"""
from picard.util.imagelist import get_sources_metadata_images

state = self._get_imagelist_state()

removed_new_images = state.get_sources_metadata_images(s.metadata for s in removed_sources)
removed_orig_images = state.get_sources_metadata_images(s.orig_metadata for s in removed_sources)
removed_new_images = get_sources_metadata_images(s.metadata for s in removed_sources)
removed_orig_images = get_sources_metadata_images(s.orig_metadata for s in removed_sources)

if self.update_new_metadata:
sources = [s.metadata for s in state.sources]
Expand All @@ -229,10 +231,10 @@ def add_metadata_images(self, added_sources):
Args:
added_sources: List of child objects (`Track` or `File`) which's metadata images should be added to current object
"""
state = self._get_imagelist_state()
from picard.util.imagelist import get_sources_metadata_images

added_new_images = state.get_sources_metadata_images(s.metadata for s in added_sources)
added_orig_images = state.get_sources_metadata_images(s.orig_metadata for s in added_sources)
added_new_images = get_sources_metadata_images(s.metadata for s in added_sources)
added_orig_images = get_sources_metadata_images(s.orig_metadata for s in added_sources)

changed = False

Expand Down
13 changes: 7 additions & 6 deletions picard/util/imagelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ def hash_dict(self):
return self._hash_dict


def get_sources_metadata_images(sources_metadata):
images = set()
for s in sources_metadata:
images = images.union(s.images)
return images


class ImageListState:
def __init__(self, update_new_metadata=False, update_orig_metadata=False):
self.new_images = {}
Expand All @@ -115,12 +122,6 @@ def __init__(self, update_new_metadata=False, update_orig_metadata=False):
self.update_new_metadata = update_new_metadata
self.update_orig_metadata = update_orig_metadata

def get_sources_metadata_images(self, sources_metadata):
images = set()
for s in sources_metadata:
images = images.union(s.images)
return images

def process_images(self, src_obj, Track):
# Check new images
if self.update_new_metadata:
Expand Down

0 comments on commit d3fc321

Please sign in to comment.