當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。