diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index 768eb76c7..a4c4c376b 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -70,7 +70,7 @@ class UserError(Exception): """ -# Utilities. +# Encoding utilities. def _out_encoding(): """Get the encoding to use for *outputting* strings to the console. @@ -137,6 +137,27 @@ def print_(*strings, **kwargs): sys.stdout.write(txt) +# Configuration wrappers. + +def _bool_fallback(opt, view): + """Given a boolean or None, return the original value or a + configuration option as a fallback. + """ + if opt is None: + return view.get(bool) + else: + return opt + + +def should_write(write_opt): + """Decide whether a command that updates metadata should also write tags, + using the importer configuration as the default. + """ + return _bool_fallback(write_opt, config['import']['write']) + + +# Input prompts. + def input_(prompt=None): """Like `raw_input`, but decodes the result to a Unicode string. Raises a UserError if stdin is not available. The prompt is sent to @@ -327,6 +348,8 @@ def input_yn(prompt, require=False): return sel == 'y' +# Human output formatting. + def human_bytes(size): """Formats size, a number of bytes, in a human-readable way.""" powers = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 'H'] @@ -374,6 +397,8 @@ def human_seconds_short(interval): return u'%i:%02i' % (interval // 60, interval % 60) +# Colorization. + # ANSI terminal colorization code heavily inspired by pygments: # http://dev.pocoo.org/hg/pygments-main/file/b2deea5b5030/pygments/console.py # (pygments is by Tim Hatch, Armin Ronacher, et al.) diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 348d12c88..69213ea97 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -1293,10 +1293,8 @@ def modify_func(lib, opts, args): query, mods, dels = modify_parse_args(decargs(args)) if not mods and not dels: raise ui.UserError('no modifications specified') - write = opts.write if opts.write is not None else \ - config['import']['write'].get(bool) - modify_items(lib, mods, dels, query, write, opts.move, opts.album, - not opts.yes) + modify_items(lib, mods, dels, query, ui.should_write(opts.write), + opts.move, opts.album, not opts.yes) modify_cmd = ui.Subcommand(