mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
zero: remove redundant list of dict's keys
This commit is contained in:
parent
58d9a775cc
commit
e6ea6dc875
1 changed files with 5 additions and 7 deletions
|
|
@ -42,7 +42,6 @@ class ZeroPlugin(BeetsPlugin):
|
|||
'fields': [],
|
||||
})
|
||||
|
||||
self.fields = []
|
||||
self.patterns = {}
|
||||
self.warned = False
|
||||
|
||||
|
|
@ -50,7 +49,6 @@ class ZeroPlugin(BeetsPlugin):
|
|||
if f not in ITEM_KEYS:
|
||||
self._log.error(u'[zero] invalid field: {0}'.format(f))
|
||||
else:
|
||||
self.fields.append(f)
|
||||
try:
|
||||
self.patterns[f] = self.config[f].as_str_seq()
|
||||
except confit.NotFoundError:
|
||||
|
|
@ -75,22 +73,22 @@ class ZeroPlugin(BeetsPlugin):
|
|||
|
||||
def write_event(self, item):
|
||||
"""Listen for write event."""
|
||||
if not self.fields:
|
||||
if not self.patterns:
|
||||
self._log.warn(u'[zero] no fields, nothing to do')
|
||||
return
|
||||
for fn in self.fields:
|
||||
for fn, patterns in self.patterns.items():
|
||||
try:
|
||||
fval = getattr(item, fn)
|
||||
except AttributeError:
|
||||
self._log.error(u'[zero] no such field: {0}'.format(fn))
|
||||
else:
|
||||
if not self.match_patterns(fval, self.patterns[fn]):
|
||||
if not self.match_patterns(fval, patterns):
|
||||
self._log.debug(u'[zero] \"{0}\" ({1}) not match: {2}'
|
||||
.format(fval, fn,
|
||||
' '.join(self.patterns[fn])))
|
||||
' '.join(patterns)))
|
||||
continue
|
||||
self._log.debug(u'[zero] \"{0}\" ({1}) match: {2}'
|
||||
.format(fval, fn, ' '.join(self.patterns[fn])))
|
||||
.format(fval, fn, ' '.join(patterns)))
|
||||
setattr(item, fn, type(fval)())
|
||||
self._log.debug(u'[zero] {0}={1}'
|
||||
.format(fn, getattr(item, fn)))
|
||||
|
|
|
|||
Loading…
Reference in a new issue