CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/scripts/build_sizes/build_sizes.py
Views: 1799
1
#!/usr/bin/env python3
2
'''
3
script to build a html file showing flash free for current builds
4
5
AP_FLAKE8_CLEAN
6
'''
7
8
import os
9
import argparse
10
import fnmatch
11
import json
12
from datetime import datetime
13
14
parser = argparse.ArgumentParser(description='create builds.html for list of builds')
15
parser.add_argument('basedir', default=None, help='base directory (binaries directory)')
16
parser.add_argument('--outfile', default="builds.html", help='output file')
17
18
build_dirs = ['latest', 'beta', 'beta-4.3', 'stable']
19
builds = ['Plane', 'Copter', 'Rover', 'Sub', 'Blimp', 'AntennaTracker', 'AP_Periph']
20
21
args = parser.parse_args()
22
23
warning_flash_free = 5000
24
warning_build_days = 3
25
26
LINUX_BINARIES = ["arduplane", "arducopter", "arducopter-heli", "ardurover", "ardusub", "antennatracker"]
27
28
29
class APJInfo:
30
def __init__(self, vehicle, board, githash, mtime, flash_free):
31
self.vehicle = vehicle
32
self.board = board
33
self.githash = githash
34
self.mtime = mtime
35
self.flash_free = flash_free
36
self.warning = 0
37
38
39
def firmware_list(basedir):
40
'''list of APJInfo for one directory'''
41
boards = []
42
for root, subdirs, files in os.walk(basedir):
43
for f in files:
44
if not fnmatch.fnmatch(f, "*.apj") and f not in LINUX_BINARIES:
45
continue
46
fname = os.path.join(root, f)
47
board = os.path.basename(root)
48
vehicle = fname.split('/')[-4]
49
mtime = os.stat(fname).st_mtime
50
if f in LINUX_BINARIES:
51
git_version = os.path.join(root, "git-version.txt")
52
try:
53
line = open(git_version, 'r').readline()
54
githash = line.split()[1][:8]
55
except OSError:
56
githash = "unknown"
57
flash_free = 999999
58
else:
59
fw_json = json.load(open(fname, "r"))
60
githash = fw_json['git_identity']
61
flash_free = fw_json.get('flash_free', -1)
62
apjinfo = APJInfo(vehicle, board, githash, mtime, flash_free)
63
boards.append(apjinfo)
64
return boards
65
66
67
def write_headers(h):
68
'''write html headers'''
69
h.write('''
70
<!DOCTYPE html>
71
<html>
72
<head>
73
<script src="sorttable.js"></script>
74
<script src="filtertable.js"></script>
75
<link href="../../css/main.css" rel="stylesheet" type="text/css" />
76
<style>
77
td {
78
border-left:1px solid black;
79
border-top:1px solid black;
80
}
81
th {
82
text-align: left;
83
border-left:1px solid black;
84
border-top:1px solid black;
85
}
86
table {
87
border-right:1px solid black;
88
border-bottom:1px solid black;
89
}
90
a {
91
color: inherit;
92
}
93
</style>
94
<title>Build List</title>
95
</head>
96
<body>
97
<div id="main">
98
<a href="https://firmware.ardupilot.org/">
99
<div id="logo" style="text-align:center;">
100
</div>
101
</a>
102
<h2 id='top'>Build List</h2>
103
<p>This is an auto-generated list of current builds
104
allowing us to quickly see how close we are to running out of flash space.
105
<br>This page was most recently regenerated on %s UTC.</p>
106
<p>Builds that are coloured red haven't built recently. Builds that are coloured yellow have low flash space remaining.</p>
107
<p>Click on any column header to sort by that column, or filter by entering a search term in the box above each table.</p>
108
<ul>
109
<li>Jump to <a href='#latest'>latest</a></li>
110
<li>Jump to <a href='#beta'>beta</a></li>
111
<li>Jump to <a href='#beta-4.3'>beta-4.3</a></li>
112
<li>Jump to <a href='#stable'>stable</a></li>
113
</ul>
114
''' % datetime.now().strftime("%F %k:%M"))
115
116
117
def write_footer(h):
118
'''write html footer'''
119
h.write('''
120
</div>
121
</body>
122
</html>
123
''')
124
125
126
def write_table(h, build_type):
127
'''write table for one build type'''
128
boards = []
129
130
for build in builds:
131
boards.extend(firmware_list(os.path.join(args.basedir, build, build_type)))
132
133
max_mtime = 0
134
for apjinfo in boards:
135
if apjinfo.mtime > max_mtime:
136
max_mtime = apjinfo.mtime
137
138
for apjinfo in boards:
139
if apjinfo.flash_free < warning_flash_free and not apjinfo.flash_free == -1:
140
apjinfo.warning = 1
141
if int(apjinfo.mtime) < int(max_mtime)-warning_build_days*86400 and build_type == "latest":
142
apjinfo.warning = 2
143
144
boards.sort(key=lambda board: board.warning, reverse=True)
145
146
try:
147
idxs1 = [i for (i, e) in enumerate(boards) if e.warning == 1]
148
boards[min(idxs1):max(idxs1)] = sorted(boards[min(idxs1):max(idxs1)], key=lambda board: board.flash_free)
149
except ValueError:
150
pass
151
152
try:
153
idxs2 = [i for (i, e) in enumerate(boards) if e.warning == 2]
154
boards[min(idxs2):max(idxs2)] = sorted(boards[min(idxs2):max(idxs2)], key=lambda board: board.mtime)
155
except ValueError:
156
pass
157
158
h.write('''
159
<h3 id='%s'>%s builds</h3>
160
<p><input type="text" id="search_%s" onkeyup="searchFunc('%s')" placeholder="Filter..."></p>
161
<table class="sortable" id="table_%s">
162
<tr><th style="width:90px">Vehicle</th><th style="width:250px">Board</th><th style="width:140px">Build Date</th>
163
<th style="width:100px">git hash</th><th style="width:100px">Flash Free</th></tr>
164
''' % (build_type, build_type.capitalize(), build_type, build_type, build_type))
165
166
for apjinfo in boards:
167
if apjinfo.warning == 1:
168
h.write('<tr style="color:#E6B800;">')
169
elif apjinfo.warning == 2:
170
h.write('<tr style="color:#FF0000;">')
171
else:
172
h.write('<tr>')
173
h.write('''<td>%s</td>
174
<td><a href="https://firmware.ardupilot.org/%s/%s/%s">%s</a></td>
175
<td>%s</td>
176
<td><a href="https://github.com/ArduPilot/ardupilot/commit/%s">%s</a></td>
177
<td>%u</td></tr>\n''' % (
178
apjinfo.vehicle, apjinfo.vehicle, build_type, apjinfo.board, apjinfo.board,
179
datetime.fromtimestamp(apjinfo.mtime).strftime("%F %k:%M"),
180
apjinfo.githash, apjinfo.githash, apjinfo.flash_free))
181
182
h.write('''
183
</table>
184
<p>Return to <a href='#top'>top</a></p>
185
''')
186
187
188
h = open(args.outfile, "w")
189
write_headers(h)
190
for t in build_dirs:
191
write_table(h, t)
192
write_footer(h)
193
194