本文整理汇总了Python中jinja2.Template.stream方法的典型用法代码示例。如果您正苦于以下问题:Python Template.stream方法的具体用法?Python Template.stream怎么用?Python Template.stream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jinja2.Template
的用法示例。
在下文中一共展示了Template.stream方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from jinja2 import Template [as 别名]
# 或者: from jinja2.Template import stream [as 别名]
def main():
parser = argparse.ArgumentParser(description='Parser for Teacon')
parser.add_argument('period', help='period (period of teacon)')
parser.add_argument('seq', help='seq (week of teacon)')
parser.add_argument('input', help='path of tsv')
parser.add_argument('output', help='path of html')
args = parser.parse_args()
period = args.period
seq = args.seq
input_file = args.input
output_file = args.output
tsv = csv.reader(open(input_file, 'r', encoding='utf-8'), delimiter='\t')
headers = next(tsv)
players = []
for row in tsv:
player = {}
player['eno'] = row[0]
player['d04_eno'] = row[0].zfill(4)
row.pop(0)
player['data'] = row
players.append(player)
template = Template(open('template/report.html', 'r', encoding='utf-8').read())
template.stream(period=period, seq=seq, headers=headers, players=players).dump(output_file)
示例2: create_conf
# 需要导入模块: from jinja2 import Template [as 别名]
# 或者: from jinja2.Template import stream [as 别名]
def create_conf():
# Ask serf-agent for members.
client = SerfClient()
members = client.connection.call('members').body['Members']
servers = [member_to_server(member) for member in members]
owncloud_servers = [s for s in servers if s['role'] == 'owncloud']
# if ownclouds not changed return false ?
# Create new config with found members.
with open(HA_CFG_TEMPL, 'r') as file:
template = Template(file.read())
template.stream(servers=owncloud_servers).dump(HA_CFG)
示例3: place_file
# 需要导入模块: from jinja2 import Template [as 别名]
# 或者: from jinja2.Template import stream [as 别名]
def place_file(path, source_file, context={}):
yield 'STRING cat > {} <<"EOF"'.format(path)
yield 'ENTER'
with open(source_file) as fh:
template = Template(fh.read())
for block in template.stream(**context):
for line in block.split('\n'):
if line:
yield 'STRING {}'.format(line)
yield 'ENTER'
yield 'STRING EOF'
yield 'ENTER'
示例4: dirname
# 需要导入模块: from jinja2 import Template [as 别名]
# 或者: from jinja2.Template import stream [as 别名]
if __name__ == '__main__':
args = parser.parse_args()
cur_path = dirname(abspath(__file__))
if args.gpio:
gpio = read_gpio(args.gpio)
else:
gpio_file = get_gpio_file(args.project, args.mx)
gpio = read_gpio(gpio_file)
proj = read_project(gpio, args.project)
defines = gen_defines(proj)
ports = gen_ports(gpio, proj)
with open(cur_path + '/templates/board_gpio.tpl', 'r') as tpl_file:
tpl = tpl_file.read()
template = Template(tpl)
defines_sorted = []
for d in sorted(defines.keys()):
defines_sorted.append((d, defines[d]))
ports_sorted = []
for p in sorted(ports.keys()):
ports_sorted.append((p, ports[p]))
template.stream(defines=defines_sorted, ports=ports_sorted).dump(args.output)
print('File generated at ' + args.output)
示例5: make_template_stream
# 需要导入模块: from jinja2 import Template [as 别名]
# 或者: from jinja2.Template import stream [as 别名]
def make_template_stream(self):
template_obj = self.env.get_template("overview.templ")
ads = serialize.AnalysisDeserializer(
self.database_connection._original_connection,
analysis_id=self.analysis_id)
self.glycan_chromatograms = gcs = ads.load_glycan_composition_chromatograms()
# und = ads.load_unidentified_chromatograms()
self.unidentified_chromatograms = und = ChromatogramFilter(
ads.query(serialize.UnidentifiedChromatogram).filter(
serialize.UnidentifiedChromatogram.analysis_id == self.analysis_id).all())
if len(gcs) == 0:
self.log("No glycan compositions were identified. Skipping report building")
templ = Template('''
<html>
<style>
body {
font-family: sans-serif;
}
</style>
<body>
<h3>No glycan compositions were identified</h3>
</body>
</html>
''')
return templ.stream()
summary_plot = summaries.GlycanChromatographySummaryGraphBuilder(
filter(lambda x: x.score > self.threshold, gcs + und))
lcms_plot, composition_abundance_plot = summary_plot.draw(min_score=5)
try:
lcms_plot.ax.legend_.set_visible(False)
except AttributeError:
# The legend may not have been created
pass
lcms_plot.ax.set_title("Glycan Composition\nLC-MS Aggregated EICs", fontsize=24)
fig = lcms_plot.ax.figure
fig.set_figwidth(fig.get_figwidth() * 2.)
fig.set_figheight(fig.get_figheight() * 2.)
composition_abundance_plot.ax.set_title("Glycan Composition\nTotal Abundances", fontsize=24)
composition_abundance_plot.ax.set_xlabel(
composition_abundance_plot.ax.get_xlabel(), fontsize=14)
def resolve_key(key):
match = gcs.find_key(key)
if match is None:
match = und.find_key(key)
return match
template_stream = (template_obj.stream(
analysis=ads.analysis, lcms_plot=svguri_plot(
lcms_plot.ax, bbox_inches='tight', patchless=True,
svg_width="100%"),
composition_abundance_plot=svguri_plot(
composition_abundance_plot.ax, bbox_inches='tight', patchless=True,
svg_width="100%"),
glycan_chromatograms=gcs,
unidentified_chromatograms=und,
resolve_key=resolve_key
))
return template_stream
示例6: Template
# 需要导入模块: from jinja2 import Template [as 别名]
# 或者: from jinja2.Template import stream [as 别名]
from jinja2 import Template
template_str = 'first={{first}}\n' \
'last={{last}}'
template = Template(template_str)
stream = template.stream({'first': 'John', 'last': 'Doe'})
count = 0
while True:
try:
count += 1
resolved = stream.next()
print count, resolved
except StopIteration:
break
generator = template.generate({'first': 'John', 'last': 'Doe'})
count = 0
for s in generator:
count += 1
print count, s
示例7: prev
# 需要导入模块: from jinja2 import Template [as 别名]
# 或者: from jinja2.Template import stream [as 别名]
# Generate rows for HTML template
rows = []
prev_record = None
for record in records:
def prev(key):
if prev_record and record[key] != prev_record[key]:
return prev_record[key]
else:
return None
rows.append({
'date': record['date'],
'pkgver': record['pkgver'],
'openslide_prev': prev('openslide'),
'openslide_cur': record['openslide'],
'java_prev': prev('openslide-java'),
'java_cur': record['openslide-java'],
'winbuild_prev': prev('openslide-winbuild'),
'winbuild_cur': record['openslide-winbuild'],
})
prev_record = record
# Write HTML
with atomic_update(os.path.join(basedir, HTML)) as fh:
template.stream({
'rows': reversed(rows),
}).dump(fh)
# Write records to JSON
with atomic_update(os.path.join(basedir, JSON)) as fh:
json.dump(records, fh, indent=2, sort_keys=True)