changelog note &c. for "the" plugin (GH-47)

This commit is contained in:
Adrian Sampson 2012-09-17 11:11:22 -07:00
parent cdc833b8ab
commit 201571bf93
2 changed files with 30 additions and 21 deletions

View file

@ -1,9 +1,16 @@
#!/usr/bin/env python2
# This file is part of beets.
# Copyright 2012, Blemjhoo Tezoulbr <baobab@heresiarch.info>.
#
# This is a plugin for beets music organizer.
# Copyright (c) 2012 Blemjhoo Tezoulbr <baobab@heresiarch.info>
# Licensed under the same terms as beets itself.
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
"""Moves patterns in path formats (suitable for moving articles)."""
@ -26,32 +33,32 @@ the_options = {
'the': True,
'a': True,
'format': FORMAT,
'strip': False,
'strip': False,
'silent': False,
'patterns': [PATTERN_THE, PATTERN_A],
'patterns': [PATTERN_THE, PATTERN_A],
}
class ThePlugin(BeetsPlugin):
def configure(self, config):
if not config.has_section('the'):
print('[the] plugin is not configured, using defaults',
file=sys.stderr)
return
self.in_config = True
the_options['debug'] = ui.config_val(config, 'the', 'debug', False,
the_options['debug'] = ui.config_val(config, 'the', 'debug', False,
bool)
the_options['the'] = ui.config_val(config, 'the', 'the', True, bool)
the_options['a'] = ui.config_val(config, 'the', 'a', True, bool)
the_options['format'] = ui.config_val(config, 'the', 'format',
FORMAT)
the_options['strip'] = ui.config_val(config, 'the', 'strip', False,
the_options['strip'] = ui.config_val(config, 'the', 'strip', False,
bool)
the_options['silent'] = ui.config_val(config, 'the', 'silent', False,
the_options['silent'] = ui.config_val(config, 'the', 'silent', False,
bool)
the_options['patterns'] = ui.config_val(config, 'the', 'patterns',
'').split()
the_options['patterns'] = ui.config_val(config, 'the', 'patterns',
'').split()
for p in the_options['patterns']:
if p:
try:
@ -63,18 +70,18 @@ class ThePlugin(BeetsPlugin):
if not (p.startswith('^') or p.endswith('$')):
if not the_options['silent']:
print(u'[the] warning: pattern \"{}\" will not '
'match string start/end'.format(p),
'match string start/end'.format(p),
file=sys.stderr)
if the_options['a']:
the_options['patterns'] = [PATTERN_A] + the_options['patterns']
if the_options['the']:
the_options['patterns'] = [PATTERN_THE] + the_options['patterns']
if not the_options['patterns'] and not the_options['silent']:
print('[the] no patterns defined!')
print('[the] no patterns defined!')
if the_options['debug']:
print(u'[the] patterns: {}'
.format(' '.join(the_options['patterns'])), file=sys.stderr)
def unthe(text, pattern, strip=False):
"""Moves pattern in the path format string or strips it
@ -82,9 +89,9 @@ def unthe(text, pattern, strip=False):
text -- text to handle
pattern -- regexp pattern (case ignore is already on)
strip -- if True, pattern will be removed
"""
if text:
"""
if text:
r = re.compile(pattern, flags=re.IGNORECASE)
try:
t = r.findall(text)[0]
@ -95,10 +102,10 @@ def unthe(text, pattern, strip=False):
if strip:
return r
else:
return the_options['format'].format(r, t.strip()).strip()
return the_options['format'].format(r, t.strip()).strip()
else:
return u''
@ThePlugin.template_func('the')
def func_the(text):
@ -119,6 +126,6 @@ def func_the(text):
# simple tests
if __name__ == '__main__':
print(unthe('The The', PATTERN_THE))
print(unthe('The The', PATTERN_THE))
print(unthe('An Apple', PATTERN_A))
print(unthe('A Girl', PATTERN_A, strip=True))

View file

@ -4,6 +4,8 @@ Changelog
1.0b16 (in development)
-----------------------
* New plugin: :doc:`/plugins/the` adds a template function that helps format
text for nicely-sorted directory listings. Thanks to Blemjhoo Tezoulbr.
* :doc:`/plugins/scrub`: Scrubbing now removes *all* types of tags from a file
rather than just one. For example, if your FLAC file has both ordinary FLAC
tags and ID3 tags, the ID3 tags are now also removed.