mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 21:14:19 +01:00
Replace path separators from config
This commit is contained in:
parent
802c4560d4
commit
c82b31e750
4 changed files with 31 additions and 6 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue