Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/scripts/check_firmware_version.py
9386 views
1
#!/usr/bin/env python3
2
3
# flake8: noqa
4
5
'''
6
check firmware-version.txt in binaries directory
7
'''
8
9
import os
10
11
VEHICLES = ['AntennaTracker', 'Copter', 'Plane', 'Rover', 'Sub']
12
13
def parse_git_version(gfile):
14
'''parse git-version.txt, producing a firmware-version.txt'''
15
gv = open(gfile).readlines()
16
vline = gv[-1]
17
if not vline.startswith("APMVERSION:"):
18
print("Bad version %s in %s" % (vline, gfile))
19
return None
20
vline = vline[11:]
21
a = vline.split('V')
22
if len(a) != 2:
23
return None
24
vers = a[1].strip()
25
if vers[-1].isdigit():
26
return vers+"-FIRMWARE_VERSION_TYPE_OFFICIAL"
27
print("Bad vers %s in %s" % (vers, gfile))
28
return None
29
30
def check_fw_version(version):
31
try:
32
(version_numbers, release_type) = version.split("-")
33
(_, _, _) = version_numbers.split(".")
34
except Exception:
35
return False
36
return True
37
38
def check_version(vehicle):
39
'''check firmware-version.txt version for a vehicle'''
40
for d in os.listdir(vehicle):
41
if not d.startswith("stable"):
42
continue
43
stable_dir = '%s/%s' % (vehicle, d)
44
for b in sorted(os.listdir(stable_dir)):
45
if not os.path.isdir(os.path.join(stable_dir, b)):
46
continue
47
vfile = os.path.join(stable_dir, b, "firmware-version.txt")
48
if os.path.exists(vfile):
49
v = open(vfile).read()
50
if check_fw_version(v):
51
continue
52
gfile = os.path.join(stable_dir, b, "git-version.txt")
53
if not os.path.exists(gfile):
54
print("Missing %s" % gfile)
55
continue
56
v = parse_git_version(gfile)
57
if v is not None:
58
open(vfile, "w").write(v)
59
print("Added %s" % vfile)
60
continue
61
print("Failed for %s" % gfile)
62
63
if __name__ == "__main__":
64
import argparse
65
parser = argparse.ArgumentParser(description='check_firmware_version.py')
66
67
args = parser.parse_args()
68
69
for v in VEHICLES:
70
check_version(v)
71
72