forked from yt-project/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
111 lines (93 loc) · 2.82 KB
/
generate.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from __future__ import print_function
import yaml
import os
import sys
from jinja2 import Environment, FileSystemLoader
PATH = os.path.dirname(os.path.abspath(__file__))
TEMPLATE_ENVIRONMENT = Environment(
autoescape=False,
loader=FileSystemLoader(os.path.join(PATH, 'templates')),
trim_blocks=False)
try:
import pkg_resources
yt_provider = pkg_resources.get_provider("yt")
yt_path = os.path.dirname(yt_provider.module_path)
if not os.path.exists(os.sep.join([yt_path, '.git'])):
yt_path = None
except ImportError:
yt_path = None
def render_template(template_filename, context):
return TEMPLATE_ENVIRONMENT.get_template(template_filename).render(context)
pages = {}
def page(name, output_name = None):
if output_name is None:
output_name = name + '.html'
def _page(func):
pages[name] = (func, output_name)
return func
return _page
@page('index')
def index():
examples = yaml.load(open("examples.yaml", "r"))
return {'title': 'Home', 'examples': examples}
@page('gallery')
def gallery():
entries = yaml.load(open("gallery.yaml", "r"))
return {'entries': entries}
name_ignores = ["convert-repo"]
def lastname_sort(a):
return a.rsplit(None, 1)[-1]
@page('about')
def about():
# Uncomment for rapid dev
if "--fast" in sys.argv:
return {'developers': []}
import git
if yt_path:
repo = git.Repo(yt_path)
else:
import tempfile
repo_path = tempfile.mkdtemp()
repo = git.Repo.clone_from(
'https://github.com/yt-project/yt', repo_path)
shortlog = repo.git.shortlog('-ns').split('\n')
repo.close()
devs = set([sl.split('\t')[1] for sl in shortlog])
for name in name_ignores:
devs.discard(name)
return {'developers': sorted(devs, key=lastname_sort)}
@page('community')
def community():
return {}
@page('members')
def members():
members = yaml.load(open("members.yaml", "r"))
members.sort(key = lambda a: lastname_sort(a['name']))
return {'members': members}
@page('development')
def development():
return {}
@page('data/index')
def data():
return {'url_prefix':'../'}
@page('extensions')
def extensions():
extensions = yaml.load(open("extensions.yaml", "r"))
return {'extensions': extensions}
@page('slack')
def slack():
return {}
def main():
for name in sorted(pages):
setup_func, template_name = pages[name]
out_name = os.path.join(".", template_name)
context = {'theme': 'flatly', 'title': name,
'url_prefix': ''}
context.update(setup_func())
with open(out_name, "w") as f:
html = render_template(template_name, context)
if sys.version_info.major < 3:
html = html.encode('utf8')
f.write(html)
if __name__ == "__main__":
main()