mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
fix inline for album plugin fields (#274)
This commit is contained in:
parent
1ffc56b85a
commit
1898a79d4f
1 changed files with 13 additions and 4 deletions
|
|
@ -18,6 +18,7 @@ import logging
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from beets.plugins import BeetsPlugin
|
from beets.plugins import BeetsPlugin
|
||||||
|
from beets.library import Item, Album
|
||||||
from beets import config
|
from beets import config
|
||||||
|
|
||||||
log = logging.getLogger('beets')
|
log = logging.getLogger('beets')
|
||||||
|
|
@ -46,6 +47,14 @@ def _compile_func(body):
|
||||||
eval(code, env)
|
eval(code, env)
|
||||||
return env[FUNC_NAME]
|
return env[FUNC_NAME]
|
||||||
|
|
||||||
|
def _record(obj):
|
||||||
|
"""Get a dictionary of values for an Item or Album object.
|
||||||
|
"""
|
||||||
|
if isinstance(obj, Item):
|
||||||
|
return dict(obj.record)
|
||||||
|
else:
|
||||||
|
return dict(obj._record)
|
||||||
|
|
||||||
def compile_inline(python_code):
|
def compile_inline(python_code):
|
||||||
"""Given a Python expression or function body, compile it as a path
|
"""Given a Python expression or function body, compile it as a path
|
||||||
field function. The returned function takes a single argument, an
|
field function. The returned function takes a single argument, an
|
||||||
|
|
@ -70,8 +79,8 @@ def compile_inline(python_code):
|
||||||
|
|
||||||
if is_expr:
|
if is_expr:
|
||||||
# For expressions, just evaluate and return the result.
|
# For expressions, just evaluate and return the result.
|
||||||
def _expr_func(item):
|
def _expr_func(obj):
|
||||||
values = dict(item.record)
|
values = _record(obj)
|
||||||
try:
|
try:
|
||||||
return eval(code, values)
|
return eval(code, values)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|
@ -80,8 +89,8 @@ def compile_inline(python_code):
|
||||||
else:
|
else:
|
||||||
# For function bodies, invoke the function with values as global
|
# For function bodies, invoke the function with values as global
|
||||||
# variables.
|
# variables.
|
||||||
def _func_func(item):
|
def _func_func(obj):
|
||||||
func.__globals__.update(item.record)
|
func.__globals__.update(_record(obj))
|
||||||
try:
|
try:
|
||||||
return func()
|
return func()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue