Reformatted code base using black.
This commit is contained in:
parent
56319cbad3
commit
53fdaa9d09
1 changed files with 12604 additions and 8966 deletions
|
|
@ -43,15 +43,19 @@ class Template(object):
|
|||
|
||||
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 @@ class Template(object):
|
|||
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 @@ class Template(object):
|
|||
# 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 @@ class Template(object):
|
|||
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 @@ class Template(object):
|
|||
# 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)
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue