Mercurial > libervia-backend
diff sat_frontends/jp/output_template.py @ 2624:56f94936df1e
code style reformatting using black
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 27 Jun 2018 20:14:46 +0200 |
parents | 26edcf3a30eb |
children | 0fa217fafabf |
line wrap: on
line diff
--- a/sat_frontends/jp/output_template.py Wed Jun 27 07:51:29 2018 +0200 +++ b/sat_frontends/jp/output_template.py Wed Jun 27 20:14:46 2018 +0200 @@ -27,8 +27,8 @@ import os.path __outputs__ = ["Template"] -TEMPLATE = u'template' -OPTIONS = {u'template', u'browser', u'inline-css'} +TEMPLATE = u"template" +OPTIONS = {u"template", u"browser", u"inline-css"} class Template(object): @@ -49,28 +49,29 @@ data to a dict usable by the template. """ # media_dir is needed for the template - self.host.media_dir = self.host.bridge.getConfig('', 'media_dir') + self.host.media_dir = self.host.bridge.getConfig("", "media_dir") cmd = self.host.command try: template_path = cmd.TEMPLATE except AttributeError: - if not 'template' in cmd.args.output_opts: - self.host.disp(u'no default template set for this command, ' - u'you need to specify a template using --oo template=[path/to/template.html]', - error=True) + if not "template" in cmd.args.output_opts: + self.host.disp( + u"no default template set for this command, " + u"you need to specify a template using --oo template=[path/to/template.html]", + error=True, + ) self.host.quit(C.EXIT_BAD_ARG) options = self.host.parse_output_options() self.host.check_output_options(OPTIONS, options) self.renderer = template.Renderer(self.host) try: - template_path = options['template'] + template_path = options["template"] except KeyError: # template is not specified, we use default one pass if template_path is None: - self.host.disp(u"Can't parse template, please check its syntax", - error=True) + self.host.disp(u"Can't parse template, please check its syntax", error=True) self.host.quit(C.EXIT_BAD_ARG) try: @@ -80,22 +81,29 @@ else: kwargs = mapping_cb(data) - css_inline = u'inline-css' in options + css_inline = u"inline-css" in options rendered = self.renderer.render(template_path, css_inline=css_inline, **kwargs) - if 'browser' in options: + if "browser" in options: template_name = os.path.basename(template_path) tmp_dir = tempfile.mkdtemp() - self.host.disp(_(u"Browser opening requested.\nTemporary files are put in the following directory, " - u"you'll have to delete it yourself once finished viewing: {}").format(tmp_dir)) + self.host.disp( + _( + u"Browser opening requested.\nTemporary files are put in the following directory, " + u"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')) + with open(tmp_file, "w") as f: + f.write(rendered.encode("utf-8")) theme, theme_root_path = self.renderer.getThemeAndRoot(template_path) static_dir = os.path.join(theme_root_path, C.TEMPLATE_STATIC_DIR) if os.path.exists(static_dir): import shutil - shutil.copytree(static_dir, os.path.join(tmp_dir, theme, C.TEMPLATE_STATIC_DIR)) + + shutil.copytree( + static_dir, os.path.join(tmp_dir, theme, C.TEMPLATE_STATIC_DIR) + ) webbrowser.open(tmp_file) else: self.host.disp(rendered)