zero, the: Python 2.6-compatible format strings

This commit is contained in:
Adrian Sampson 2012-09-25 15:13:33 -07:00
parent 4aac7f5324
commit 2793af7d70
3 changed files with 15 additions and 13 deletions

View file

@ -64,12 +64,12 @@ class ThePlugin(BeetsPlugin):
try:
re.compile(p)
except re.error:
print(u'[the] invalid pattern: {}'.format(p),
print(u'[the] invalid pattern: {0}'.format(p),
file=sys.stderr)
else:
if not (p.startswith('^') or p.endswith('$')):
if not the_options['silent']:
print(u'[the] warning: pattern \"{}\" will not '
print(u'[the] warning: pattern \"{0}\" will not '
'match string start/end'.format(p),
file=sys.stderr)
if the_options['a']:
@ -79,7 +79,7 @@ class ThePlugin(BeetsPlugin):
if not the_options['patterns'] and not the_options['silent']:
print('[the] no patterns defined!')
if the_options['debug']:
print(u'[the] patterns: {}'
print(u'[the] patterns: {0}'
.format(' '.join(the_options['patterns'])), file=sys.stderr)
@ -118,7 +118,7 @@ def func_the(text):
if r != text:
break
if the_options['debug']:
print(u'[the] \"{}\" -> \"{}\"'.format(text, r), file=sys.stderr)
print(u'[the] \"{0}\" -> \"{1}\"'.format(text, r), file=sys.stderr)
return r
else:
return u''

View file

@ -43,9 +43,9 @@ class ZeroPlugin(BeetsPlugin):
return cls._instance
def __str__(self):
return ('[zero]\n debug = {}\n fields = {}\n patterns = {}\n'
' warned = {}'.format(self.debug, self.fields, self.patterns,
self.warned))
return ('[zero]\n debug = {0}\n fields = {1}\n patterns = {2}\n'
' warned = {3}'.format(self.debug, self.fields, self.patterns,
self.warned))
def dbg(self, *args):
"""Prints message to stderr."""
@ -59,7 +59,9 @@ class ZeroPlugin(BeetsPlugin):
self.debug = ui.config_val(config, 'zero', 'debug', True, bool)
for f in ui.config_val(config, 'zero', 'fields', '').split():
if f not in ITEM_KEYS:
self.dbg('invalid field \"{}\" (try \'beet fields\')')
self.dbg(
'invalid field \"{0}\" (try \'beet fields\')'.format(f)
)
else:
self.fields.append(f)
p = ui.config_val(config, 'zero', f, '').split()
@ -100,16 +102,16 @@ class ZeroPlugin(BeetsPlugin):
try:
fval = getattr(item, fn)
except AttributeError:
self.dbg('? no such field: {}'.format(fn))
self.dbg('? no such field: {0}'.format(fn))
else:
if not self.match_patterns(fval, self.patterns[fn]):
self.dbg('\"{}\" ({}) is not match any of: {}'
self.dbg('\"{0}\" ({1}) is not match any of: {2}'
.format(fval, fn, ' '.join(self.patterns[fn])))
continue
self.dbg('\"{}\" ({}) match: {}'
self.dbg('\"{0}\" ({1}) match: {2}'
.format(fval, fn, ' '.join(self.patterns[fn])))
setattr(item, fn, type(fval)())
self.dbg('{}={}'.format(fn, getattr(item, fn)))
self.dbg('{0}={1}'.format(fn, getattr(item, fn)))
@ZeroPlugin.listen('import_task_choice')

View file

@ -5,7 +5,7 @@ from beets.library import Item
from beetsplug.zero import ZeroPlugin
class ThePluginTest(unittest.TestCase):
class ZeroPluginTest(unittest.TestCase):
def test_singleton(self):
z1 = ZeroPlugin()