-
Notifications
You must be signed in to change notification settings - Fork 0
/
boards.py
192 lines (156 loc) · 6.42 KB
/
boards.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env python3
import yaml
import glob
import os
import json
from bs4 import BeautifulSoup
import lxml
board_root = "boards"
boards = []
BOARD_HTML = """
<figure class="grid__brick mt-3 col-6 col-md-4 col-xl-3 picture-item figure" data-groups='["{arch}"]' data-date-created="2016-08-12"
data-title="{name}">
<div class="aspect aspect--16x9">
<div class="aspect__inner">
<img class="figure-img img-fluid rounded"
src="_images/{image}"
alt="{name}"/>
</div>
</div>
<figcaption class="picture-item__title figure-caption"><h4><a href="https://docs.zephyrproject.org/latest/boards/{arch}/{identifier}/doc/index.html">{name}</a></h4>
<p>{intro}</p>
</figcaption>
</figure>
"""
BOARD_HTML2 = """
<figure class="grid__brick mt-3 col-6 col-md-4 col-xl-3 picture-item figure" data-groups='["{arch}"]' data-date-created="2016-08-12"
data-title="{name}">
<div class="aspect aspect--16x9">
<div class="aspect__inner">
</div>
</div>
<figcaption class="picture-item__title figure-caption"><h4><a href="https://docs.zephyrproject.org/latest/boards/{arch}/{identifier}/doc/index.html">{name}</a></h4>
<p>{intro}</p>
</figcaption>
</figure>
"""
output = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Boards</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<link rel="stylesheet" href="css/shuffle.css" >
<link rel="stylesheet" href="css/zephyr.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Shuffle/5.2.1/shuffle.js" language="JavaScript">
</script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/json2html/1.2.0/json2html.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.json2html/1.2.0/jquery.json2html.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Zephyr Boards</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2 filter__search js-shuffle-search" type="search" placeholder="Search"
aria-label="Search">
</form>
</div>
</nav>
<main role="main" id="main">
<style>
/* Allow bootstrap grid elements to fit on mobile */
@media (max-width: 575px) {
.row > [class*="col-"] {
padding-left: 8px;
padding-right: 8px;
}
}
</style>
<div class="container">
<div class="row">
<div class="col-12@sm filters-group-wrap">
<div class="filters-group">
<p class="filter-label">Filter</p>
<div class="btn-group filter-options">
<button class="btn btn--primary" data-group="all">All</button>
<button class="btn btn--primary" data-group="arm">ARM</button>
<button class="btn btn--primary" data-group="x86">X86</button>
<button class="btn btn--primary" data-group="arc">ARC</button>
<button class="btn btn--primary" data-group="riscv32">RISCV32</button>
<button class="btn btn--primary" data-group="xtensa">Xtensa</button>
<button class="btn btn--primary" data-group="nios2">NIOS-II</button>
<button class="btn btn--primary" data-group="posix">Posix</button>
</div>
</div>
<fieldset class="filters-group">
<legend class="filter-label">Sort</legend>
<div class="btn-group sort-options">
<label class="btn active">
<input type="radio" name="sort-value" value="dom" /> Default
</label>
<label class="btn">
<input type="radio" name="sort-value" value="title" /> Title
</label>
<label class="btn">
<input type="radio" name="sort-value" value="date-created" /> Date Created
</label>
</div>
</fieldset>
</div>
</div>
</div>
<div class="container mb-4" style="margin-top: 30px;">
<div id="grid" class="row my-shuffle-container">
"""
for fn in glob.glob(os.path.join(board_root, "*", "*", "*.yaml")):
with open(fn, 'r') as f:
board = yaml.safe_load(f)
ff = fn.split("/")
bpath = "/".join(ff[0:3])
dir_name = ff[-2]
html_file = os.path.join("./doc/_build/html/" + bpath + "/doc/index.html")
if board['identifier'] != dir_name:
print("skipping {}".format(fn))
continue
else:
print("working on {}".format(fn))
if os.path.exists(html_file):
with open (html_file, "r") as myfile:
data=myfile.read()
soup = BeautifulSoup(data, 'lxml')
intro = soup.find('p').text
board['intro'] = intro
image_p = "doc/_build/html/_images/{}".format(board['identifier'])
if os.path.exists(image_p + ".png"):
image_file = "{}.png".format(board['identifier'])
output += BOARD_HTML.format(name=board['name'],arch=board['arch'],intro=intro, image=image_file, identifier=board['identifier'])
elif os.path.exists(image_p + ".jpg"):
image_file = "{}.jpg".format(board['identifier'])
output += BOARD_HTML.format(name=board['name'],arch=board['arch'],intro=intro, image=image_file,identifier=board['identifier'])
else:
output += BOARD_HTML2.format(name=board['name'],arch=board['arch'],intro=intro, identifier=board['identifier'])
boards.append(board)
with open('boards.json', 'w') as outfile:
json.dump(boards, outfile)
output += """
</div>
<div class="col-3 my-sizer-element"></div>
</div>
</main>
<script language="JavaScript" src="js/boards.js"></script>
</body>
</html>
"""
with open("output.html", 'w') as outfile:
outfile.write(output)