Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/scripts/build_sizes/build_sizes.py
Views: 1799
#!/usr/bin/env python31'''2script to build a html file showing flash free for current builds34AP_FLAKE8_CLEAN5'''67import os8import argparse9import fnmatch10import json11from datetime import datetime1213parser = argparse.ArgumentParser(description='create builds.html for list of builds')14parser.add_argument('basedir', default=None, help='base directory (binaries directory)')15parser.add_argument('--outfile', default="builds.html", help='output file')1617build_dirs = ['latest', 'beta', 'beta-4.3', 'stable']18builds = ['Plane', 'Copter', 'Rover', 'Sub', 'Blimp', 'AntennaTracker', 'AP_Periph']1920args = parser.parse_args()2122warning_flash_free = 500023warning_build_days = 32425LINUX_BINARIES = ["arduplane", "arducopter", "arducopter-heli", "ardurover", "ardusub", "antennatracker"]262728class APJInfo:29def __init__(self, vehicle, board, githash, mtime, flash_free):30self.vehicle = vehicle31self.board = board32self.githash = githash33self.mtime = mtime34self.flash_free = flash_free35self.warning = 0363738def firmware_list(basedir):39'''list of APJInfo for one directory'''40boards = []41for root, subdirs, files in os.walk(basedir):42for f in files:43if not fnmatch.fnmatch(f, "*.apj") and f not in LINUX_BINARIES:44continue45fname = os.path.join(root, f)46board = os.path.basename(root)47vehicle = fname.split('/')[-4]48mtime = os.stat(fname).st_mtime49if f in LINUX_BINARIES:50git_version = os.path.join(root, "git-version.txt")51try:52line = open(git_version, 'r').readline()53githash = line.split()[1][:8]54except OSError:55githash = "unknown"56flash_free = 99999957else:58fw_json = json.load(open(fname, "r"))59githash = fw_json['git_identity']60flash_free = fw_json.get('flash_free', -1)61apjinfo = APJInfo(vehicle, board, githash, mtime, flash_free)62boards.append(apjinfo)63return boards646566def write_headers(h):67'''write html headers'''68h.write('''69<!DOCTYPE html>70<html>71<head>72<script src="sorttable.js"></script>73<script src="filtertable.js"></script>74<link href="../../css/main.css" rel="stylesheet" type="text/css" />75<style>76td {77border-left:1px solid black;78border-top:1px solid black;79}80th {81text-align: left;82border-left:1px solid black;83border-top:1px solid black;84}85table {86border-right:1px solid black;87border-bottom:1px solid black;88}89a {90color: inherit;91}92</style>93<title>Build List</title>94</head>95<body>96<div id="main">97<a href="https://firmware.ardupilot.org/">98<div id="logo" style="text-align:center;">99</div>100</a>101<h2 id='top'>Build List</h2>102<p>This is an auto-generated list of current builds103allowing us to quickly see how close we are to running out of flash space.104<br>This page was most recently regenerated on %s UTC.</p>105<p>Builds that are coloured red haven't built recently. Builds that are coloured yellow have low flash space remaining.</p>106<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>107<ul>108<li>Jump to <a href='#latest'>latest</a></li>109<li>Jump to <a href='#beta'>beta</a></li>110<li>Jump to <a href='#beta-4.3'>beta-4.3</a></li>111<li>Jump to <a href='#stable'>stable</a></li>112</ul>113''' % datetime.now().strftime("%F %k:%M"))114115116def write_footer(h):117'''write html footer'''118h.write('''119</div>120</body>121</html>122''')123124125def write_table(h, build_type):126'''write table for one build type'''127boards = []128129for build in builds:130boards.extend(firmware_list(os.path.join(args.basedir, build, build_type)))131132max_mtime = 0133for apjinfo in boards:134if apjinfo.mtime > max_mtime:135max_mtime = apjinfo.mtime136137for apjinfo in boards:138if apjinfo.flash_free < warning_flash_free and not apjinfo.flash_free == -1:139apjinfo.warning = 1140if int(apjinfo.mtime) < int(max_mtime)-warning_build_days*86400 and build_type == "latest":141apjinfo.warning = 2142143boards.sort(key=lambda board: board.warning, reverse=True)144145try:146idxs1 = [i for (i, e) in enumerate(boards) if e.warning == 1]147boards[min(idxs1):max(idxs1)] = sorted(boards[min(idxs1):max(idxs1)], key=lambda board: board.flash_free)148except ValueError:149pass150151try:152idxs2 = [i for (i, e) in enumerate(boards) if e.warning == 2]153boards[min(idxs2):max(idxs2)] = sorted(boards[min(idxs2):max(idxs2)], key=lambda board: board.mtime)154except ValueError:155pass156157h.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))164165for apjinfo in boards:166if apjinfo.warning == 1:167h.write('<tr style="color:#E6B800;">')168elif apjinfo.warning == 2:169h.write('<tr style="color:#FF0000;">')170else:171h.write('<tr>')172h.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''' % (177apjinfo.vehicle, apjinfo.vehicle, build_type, apjinfo.board, apjinfo.board,178datetime.fromtimestamp(apjinfo.mtime).strftime("%F %k:%M"),179apjinfo.githash, apjinfo.githash, apjinfo.flash_free))180181h.write('''182</table>183<p>Return to <a href='#top'>top</a></p>184''')185186187h = open(args.outfile, "w")188write_headers(h)189for t in build_dirs:190write_table(h, t)191write_footer(h)192193194