From aa7891eb21862a3d53c1029040466d77bf7e048f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Sun, 25 Mar 2007 14:08:59 +0200 Subject: [PATCH] Strip white-space from directory names. (#2558) --- NEWS.txt | 1 + picard/util/__init__.py | 5 +++-- test/test_utils.py | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/NEWS.txt b/NEWS.txt index 3202a3779..4c37774c0 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -5,6 +5,7 @@ Version 0.9.0alpha6 - 2007-03-XX * Automatically parse track numbers from file names like 01.flac for better cluster->album matching with untagged files. * Support for the new sorting tags in MP4 tags from iTunes 7.1. + * Strip white-space from directory names. (#2558) * Bug Fixes: * Artist names from ARs should be translated, too. * Freeze after answering no to "download the new version" prompt. (#2542) diff --git a/picard/util/__init__.py b/picard/util/__init__.py index c6454a108..2e787bde5 100644 --- a/picard/util/__init__.py +++ b/picard/util/__init__.py @@ -182,10 +182,11 @@ _re_slashes = re.compile(r'[\\/]', re.UNICODE) def sanitize_filename(string, repl="_"): return _re_slashes.sub(repl, string) -def make_short_filename(prefix, filename, length=250, max_length=250, +def make_short_filename(prefix, filename, length=240, max_length=200, mid_length=32, min_length=2): - parts = _re_slashes.split(filename) + parts = [part.strip() for part in _re_slashes.split(filename)] parts.reverse() + filename = os.path.join(*parts) left = len(prefix) + len(filename) + 1 - length for i in range(len(parts)): diff --git a/test/test_utils.py b/test/test_utils.py index bb680a674..c72d5456a 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -75,6 +75,10 @@ class ShortFilenameTest(unittest.TestCase): def test_too_long(self): self.failUnlessRaises(IOError, util.make_short_filename, "/home/me/", os.path.join("a1234567890", "b1234567890"), 10) + def test_whitespace(self): + fn = util.make_short_filename("/home/me/", os.path.join("a1234567890 ", " b1234567890 "), 22) + self.failUnlessEqual(fn, os.path.join("a12345678", "b1")) + class TranslateArtistTest(unittest.TestCase):