Replace path separators from config

This commit is contained in:
Thomas Scholtes 2014-02-06 14:22:40 +01:00
parent 802c4560d4
commit c82b31e750
4 changed files with 31 additions and 6 deletions

View file

@ -346,6 +346,10 @@ class Model(object):
value = unicode(value)
if for_path:
replacements = self._db.replacements or []
for regex, repl in replacements:
value = regex.sub(repl, value)
sep_repl = beets.config['path_sep_replace'].get(unicode)
for sep in (os.path.sep, os.path.altsep):
if sep:

View file

@ -70,6 +70,8 @@ Other little fixes:
are now treated as directories. Thanks to Pedro Silva.
* The :ref:`modify-cmd` command now skips confirmation and prints a message if
no changes are necessary. Thanks to brilnius.
* The replacement characters for path separators can be set in the
"replace" configuration.
1.3.2 (December 22, 2013)

View file

@ -257,14 +257,18 @@ class Bag(object):
def platform_windows():
import ntpath
old_path = os.path
os.path = ntpath
yield
os.path = old_path
try:
os.path = ntpath
yield
finally:
os.path = old_path
@contextmanager
def platform_posix():
import posixpath
old_path = os.path
os.path = posixpath
yield
os.path = old_path
try:
os.path = posixpath
yield
finally:
os.path = old_path

View file

@ -248,6 +248,21 @@ class DestinationTest(_common.TestCase):
self.assertFalse('>' in p)
self.assertFalse('|' in p)
def test_replace_unix_path_separator_from_config(self):
self.i.title = 'one \\ two / three.mp3'
self.lib.replacements = [(re.compile(r'[\\/]'), 'x')]
with _common.platform_windows():
p = self.i.destination()
self.assertTrue('one x two x three.mp3' in p)
self.lib.replacements = None
def test_replace_windows_path_separator_from_config(self):
self.i.title = 'one \\ two / three.mp3'
self.lib.replacements = [(re.compile(r'[\\/]'), 'x')]
with _common.platform_windows():
p = self.i.destination()
self.assertTrue('one x two x three.mp3' in p)
def test_path_with_format(self):
self.lib.path_formats = [('default', '$artist/$album ($format)')]
p = self.i.destination()