From 89827fde3ade7777d8b8aa4dee3ee141a4b01877 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Fri, 11 Jul 2025 14:18:09 +0100 Subject: [PATCH 1/2] Allow specifying a separator in the formats_paths() function. --- src/calibre/utils/formatter_functions.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index 01d0ebcfe7..5981a57ce5 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -1300,20 +1300,25 @@ format names are always uppercase, as in EPUB. class BuiltinFormatsPaths(BuiltinFormatterFunction): name = 'formats_paths' - arg_count = 0 + arg_count = -1 category = GET_FROM_METADATA __doc__ = doc = _( r''' -``formats_paths()`` -- return a comma-separated list of colon-separated items -``FMT:PATH`` giving the full path to the formats of a book.[/] You can use the -``select()`` function to get the path for a specific format. Note that format names -are always uppercase, as in EPUB. + +``formats_paths([separator])`` -- return a ``separator``-separated list of +colon-separated items ``FMT:PATH`` giving the full path to the formats of a +book.[/] The ``separator`` argument is optional. If not supplied then the +seoarator is ``', '`` (comma space). If the separator is a comma then you can +use the ``select()`` function to get the path for a specific format. Note that +format names are always uppercase, as in EPUB. + + ''') - def evaluate(self, formatter, kwargs, mi, locals): + def evaluate(self, formatter, kwargs, mi, locals, sep=','): fmt_data = mi.get('format_metadata', {}) try: - return ','.join(k.upper()+':'+str(v['path']) for k,v in iteritems(fmt_data)) + return sep.join(k.upper()+':'+str(v['path']) for k,v in iteritems(fmt_data)) except: return '' From baa0756113de5647d760f2f4060f99581d350185 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Fri, 11 Jul 2025 14:21:10 +0100 Subject: [PATCH 2/2] Remove blank lines from formats_paths() documentation --- src/calibre/utils/formatter_functions.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index 5981a57ce5..3efb7bf495 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -1284,6 +1284,7 @@ class BuiltinFormatsSizes(BuiltinFormatterFunction): category = GET_FROM_METADATA __doc__ = doc = _( r''' + ``formats_sizes()`` -- return a comma-separated list of colon-separated ``FMT:SIZE`` items giving the sizes of the formats of a book in bytes.[/] You can use the ``select()`` function to get the size for a specific format. Note that @@ -1304,15 +1305,12 @@ class BuiltinFormatsPaths(BuiltinFormatterFunction): category = GET_FROM_METADATA __doc__ = doc = _( r''' - ``formats_paths([separator])`` -- return a ``separator``-separated list of colon-separated items ``FMT:PATH`` giving the full path to the formats of a book.[/] The ``separator`` argument is optional. If not supplied then the seoarator is ``', '`` (comma space). If the separator is a comma then you can use the ``select()`` function to get the path for a specific format. Note that format names are always uppercase, as in EPUB. - - ''') def evaluate(self, formatter, kwargs, mi, locals, sep=','):