From 390b0d45c1630e88dabbe6b8451a462a1d2a7d13 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 25 Mar 2019 20:18:19 +0530 Subject: [PATCH] Dont use a python file to store catalog section templates --- resources/catalog/section_list_templates.conf | 30 ++++++++++++++ resources/catalog/section_list_templates.py | 40 ------------------- .../library/catalogs/epub_mobi_builder.py | 16 +++++--- 3 files changed, 40 insertions(+), 46 deletions(-) create mode 100644 resources/catalog/section_list_templates.conf delete mode 100644 resources/catalog/section_list_templates.py diff --git a/resources/catalog/section_list_templates.conf b/resources/catalog/section_list_templates.conf new file mode 100644 index 0000000000..f46da145e0 --- /dev/null +++ b/resources/catalog/section_list_templates.conf @@ -0,0 +1,30 @@ +# These templates control the content of titles displayed in the various sections + +# Available fields: +# Any column, custom or otherwise, defined for the book, plus +# {rating_parens} Rating, in parentheses +# {pubyear} Year the book was published +# {pubyear_parens} Year the book was published, in parentheses + +# Books by Author +by_authors_normal_title_template {title} {pubyear_parens} +by_authors_series_title_template [{series_index}] {title} {pubyear_parens} + +# Books by Title +by_titles_normal_title_template {title} +by_titles_series_title_template {title} ({series} [{series_index}]) + +# Books by Series +by_series_title_template [{series_index}] {title} {pubyear_parens} + +# Books by Genre +by_genres_normal_title_template {title} {pubyear_parens} +by_genres_series_title_template {series_index}. {title} {pubyear_parens} + +# Recently Added +by_recently_added_normal_title_template {title} +by_recently_added_series_title_template {title} ({series} [{series_index}]) + +# By Month added +by_month_added_normal_title_template {title} {pubyear_parens} +by_month_added_series_title_template [{series_index}] {title} {pubyear_parens} diff --git a/resources/catalog/section_list_templates.py b/resources/catalog/section_list_templates.py deleted file mode 100644 index ff89c9e753..0000000000 --- a/resources/catalog/section_list_templates.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python2 -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai - -__license__ = 'GPL v3' -__copyright__ = '2010, Kovid Goyal ' -__docformat__ = 'restructuredtext en' - -''' - These templates control the content of titles displayed in the various sections - - Available fields: - Any column, custom or otherwise, defined for the book, plus - {rating_parens} Rating, in parentheses - {pubyear} Year the book was published - {pubyear_parens} Year the book was published, in parentheses - - -''' -# Books by Author -by_authors_normal_title_template = '{title} {pubyear_parens}' -by_authors_series_title_template = '[{series_index}] {title} {pubyear_parens}' - -# Books by Title -by_titles_normal_title_template = '{title}' -by_titles_series_title_template = '{title} ({series} [{series_index}])' - -# Books by Series -by_series_title_template = '[{series_index}] {title} {pubyear_parens}' - -# Books by Genre -by_genres_normal_title_template = '{title} {pubyear_parens}' -by_genres_series_title_template = '{series_index}. {title} {pubyear_parens}' - -# Recently Added -by_recently_added_normal_title_template = '{title}' -by_recently_added_series_title_template = '{title} ({series} [{series_index}])' - -# By Month added -by_month_added_normal_title_template = '{title} {pubyear_parens}' -by_month_added_series_title_template = '[{series_index}] {title} {pubyear_parens}' diff --git a/src/calibre/library/catalogs/epub_mobi_builder.py b/src/calibre/library/catalogs/epub_mobi_builder.py index 9e3bbaed88..d60941d202 100644 --- a/src/calibre/library/catalogs/epub_mobi_builder.py +++ b/src/calibre/library/catalogs/epub_mobi_builder.py @@ -42,7 +42,7 @@ from calibre.utils.icu import capitalize, collation_order, sort_key from calibre.utils.img import scale_image from calibre.utils.localization import get_lang, lang_as_iso639_1 from calibre.utils.zipfile import ZipFile -from polyglot.builtins import unicode_type, iteritems, exec_path +from polyglot.builtins import unicode_type, iteritems NBSP = u'\u00a0' @@ -4615,11 +4615,15 @@ class CatalogBuilder(object): (strs): section templates added to local namespace """ - templates = {} - exec_path(P('catalog/section_list_templates.py'), templates) - for name, template in iteritems(templates): - if name.startswith('by_') and name.endswith('_template'): - setattr(self, name, force_unicode(template, 'utf-8')) + for line in P('catalog/section_list_templates.conf', data=True).decode('utf-8').splitlines(): + line = line.lstrip() + if line.startswith('#'): + continue + if line.startswith('by_'): + key, val = line.split(' ', 1) + key, val = key.strip(), val.strip() + if key.endswith('_template'): + setattr(self, key, val) def merge_comments(self, record): """ Merge comments with custom column content.