mirror of
https://github.com/beetbox/beets.git
synced 2025-12-25 18:13:17 +01:00
Add _item_write method and remove duplicate code
This commit is contained in:
parent
13cbcad581
commit
ddf5233daa
2 changed files with 17 additions and 28 deletions
|
|
@ -29,6 +29,7 @@ from beets import dbcore
|
|||
from beets import plugins
|
||||
from beets import util
|
||||
from beets import config
|
||||
from beets import ui
|
||||
from beets.util import pipeline
|
||||
from beets.util import syspath, normpath, displayable_path
|
||||
from beets.util.enumeration import enum
|
||||
|
|
@ -893,15 +894,7 @@ def manipulate_files(session):
|
|||
item.move(True)
|
||||
|
||||
if config['import']['write'] and task.should_write_tags():
|
||||
# FIXME duplicates code from `ui.commands.write_items`.
|
||||
try:
|
||||
item.write()
|
||||
except (mediafile.UnreadableFileError,
|
||||
util.FilesystemError,
|
||||
plugins.BeforeWriteError) as exc:
|
||||
log.error(u'could not write {0}: {1}'.format(
|
||||
util.displayable_path(item.path), exc
|
||||
))
|
||||
ui.commands._item_write(item)
|
||||
|
||||
# Save new paths.
|
||||
with session.lib.transaction():
|
||||
|
|
|
|||
|
|
@ -76,6 +76,19 @@ def _do_query(lib, query, album, also_items=True):
|
|||
|
||||
return items, albums
|
||||
|
||||
def _item_write(item):
|
||||
"""Wrapper for ``item.write()`` that handles exceptions and logs
|
||||
errors during user interaction.
|
||||
"""
|
||||
try:
|
||||
item.write()
|
||||
except (mediafile.UnreadableFileError,
|
||||
util.FilesystemError,
|
||||
plugins.BeforeWriteError) as exc:
|
||||
log.error(u'could not write {0}: {1}'.format(
|
||||
util.displayable_path(item.path), exc
|
||||
))
|
||||
|
||||
|
||||
|
||||
# fields: Shows a list of available fields for queries and format strings.
|
||||
|
|
@ -1135,16 +1148,7 @@ def modify_items(lib, mods, query, write, move, album, confirm):
|
|||
else:
|
||||
changed_items = changed
|
||||
for item in changed_items:
|
||||
# FIXME duplicates code from `ui.commands.write_items`.
|
||||
try:
|
||||
item.write()
|
||||
except (mediafile.UnreadableFileError,
|
||||
util.FilesystemError,
|
||||
plugins.BeforeWriteError) as exc:
|
||||
log.error(u'could not write {0}: {1}'.format(
|
||||
util.displayable_path(item.path), exc
|
||||
))
|
||||
continue
|
||||
_item_write(item)
|
||||
|
||||
modify_cmd = ui.Subcommand('modify',
|
||||
help='change metadata fields', aliases=('mod',))
|
||||
|
|
@ -1241,15 +1245,7 @@ def write_items(lib, query, pretend):
|
|||
changed = ui.show_model_changes(item, clean_item,
|
||||
library.ITEM_KEYS_WRITABLE, always=True)
|
||||
if changed and not pretend:
|
||||
try:
|
||||
item.write()
|
||||
except (mediafile.UnreadableFileError,
|
||||
util.FilesystemError,
|
||||
plugins.BeforeWriteError) as exc:
|
||||
log.error(u'could not write {0}: {1}'.format(
|
||||
util.displayable_path(item.path), exc
|
||||
))
|
||||
continue
|
||||
_item_write(item)
|
||||
|
||||
write_cmd = ui.Subcommand('write', help='write tag information to files')
|
||||
write_cmd.parser.add_option('-p', '--pretend', action='store_true',
|
||||
|
|
|
|||
Loading…
Reference in a new issue