Skip to content

Commit 8c35a24

Browse files
committed
zero: Check for conflicts only once (#1641)
The old version would trigger the warning twice.
1 parent 71acf93 commit 8c35a24

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

beetsplug/zero.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ def __init__(self):
4848
self.patterns = {}
4949
self.warned = False
5050

51+
# We'll only handle `fields` or `keep_fields`, but not both.
52+
if self.config['fields'] and self.config['keep_fields']:
53+
self._log.warn(u'cannot blacklist and whitelist at the same time')
54+
55+
# Blacklist mode.
5156
if self.config['fields']:
5257
self.validate_config('fields')
5358
for field in self.config['fields'].as_str_seq():
5459
self.set_pattern(field)
5560

61+
# Whitelist mode.
5662
elif self.config['keep_fields']:
5763
self.validate_config('keep_fields')
5864

@@ -61,15 +67,17 @@ def __init__(self):
6167
continue
6268
self.set_pattern(field)
6369

64-
# These fields should be preserved
70+
# These fields should always be preserved.
6571
for key in ('id', 'path', 'album_id'):
6672
if key in self.patterns:
6773
del self.patterns[key]
6874

6975
def validate_config(self, mode):
70-
"""Check if fields written in config are correct."""
71-
if self.config['fields'] and self.config['keep_fields']:
72-
self._log.warn(u'cannot blacklist and whitelist at the same time')
76+
"""Check whether fields in the configuration are valid.
77+
78+
`mode` should either be "fields" or "keep_fields", indicating
79+
the section of the configuration to validate.
80+
"""
7381
for field in self.config[mode].as_str_seq():
7482
if field not in MediaFile.fields():
7583
self._log.error(u'invalid field: {0}', field)

0 commit comments

Comments
 (0)