-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
persist set_fields to media files #3927
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -572,18 +572,24 @@ def remove_duplicates(self, lib): | |
util.prune_dirs(os.path.dirname(item.path), | ||
lib.directory) | ||
|
||
def set_fields(self): | ||
def set_fields(self, lib): | ||
"""Sets the fields given at CLI or configuration to the specified | ||
values. | ||
values, for both the album and all its items. | ||
""" | ||
for field, view in config['import']['set_fields'].items(): | ||
value = view.get() | ||
log.debug(u'Set field {1}={2} for {0}', | ||
displayable_path(self.paths), | ||
field, | ||
value) | ||
self.album[field] = value | ||
self.album.store() | ||
with lib.transaction(): | ||
items = self.imported_items() | ||
for field, view in config['import']['set_fields'].items(): | ||
value = view.get() | ||
log.debug(u'Set field {1}={2} for {0}', | ||
displayable_path(self.paths), | ||
field, | ||
value) | ||
self.album[field] = value | ||
for item in items: | ||
item[field] = value | ||
for item in items: | ||
item.store() | ||
self.album.store() | ||
Comment on lines
+590
to
+592
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be sufficient for the transaction to extend only over these three lines, setting the fields above shouldn't interact with the database. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thx, fixed |
||
|
||
def finalize(self, session): | ||
"""Save progress, clean up files, and emit plugin event. | ||
|
@@ -946,18 +952,19 @@ def choose_match(self, session): | |
def reload(self): | ||
self.item.load() | ||
|
||
def set_fields(self): | ||
def set_fields(self, lib): | ||
"""Sets the fields given at CLI or configuration to the specified | ||
values. | ||
values, for the singleton item. | ||
""" | ||
for field, view in config['import']['set_fields'].items(): | ||
value = view.get() | ||
log.debug(u'Set field {1}={2} for {0}', | ||
displayable_path(self.paths), | ||
field, | ||
value) | ||
self.item[field] = value | ||
self.item.store() | ||
with lib.transaction(): | ||
for field, view in config['import']['set_fields'].items(): | ||
value = view.get() | ||
log.debug(u'Set field {1}={2} for {0}', | ||
displayable_path(self.paths), | ||
field, | ||
value) | ||
self.item[field] = value | ||
self.item.store() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The exact same loop as before, wrapped in a transaction. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It think there's no need for the transaction here, the only interaction with the database here is in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thx. fixed. |
||
|
||
|
||
# FIXME The inheritance relationships are inverted. This is why there | ||
|
@@ -1516,7 +1523,7 @@ def apply_choice(session, task): | |
# because then the ``ImportTask`` won't have an `album` for which | ||
# it can set the fields. | ||
if config['import']['set_fields']: | ||
task.set_fields() | ||
task.set_fields(session.lib) | ||
|
||
|
||
@pipeline.mutator_stage | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -740,10 +740,12 @@ def test_asis_no_data_source(self): | |||||||||||||||||
def test_set_fields(self): | ||||||||||||||||||
genre = u"\U0001F3B7 Jazz" | ||||||||||||||||||
collection = u"To Listen" | ||||||||||||||||||
comments = u"managed by beets" | ||||||||||||||||||
|
||||||||||||||||||
config['import']['set_fields'] = { | ||||||||||||||||||
u'collection': collection, | ||||||||||||||||||
u'genre': genre | ||||||||||||||||||
u'genre': genre, | ||||||||||||||||||
u'comments': comments | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
# As-is album import. | ||||||||||||||||||
|
@@ -755,6 +757,10 @@ def test_set_fields(self): | |||||||||||||||||
album.load() # TODO: Not sure this is necessary. | ||||||||||||||||||
self.assertEqual(album.genre, genre) | ||||||||||||||||||
self.assertEqual(album.collection, collection) | ||||||||||||||||||
for item in album.items(): | ||||||||||||||||||
self.assertEqual(item.genre, genre) | ||||||||||||||||||
self.assertEqual(item.collection, collection) | ||||||||||||||||||
self.assertEqual(item.comments, comments) | ||||||||||||||||||
# Remove album from library to test again with APPLY choice. | ||||||||||||||||||
album.remove() | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -768,6 +774,10 @@ def test_set_fields(self): | |||||||||||||||||
album.load() | ||||||||||||||||||
self.assertEqual(album.genre, genre) | ||||||||||||||||||
self.assertEqual(album.collection, collection) | ||||||||||||||||||
for item in album.items(): | ||||||||||||||||||
self.assertEqual(item.genre, genre) | ||||||||||||||||||
self.assertEqual(item.collection, collection) | ||||||||||||||||||
self.assertEqual(item.comments, comments) | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you checked that this test fails without the above changes to Maybe change to
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I checked. It failed without the change. In particular, it would not set the comments. Nevertheless I have adopted your suggestion for a stricter |
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
class ImportTracksTest(_common.TestCase, ImportHelper): | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exact same loop as before, wrapped in a transaction plus amended with changing all items of the album.