CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

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