mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
add confirmation for empty query
This commit is contained in:
parent
2903925e2f
commit
7833469261
2 changed files with 38 additions and 6 deletions
|
|
@ -23,7 +23,7 @@ import re
|
|||
from beets.plugins import BeetsPlugin
|
||||
from beets.mediafile import MediaFile
|
||||
from beets.importer import action
|
||||
from beets.ui import Subcommand, decargs
|
||||
from beets.ui import Subcommand, decargs, input_yn
|
||||
from beets.util import confit
|
||||
|
||||
__author__ = 'baobab@heresiarch.info'
|
||||
|
|
@ -69,6 +69,8 @@ class ZeroPlugin(BeetsPlugin):
|
|||
zero_command = Subcommand('zero', help='set fields to null')
|
||||
|
||||
def zero_fields(lib, opts, args):
|
||||
if not decargs(args) and not input_yn(u"Remove fields for all items? (Y/n)", True):
|
||||
return
|
||||
for item in lib.items(decargs(args)):
|
||||
self.process_item(item)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
from __future__ import division, absolute_import, print_function
|
||||
|
||||
import unittest
|
||||
from test.helper import TestHelper
|
||||
from test.helper import TestHelper, control_stdin
|
||||
|
||||
from beets.library import Item
|
||||
from beetsplug.zero import ZeroPlugin
|
||||
|
|
@ -135,7 +135,8 @@ class ZeroPluginTest(unittest.TestCase, TestHelper):
|
|||
self.config['zero']['auto'] = False
|
||||
|
||||
self.load_plugins('zero')
|
||||
self.run_command('zero')
|
||||
with control_stdin('y'):
|
||||
self.run_command('zero')
|
||||
|
||||
mf = MediaFile(syspath(item.path))
|
||||
item = self.lib.get_item(item_id)
|
||||
|
|
@ -160,7 +161,8 @@ class ZeroPluginTest(unittest.TestCase, TestHelper):
|
|||
self.config['zero']['auto'] = False
|
||||
|
||||
self.load_plugins('zero')
|
||||
self.run_command('zero')
|
||||
with control_stdin('y'):
|
||||
self.run_command('zero')
|
||||
|
||||
mf = MediaFile(syspath(item.path))
|
||||
item = self.lib.get_item(item_id)
|
||||
|
|
@ -223,7 +225,8 @@ class ZeroPluginTest(unittest.TestCase, TestHelper):
|
|||
item_id = item.id
|
||||
|
||||
self.load_plugins('zero')
|
||||
self.run_command('zero')
|
||||
with control_stdin('y'):
|
||||
self.run_command('zero')
|
||||
|
||||
item = self.lib.get_item(item_id)
|
||||
|
||||
|
|
@ -241,7 +244,8 @@ class ZeroPluginTest(unittest.TestCase, TestHelper):
|
|||
self.config['zero']['keep_fields'] = [u'comments']
|
||||
|
||||
self.load_plugins('zero')
|
||||
self.run_command('zero')
|
||||
with control_stdin('y'):
|
||||
self.run_command('zero')
|
||||
|
||||
item = self.lib.get_item(item_id)
|
||||
|
||||
|
|
@ -259,6 +263,7 @@ class ZeroPluginTest(unittest.TestCase, TestHelper):
|
|||
'year': 2016,
|
||||
}
|
||||
self.load_plugins('zero')
|
||||
|
||||
z = ZeroPlugin()
|
||||
z.write_event(item, item.path, tags)
|
||||
self.assertEqual(tags['comments'], None)
|
||||
|
|
@ -281,6 +286,31 @@ class ZeroPluginTest(unittest.TestCase, TestHelper):
|
|||
|
||||
self.assertNotIn('id', z.fields_to_progs)
|
||||
|
||||
def test_empty_query_n_response_no_changes(self):
|
||||
item = self.add_item_fixture(
|
||||
year=2016,
|
||||
day=13,
|
||||
month=3,
|
||||
comments=u'test comment'
|
||||
)
|
||||
item.write()
|
||||
item_id = item.id
|
||||
self.config['zero']['fields'] = ['comments']
|
||||
self.config['zero']['update_database'] = True
|
||||
self.config['zero']['auto'] = False
|
||||
|
||||
self.load_plugins('zero')
|
||||
with control_stdin('n'):
|
||||
self.run_command('zero')
|
||||
|
||||
mf = MediaFile(syspath(item.path))
|
||||
item = self.lib.get_item(item_id)
|
||||
|
||||
self.assertEqual(item['year'], 2016)
|
||||
self.assertEqual(mf.year, 2016)
|
||||
self.assertEqual(mf.comments, u'test comment')
|
||||
self.assertEqual(item['comments'], u'test comment')
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
|
|
|||
Loading…
Reference in a new issue