diff --git a/tmt/cli.py b/tmt/cli.py index 98fbfd798e..d31781964b 100644 --- a/tmt/cli.py +++ b/tmt/cli.py @@ -773,7 +773,7 @@ def tests_import( # TODO: move to `template` export plugin options @option( '--template', metavar='PATH', - help="Path to a template to use for rendering the export. Used with '--how=template' only." + help="Path to a template to use for rendering the export. Used with '--how=rst|template' only." ) def tests_export( context: Context, @@ -1004,7 +1004,7 @@ def plans_create( # TODO: move to `template` export plugin options @option( '--template', metavar='PATH', - help="Path to a template to use for rendering the export. Used with '--how=template' only." + help="Path to a template to use for rendering the export. Used with '--how=rst|template' only." ) def plans_export( context: Context, @@ -1260,7 +1260,7 @@ def headfoot(text: str) -> None: # TODO: move to `template` export plugin options @option( '--template', metavar='PATH', - help="Path to a template to use for rendering the export. Used with '--how=template' only." + help="Path to a template to use for rendering the export. Used with '--how=rst|template' only." ) def stories_export( context: Context, diff --git a/tmt/export/rst.py b/tmt/export/rst.py index 90d19337ba..80dd85689c 100644 --- a/tmt/export/rst.py +++ b/tmt/export/rst.py @@ -4,6 +4,7 @@ import tmt.export import tmt.export.template import tmt.utils +from tmt.utils import Path @tmt.base.Story.provides_export('rst') @@ -12,8 +13,10 @@ class RestructuredExporter(tmt.export.ExportPlugin): def export_story(cls, story: tmt.base.Story, keys: Optional[List[str]] = None, + template: Optional[Path] = None, include_title: bool = True) -> str: return tmt.export.template.TemplateExporter.render_template( + template_filepath=template, default_template_filename='default-story.rst.j2', keys=keys, STORY=story, @@ -23,7 +26,9 @@ def export_story(cls, def export_story_collection(cls, stories: List[tmt.base.Story], keys: Optional[List[str]] = None, + template: Optional[Path] = None, include_title: bool = True, **kwargs: Any) -> str: - return '\n\n'.join([cls.export_story(story, keys=keys, include_title=include_title) - for story in stories]) + return '\n\n'.join([ + cls.export_story(story, keys=keys, template=template, include_title=include_title) + for story in stories]) diff --git a/tmt/utils.py b/tmt/utils.py index 4e274aafe3..951e8ce53f 100644 --- a/tmt/utils.py +++ b/tmt/utils.py @@ -5142,6 +5142,10 @@ def render_template_file( return template.render(**variables).strip() + except FileNotFoundError as exc: + raise GeneralError( + f"Could not open template '{template_filepath}'.") from exc + except jinja2.exceptions.TemplateSyntaxError as exc: raise GeneralError( f"Could not parse template '{template_filepath}' at line {exc.lineno}.") from exc