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/PrintVersion.py
Views: 1798
#!/usr/bin/env python12"""3Extract version information for the various vehicle types, print it45AP_FLAKE8_CLEAN67"""89import os10import re11import sys1213from optparse import OptionParser1415parser = OptionParser("print_version.py [options] ArduCopter|ArduPlane|Rover|AntennaTracker")1617(opts, args) = parser.parse_args()1819includefiles = {20"ArduCopter": "version.h",21"ArduPlane": "version.h",22"Rover": "version.h",23"AntennaTracker": "version.h",24"ArduSub": "version.h",25}2627if len(args) > 0:28vehicle = args[0]29if vehicle not in includefiles:30print("Unknown vehicle (%s) (be in a vehicle directory or supply a vehicle type as an argument)" % (vehicle,))31sys.exit(1)32includefilepath = "%s/%s" % (vehicle, includefiles[vehicle])33else:34# assume we are in e.g. APM/Rover/35vehicle = os.path.basename(os.getcwd())36if vehicle not in includefiles:37print("Unknown vehicle (%s) (be in a vehicle directory or supply a vehicle type as an argument)" % (vehicle,))38sys.exit(1)39includefilepath = includefiles[vehicle]404142file = open(includefilepath)4344firmware_version_regex = re.compile(r".*define +FIRMWARE_VERSION.*")45firmware_version_extract_regex = re.compile(r".*define +FIRMWARE_VERSION[ ]+(?P<major>\d+)[ ]*,[ ]*(?P<minor>\d+)[ ]*,[ ]*(?P<point>\d+)[ ]*,[ ]*(?P<type>[A-Z_]+)[ ]*") # noqa: E5014647for line in file:48if not firmware_version_regex.match(line):49continue50match = firmware_version_extract_regex.match(line)51if not match:52print("Failed to match FIRMWARE_VERSION line (%s)" % (line,))53sys.exit(1)54print("%d.%d.%d-%s" % (int(match.group("major")),55int(match.group("minor")),56int(match.group("point")),57match.group("type")))585960