From 6678d4ccae7cbc3239322db5863fa5e199a286d2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 20 Feb 2017 19:51:44 +0530 Subject: [PATCH] Save to disk: Fix path shortening being applied to entire save template even when saving to singe directory. Fixes #1665964 [Saving books to single directory has truncate issue](https://bugs.launchpad.net/calibre/+bug/1665964) --- src/calibre/library/save_to_disk.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/calibre/library/save_to_disk.py b/src/calibre/library/save_to_disk.py index ea8873f62f..a8afad50f4 100644 --- a/src/calibre/library/save_to_disk.py +++ b/src/calibre/library/save_to_disk.py @@ -173,8 +173,8 @@ class Formatter(TemplateFormatter): def get_components(template, mi, id, timefmt='%b %Y', length=250, sanitize_func=ascii_filename, replace_whitespace=False, - to_lowercase=False, safe_format=True, last_has_extension=True): - + to_lowercase=False, safe_format=True, last_has_extension=True, + single_dir=False): tsorder = tweaks['save_template_title_series_sorting'] format_args = FORMAT_ARGS.copy() format_args.update(mi.all_non_none_fields()) @@ -252,6 +252,8 @@ def get_components(template, mi, id, timefmt='%b %Y', length=250, if replace_whitespace: components = [re.sub(r'\s', '_', x) for x in components] + if single_dir: + components = components[-1:] return shorten_components_to(length, components, last_has_extension=last_has_extension) @@ -292,13 +294,11 @@ def get_path_components(opts, mi, book_id, path_length): ascii_filename if opts.asciiize else sanitize_file_name_unicode, to_lowercase=opts.to_lowercase, replace_whitespace=opts.replace_whitespace, safe_format=False, - last_has_extension=False) + last_has_extension=False, single_dir=opts.single_dir) except Exception, e: raise ValueError(_('Failed to calculate path for ' 'save to disk. Template: %(templ)s\n' 'Error: %(err)s')%dict(templ=opts.template, err=e)) - if opts.single_dir: - components = components[-1:] if not components: raise ValueError(_('Template evaluation resulted in no' ' path components. Template: %s')%opts.template)