mirror of
https://github.com/fergalmoran/picard.git
synced 2026-01-19 15:05:33 +00:00
Documented make_short_filename a little bit, since it is not that intuitive to understand.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user