File: make_lab_templates.py

package info (click to toggle)
pyroute2 0.8.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,704 kB
  • sloc: python: 50,245; makefile: 280; javascript: 183; ansic: 81; sh: 44; awk: 17
file content (39 lines) | stat: -rwxr-xr-x 1,223 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python

import pathlib
import sys

from docutils.core import publish_parts
from jinja2 import Environment, FileSystemLoader

env = Environment(loader=FileSystemLoader('lab/_templates/'))
# js template
template = env.get_template('conf.js')
with open('lab/_static/conf.js', 'w') as f:
    f.write(template.render(distfile=sys.argv[1]))
    print('created lab/_static/conf.js')

# html template
template = env.get_template('form_template.html')
root = pathlib.Path('examples/lab')
for example in root.iterdir():
    if not example.is_dir():
        continue
    readme = publish_parts(
        example.joinpath('README.rst').read_text(), writer_name='html'
    )['html_body']
    setup = example.joinpath('setup.py').read_text()
    task = example.joinpath('task.py').read_text()
    check = ''
    with example.joinpath('check.py').open('r') as f:
        for line in f.readlines():
            if 'import' not in line:
                check += line
    name = example.name
    with open(f'lab/{name}.html', 'w') as f:
        f.write(
            template.render(
                readme=readme, setup=setup, task=task, check=check, name=name
            )
        )
        print(f'created lab/{name}.html')