From 2ffd3e287f78e66b79b77d2b9767d9b1d02c1a13 Mon Sep 17 00:00:00 2001 From: Harry Khanna Date: Tue, 19 Aug 2014 13:43:16 -0400 Subject: [PATCH] Add --always flag for write subcommand Forces a write of tags to file even if the file's tags match the database. This is useful to force plugins that respond to write (e.g., Scrub and Zero) to run on those tags. This may also make the TODO comment in zero.py less important since creates a way to manually run the zero plugin on a file imported as-is. --- beets/ui/commands.py | 12 ++++++++---- docs/reference/cli.rst | 7 +++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/beets/ui/commands.py b/beets/ui/commands.py index e688f4c44..0a32be08a 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -1415,7 +1415,7 @@ default_commands.append(move_cmd) # write: Write tags into files. -def write_items(lib, query, pretend): +def write_items(lib, query, pretend, always): """Write tag information from the database to the respective files in the filesystem. """ @@ -1440,13 +1440,13 @@ def write_items(lib, query, pretend): # Check for and display changes. changed = ui.show_model_changes(item, clean_item, - library.Item._media_fields) - if changed and not pretend: + library.Item._media_fields, always) + if (changed or always) and not pretend: item.try_write() def write_func(lib, opts, args): - write_items(lib, decargs(args), opts.pretend) + write_items(lib, decargs(args), opts.pretend, opts.always) write_cmd = ui.Subcommand('write', help='write tag information to files') @@ -1454,6 +1454,10 @@ write_cmd.parser.add_option( '-p', '--pretend', action='store_true', help="show all changes but do nothing" ) +write_cmd.parser.add_option( + '-a', '--always', action='store_true', + help="write tags even if the existing tags match the database" +) write_cmd.func = write_func default_commands.append(write_cmd) diff --git a/docs/reference/cli.rst b/docs/reference/cli.rst index 391dfa0e6..b295e0916 100644 --- a/docs/reference/cli.rst +++ b/docs/reference/cli.rst @@ -284,7 +284,7 @@ write ````` :: - beet write [-p] [QUERY] + beet write [-pa] [QUERY] Write metadata from the database into files' tags. @@ -294,9 +294,12 @@ have the option of storing changes only in the database, leaving your files untouched. The ``write`` command lets you later change your mind and write the contents of the database into the files. +You can think of this command as the opposite of :ref:`update-cmd`. + The ``-p`` option previews metadata changes without actually applying them. -You can think of this command as the opposite of :ref:`update-cmd`. +The ``-a`` option forces a write to the file, even if the file tags match the database. This is useful for making sure that enabled plugins that run on write (e.g., the Scrub and Zero plugins) are run on the file. + .. _stats-cmd: