Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/scripts/build_sizes/build_sizes.py
9640 views
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', '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='#stable'>stable</a></li>
112
</ul>
113
''' % datetime.now().strftime("%F %k:%M"))
114
115
116
def write_footer(h):
117
'''write html footer'''
118
h.write('''
119
</div>
120
</body>
121
</html>
122
''')
123
124
125
def write_table(h, build_type):
126
'''write table for one build type'''
127
boards = []
128
129
for build in builds:
130
boards.extend(firmware_list(os.path.join(args.basedir, build, build_type)))
131
132
max_mtime = 0
133
for apjinfo in boards:
134
if apjinfo.mtime > max_mtime:
135
max_mtime = apjinfo.mtime
136
137
for apjinfo in boards:
138
if apjinfo.flash_free < warning_flash_free and not apjinfo.flash_free == -1:
139
apjinfo.warning = 1
140
if int(apjinfo.mtime) < int(max_mtime)-warning_build_days*86400 and build_type == "latest":
141
apjinfo.warning = 2
142
143
boards.sort(key=lambda board: board.warning, reverse=True)
144
145
try:
146
idxs1 = [i for (i, e) in enumerate(boards) if e.warning == 1]
147
boards[min(idxs1):max(idxs1)] = sorted(boards[min(idxs1):max(idxs1)], key=lambda board: board.flash_free)
148
except ValueError:
149
pass
150
151
try:
152
idxs2 = [i for (i, e) in enumerate(boards) if e.warning == 2]
153
boards[min(idxs2):max(idxs2)] = sorted(boards[min(idxs2):max(idxs2)], key=lambda board: board.mtime)
154
except ValueError:
155
pass
156
157
h.write('''
158
<h3 id='%s'>%s builds</h3>
159
<p><input type="text" id="search_%s" onkeyup="searchFunc('%s')" placeholder="Filter..."></p>
160
<table class="sortable" id="table_%s">
161
<tr><th style="width:90px">Vehicle</th><th style="width:250px">Board</th><th style="width:140px">Build Date</th>
162
<th style="width:100px">git hash</th><th style="width:100px">Flash Free</th></tr>
163
''' % (build_type, build_type.capitalize(), build_type, build_type, build_type))
164
165
for apjinfo in boards:
166
if apjinfo.warning == 1:
167
h.write('<tr style="color:#E6B800;">')
168
elif apjinfo.warning == 2:
169
h.write('<tr style="color:#FF0000;">')
170
else:
171
h.write('<tr>')
172
h.write('''<td>%s</td>
173
<td><a href="https://firmware.ardupilot.org/%s/%s/%s">%s</a></td>
174
<td>%s</td>
175
<td><a href="https://github.com/ArduPilot/ardupilot/commit/%s">%s</a></td>
176
<td>%u</td></tr>\n''' % (
177
apjinfo.vehicle, apjinfo.vehicle, build_type, apjinfo.board, apjinfo.board,
178
datetime.fromtimestamp(apjinfo.mtime).strftime("%F %k:%M"),
179
apjinfo.githash, apjinfo.githash, apjinfo.flash_free))
180
181
h.write('''
182
</table>
183
<p>Return to <a href='#top'>top</a></p>
184
''')
185
186
187
h = open(args.outfile, "w")
188
write_headers(h)
189
for t in build_dirs:
190
write_table(h, t)
191
write_footer(h)
192
193