def main(args): data = open(args.template_directory + "/methods.json").read() json_data = json.loads(data) header = Template(open(args.template_directory + "/header.tpl").read(), escape=None) body = Template(open(args.template_directory + "/body.tpl").read(), escape=None) body_func = Template(open(args.template_directory + "/body_func.tpl").read(), escape=None) footer = Template(open(args.template_directory + "/footer.tpl").read(), escape=None) source = gen_extmethod(json_data, header, body, body_func, footer) args.cpp.write(source)
def render(gens, tmpl_dir, output_dir, mtime): license = open("%s%s" % (tmpl_dir, 'license.txt')).read() warn = open("%s%s" % (tmpl_dir, 'warn.txt')).read() prev_output_fn = gens[0][1] prev_output = "" count = (len(gens)-1) for c, (tmpl_fn, output_fn, data) in enumerate(gens): # Concat the rendered template into output_fn const_file = Template(open("%s%s" % (tmpl_dir, "traits.const.tpl")).read(), escape=None) const_file = const_file(data=data) array_file = Template(open("%s%s" % (tmpl_dir, "traits.array.tpl")).read(), escape=None) array_file = array_file(data=data) t_tmpl = Template(open("%s%s" % (tmpl_dir, tmpl_fn)).read(), escape=None) t_tmpl = t_tmpl( tmpl_dir=tmpl_dir, license=license, warn=warn, const_file=const_file, array_file=array_file, data=data ) last = count == c if (output_fn != prev_output_fn ): with open(output_dir + prev_output_fn, 'w') as f: f.write( str(prev_output) ) f.close() set_timestamp(f.name, (mtime,mtime)) prev_output = "" prev_output += str(t_tmpl) if last: with open(output_dir + output_fn, 'w') as f: f.write(str(prev_output)) f.close() set_timestamp(f.name, (mtime,mtime)) prev_output_fn = output_fn
def __call__(self, request): if request.user is None: error = "Please login to access the requested page." request.session["loginerror"] = error request.session["full_path"] = request.full_path raise HttpFound("/login") if self.level not in request.user.access: return dict(content="Access Denied", content_type="text/plain") self.data["request"] = request filename = settings.PYRATEMP_PATH + self.name content = Template(filename=filename)(**self.data) return {"content": content}
def template(name, **substitutions): """Load template from resources Arguments: name {str} -- template name Returns: str """ from importlib_resources import read_text from pyratemp import Template from . import templates return Template(read_text(templates, name))(**substitutions, f={ 'parse_host': parse_host, 'is_port_open': is_port_open })
def format_output(output): for trace in output: for i in xrange(len(trace['data'])): x, snapshot = trace['data'][i] if len(snapshot) == 4: cpu, mem, io, stack = snapshot stack.reverse() snapshot = cpu, mem, io, stack, colours(stack) trace['data'][i] = (x, snapshot) data = { 'traces': output, 'palette': ['#%x' % c for c in current_palette()] } t = Template(filename='report-template.html', data=data) html = u'%s' % t max_length = max(o['data'][-1][0] for o in output) if len(output) else 0 json = dumps(output) html = html % (json, max_length) return (json, expand_scripts(html).encode('utf-8'))
def main(self, template_file: ExistingFile, *var_files: ExistingFile): warn_shebangs(template_file) data = {} # {var: value} var_mentions = defaultdict(list) # {var: [files]} for vfile in var_files: loader = jloads if vfile.suffix.lower() == '.json' else yloads new_data = loader(vfile.read()) for v in new_data: var_mentions[v].append(vfile) data.update(new_data) warn_overrides(var_mentions) rstr = Template(filename=str(template_file), data=data)() dest = template_file.with_suffix('') if not self.overwrite: try: NonexistentPath(dest) except ValueError as e: err(f"{type(e)}: {e}") err("Use -f/--force to overwrite") sys.exit(1) dest.write(rstr)
def wrapper(request, **kwargs): data = func(request, **kwargs) data["request"] = request content = Template(filename=settings.PYRATEMP_PATH + name)(**data) return dict(content=content, *kw)
def __call__(self, request): self.data["request"] = request filename = settings.PYRATEMP_PATH + self.name content = Template(filename=filename)(**self.data) return {"content": content}