当前位置: 首页>>代码示例>>Python>>正文


Python Template.stream方法代码示例

本文整理汇总了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)
开发者ID:heriet,项目名称:teacon-script,代码行数:34,代码来源:render_report.py

示例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)
开发者ID:inthecloud247,项目名称:docker_base_files,代码行数:15,代码来源:haproxy_helper.py

示例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'
开发者ID:thusoy,项目名称:ducky-scripts,代码行数:14,代码来源:bootstrap_raspberrypi.py

示例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)
开发者ID:dismirlian,项目名称:ChibiOS-Contrib,代码行数:31,代码来源:mx2board.py

示例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
开发者ID:mobiusklein,项目名称:glycan_profiling,代码行数:68,代码来源:render.py

示例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
开发者ID:manasdk,项目名称:py-learn,代码行数:24,代码来源:streaming_template.py

示例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)
开发者ID:openslide,项目名称:openslide-automation,代码行数:32,代码来源:winbuild-index.py


注:本文中的jinja2.Template.stream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。