mirror of
https://github.com/beetbox/beets.git
synced 2026-01-05 15:33:15 +01:00
use booleans for whitelist and c14n options
homogenise options setup using booleans, while keeping the empty string (synonym of ‘true’) for backward compatibility.
This commit is contained in:
parent
d5dbaeff7a
commit
ef3c1cd1ff
2 changed files with 15 additions and 19 deletions
|
|
@ -125,7 +125,7 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
|||
'min_weight': 10,
|
||||
'count': 1,
|
||||
'fallback': None,
|
||||
'canonical': None,
|
||||
'canonical': 'false',
|
||||
'source': 'album',
|
||||
'force': True,
|
||||
'auto': True,
|
||||
|
|
@ -144,14 +144,12 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
|||
|
||||
# Read the whitelist file if enabled.
|
||||
self.whitelist = set()
|
||||
wl_filename = self.config['whitelist'].get()
|
||||
if wl_filename is not None:
|
||||
wl_filename = wl_filename.strip()
|
||||
if not wl_filename:
|
||||
wl_filename = self.config['whitelist'].get().strip()
|
||||
if wl_filename != 'false':
|
||||
if wl_filename in ('true', ''):
|
||||
wl_filename = WHITELIST
|
||||
wl_filename = normpath(wl_filename)
|
||||
with open(wl_filename, 'r') as f:
|
||||
# with open(self.config['whitelist'].as_filename()) as f:
|
||||
for line in f:
|
||||
line = line.decode('utf8').strip().lower()
|
||||
if line and not line.startswith(u'#'):
|
||||
|
|
@ -159,13 +157,11 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
|||
|
||||
# Read the genres tree for canonicalization if enabled.
|
||||
self.c14n_branches = []
|
||||
c14n_filename = self.config['canonical'].get()
|
||||
if c14n_filename is not None:
|
||||
c14n_filename = c14n_filename.strip()
|
||||
if not c14n_filename:
|
||||
c14n_filename = self.config['canonical'].get().strip()
|
||||
if c14n_filename != 'false':
|
||||
if c14n_filename in ('true', ''):
|
||||
c14n_filename = C14N_TREE
|
||||
c14n_filename = normpath(c14n_filename)
|
||||
|
||||
genres_tree = yaml.load(open(c14n_filename, 'r'))
|
||||
flatten_tree(genres_tree, [], self.c14n_branches)
|
||||
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ lastGenrePlugin = lastgenre.LastGenrePlugin()
|
|||
|
||||
class LastGenrePluginTest(unittest.TestCase):
|
||||
|
||||
def _setup_config(self, whitelist=None, canonical=None, count=1):
|
||||
def _setup_config(self, whitelist='false', canonical='false', count=1):
|
||||
config['lastgenre']['canonical'] = canonical
|
||||
config['lastgenre']['count'] = count
|
||||
if not whitelist: # Either None or default ('').
|
||||
if whitelist in ('true', 'false'):
|
||||
config['lastgenre']['whitelist'] = whitelist
|
||||
lastGenrePlugin.setup()
|
||||
if whitelist:
|
||||
if whitelist not in ('true', 'false'):
|
||||
lastGenrePlugin.whitelist = whitelist
|
||||
|
||||
def test_default(self):
|
||||
|
|
@ -46,7 +46,7 @@ class LastGenrePluginTest(unittest.TestCase):
|
|||
"""Default c14n tree funnels up to most common genre except for *wrong*
|
||||
genres that stay unchanged.
|
||||
"""
|
||||
self._setup_config(canonical='', count=99)
|
||||
self._setup_config(canonical='true', count=99)
|
||||
self.assertEqual(lastGenrePlugin._resolve_genres(['delta blues']),
|
||||
'Blues')
|
||||
self.assertEqual(lastGenrePlugin._resolve_genres(['iota blues']),
|
||||
|
|
@ -55,7 +55,7 @@ class LastGenrePluginTest(unittest.TestCase):
|
|||
def test_whitelist_only(self):
|
||||
"""Default whitelist rejects *wrong* (non existing) genres.
|
||||
"""
|
||||
self._setup_config(whitelist='')
|
||||
self._setup_config(whitelist='true')
|
||||
self.assertEqual(lastGenrePlugin._resolve_genres(['iota blues']),
|
||||
'')
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ class LastGenrePluginTest(unittest.TestCase):
|
|||
"""Default whitelist and c14n both activated result in all parents
|
||||
genres being selected (from specific to common).
|
||||
"""
|
||||
self._setup_config(canonical='', whitelist='', count=99)
|
||||
self._setup_config(canonical='true', whitelist='true', count=99)
|
||||
self.assertEqual(lastGenrePlugin._resolve_genres(['delta blues']),
|
||||
'Delta Blues, Country Blues, Blues')
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ class LastGenrePluginTest(unittest.TestCase):
|
|||
"""Keep the n first genres, after having applied c14n when necessary
|
||||
"""
|
||||
self._setup_config(whitelist=set(['blues', 'rock', 'jazz']),
|
||||
canonical='',
|
||||
canonical='true',
|
||||
count=2)
|
||||
# thanks to c14n, 'blues' superseeds 'country blues' and takes the
|
||||
# second slot
|
||||
|
|
@ -104,7 +104,7 @@ class LastGenrePluginTest(unittest.TestCase):
|
|||
def test_c14n_whitelist(self):
|
||||
"""Genres first pass through c14n and are then filtered
|
||||
"""
|
||||
self._setup_config(canonical='', whitelist=set(['rock']))
|
||||
self._setup_config(canonical='true', whitelist=set(['rock']))
|
||||
self.assertEqual(lastGenrePlugin._resolve_genres(['delta blues']),
|
||||
'')
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue