From be669e335c1606e515ce2c19c8ac5b98be2f5294 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Sun, 4 Oct 2009 13:28:24 +0200 Subject: [PATCH] Documented make_short_filename a little bit, since it is not that intuitive to understand. --- picard/util/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/picard/util/__init__.py b/picard/util/__init__.py index 3188e17c9..c7419128e 100644 --- a/picard/util/__init__.py +++ b/picard/util/__init__.py @@ -203,12 +203,20 @@ _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=240, max_length=200, +def make_short_filename(prefix, filename, max_path_length=240, max_length=200, mid_length=32, min_length=2): + """ + Attempts to shorten the file name to the maximum allowed length. + + max_path_length: The maximum length of the complete path. + max_length: The maximum length of a single file or directory name. + mid_length: The medium preferred length of a single file or directory. + min_length: The minimum allowed length of a single file or directory. + """ parts = [part.strip() for part in _re_slashes.split(filename)] parts.reverse() filename = os.path.join(*parts) - left = len(prefix) + len(filename) + 1 - length + left = len(prefix) + len(filename) + 1 - max_path_length for i in range(len(parts)): left -= max(0, len(parts[i]) - max_length)