diff libervia/cli/output_template.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 47401850dec6
children
line wrap: on
line diff
--- a/libervia/cli/output_template.py	Tue Jun 18 12:06:45 2024 +0200
+++ b/libervia/cli/output_template.py	Wed Jun 19 18:44:57 2024 +0200
@@ -43,15 +43,19 @@
 
     def _front_url_tmp_dir(self, ctx, relative_url, tmp_dir):
         """Get front URL for temporary directory"""
-        template_data = ctx['template_data']
+        template_data = ctx["template_data"]
         return "file://" + os.path.join(tmp_dir, template_data.theme, relative_url)
 
     def _do_render(self, template_path, css_inline, **kwargs):
         try:
             return self.renderer.render(template_path, css_inline=css_inline, **kwargs)
         except template.TemplateNotFound:
-            self.host.disp(_("Can't find requested template: {template_path}")
-                .format(template_path=template_path), error=True)
+            self.host.disp(
+                _("Can't find requested template: {template_path}").format(
+                    template_path=template_path
+                ),
+                error=True,
+            )
             self.host.quit(C.EXIT_NOT_FOUND)
 
     def render(self, data):
@@ -71,9 +75,11 @@
             template_path = cmd.TEMPLATE
         except AttributeError:
             if not "template" in cmd.args.output_opts:
-                self.host.disp(_(
-                    "no default template set for this command, you need to specify a "
-                    "template using --oo template=[path/to/template.html]"),
+                self.host.disp(
+                    _(
+                        "no default template set for this command, you need to specify a "
+                        "template using --oo template=[path/to/template.html]"
+                    ),
                     error=True,
                 )
                 self.host.quit(C.EXIT_BAD_ARG)
@@ -86,8 +92,7 @@
             # template is not specified, we use default one
             pass
         if template_path is None:
-            self.host.disp(_("Can't parse template, please check its syntax"),
-                           error=True)
+            self.host.disp(_("Can't parse template, please check its syntax"), error=True)
             self.host.quit(C.EXIT_BAD_ARG)
 
         try:
@@ -104,12 +109,16 @@
             tmp_dir = tempfile.mkdtemp()
             front_url_filter = partial(self._front_url_tmp_dir, tmp_dir=tmp_dir)
             self.renderer = template.Renderer(
-                self.host, front_url_filter=front_url_filter, trusted=True)
+                self.host, front_url_filter=front_url_filter, trusted=True
+            )
             rendered = self._do_render(template_path, css_inline=css_inline, **kwargs)
-            self.host.disp(_(
-                "Browser opening requested.\n"
-                "Temporary files are put in the following directory, you'll have to "
-                "delete it yourself once finished viewing: {}").format(tmp_dir))
+            self.host.disp(
+                _(
+                    "Browser opening requested.\n"
+                    "Temporary files are put in the following directory, you'll have to "
+                    "delete it yourself once finished viewing: {}"
+                ).format(tmp_dir)
+            )
             tmp_file = os.path.join(tmp_dir, template_name)
             with open(tmp_file, "w") as f:
                 f.write(rendered.encode("utf-8"))
@@ -122,6 +131,7 @@
                 # we have to copy static files in a subdirectory, to avoid file download
                 # to be blocked by same origin policy
                 import shutil
+
                 shutil.copytree(
                     static_dir, os.path.join(tmp_dir, theme, C.TEMPLATE_STATIC_DIR)
                 )