From 7e2b010458f3e48180444bb4a23f9b73f3281249 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 30 Dec 2021 16:28:49 +1100 Subject: [PATCH] Tools: a script to list builds with flash free example: https://firmware.ardupilot.org/Tools/BuildSizes/builds.html Pair programmed with MichelleR --- Tools/scripts/build_sizes.py | 123 +++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100755 Tools/scripts/build_sizes.py diff --git a/Tools/scripts/build_sizes.py b/Tools/scripts/build_sizes.py new file mode 100755 index 0000000000..fbc11ed4e0 --- /dev/null +++ b/Tools/scripts/build_sizes.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 +''' +script to build a html file showing flash free for current builds + +AP_FLAKE8_CLEAN +''' + +import os +import argparse +import fnmatch +import json +from datetime import datetime + +parser = argparse.ArgumentParser(description='create builds.html for list of builds') +parser.add_argument('basedir', default=None, help='base directory (binaries directory)') +parser.add_argument('--outfile', default="builds.html", help='output file') + +build_dirs = ['latest', 'beta', 'stable'] +builds = ['Plane', 'Copter', 'Rover', 'Sub', 'Blimp', 'AP_Periph'] + +args = parser.parse_args() + + +class APJInfo: + def __init__(self, vehicle, board, githash, mtime, flash_free): + self.vehicle = vehicle + self.board = board + self.githash = githash + self.mtime = mtime + self.flash_free = flash_free + + +def apj_list(basedir): + '''list of APJInfo for one directory''' + boards = [] + for root, subdirs, files in os.walk(basedir): + for f in files: + if not fnmatch.fnmatch(f, "*.apj"): + continue + fname = os.path.join(root, f) + board = os.path.basename(root) + vehicle = fname.split('/')[-4] + fw_json = json.load(open(fname, "r")) + githash = fw_json['git_identity'] + flash_free = fw_json.get('flash_free', -1) + mtime = os.stat(fname).st_mtime + apjinfo = APJInfo(vehicle, board, githash, mtime, flash_free) + boards.append(apjinfo) + return boards + + +def write_headers(h): + '''write html headers''' + h.write(''' + + + + + +Build List + + +

Build list

+This is an auto-generated list of current builds allowing us to quickly see how close we are to running out of flash space + +''') + + +def write_footer(h): + '''write html footer''' + h.write(''' + + +''') + + +def write_table(h, build_type): + '''write table for one build type''' + boards = [] + + for build in builds: + boards.extend(apj_list(os.path.join(args.basedir, build, build_type))) + + h.write(''' +

%s builds

+ + +''' % (build_type, build_type)) + + for apjinfo in boards: + h.write(''' + \n''' % ( + apjinfo.vehicle, apjinfo.board, datetime.fromtimestamp(apjinfo.mtime).strftime("%F %k:%M"), + apjinfo.githash, apjinfo.githash, apjinfo.flash_free)) + + h.write(''' +
VehicleBoardBuild Dategit hashFlash Free
%s%s%s%s%u
+''') + + +h = open(args.outfile, "w") +write_headers(h) +for t in build_dirs: + write_table(h, t) +write_footer(h)