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/gen_stable.py
Views: 1798
1
#!/usr/bin/env python
2
'''
3
create stable-x.y.z directories so we keep all past stable releases for users to download
4
'''
5
6
import os
7
import shutil
8
9
VEHICLES = ['AntennaTracker', 'Copter', 'Plane', 'Rover', 'Sub']
10
11
# beta directories that may contain stable builds
12
BETA_DIRS = ['beta-4.3']
13
14
def make_stable(basedir, vehicle):
15
'''make stable version for a vehicle'''
16
stable_dir = os.path.join(basedir, vehicle, 'stable')
17
if not os.path.exists(stable_dir):
18
print("Missing %s" % stable_dir)
19
return
20
for b in sorted(os.listdir(stable_dir)):
21
if not os.path.isdir(os.path.join(stable_dir, b)):
22
continue
23
vfile = os.path.join(stable_dir, b, "firmware-version.txt")
24
if not os.path.exists(vfile):
25
print("Missing %s" % vfile)
26
continue
27
vstr = open(vfile).read()
28
version = vstr.split('-')[0]
29
new_dir_parent = os.path.join(basedir, vehicle, 'stable-%s' % version)
30
new_dir = os.path.join(new_dir_parent, b)
31
if os.path.exists(new_dir):
32
continue
33
if not os.path.exists(new_dir_parent):
34
os.mkdir(new_dir_parent)
35
print('Creating %s' % new_dir)
36
old_dir = os.path.join(stable_dir, b)
37
shutil.copytree(old_dir, new_dir)
38
39
def make_stable_from_beta(basedir, vehicle, beta_dir):
40
'''make stable version from a beta with OFFICAL tag'''
41
beta_dir = os.path.join(basedir, vehicle, beta_dir)
42
if not os.path.exists(beta_dir):
43
return
44
for b in sorted(os.listdir(beta_dir)):
45
if not os.path.isdir(os.path.join(beta_dir, b)):
46
continue
47
vfile = os.path.join(beta_dir, b, "firmware-version.txt")
48
if not os.path.exists(vfile):
49
print("Missing %s" % vfile)
50
continue
51
vstr = open(vfile).read().strip()
52
a = vstr.split('-')
53
if len(a) != 2:
54
continue
55
version = a[0]
56
vtype = a[1]
57
#print(vfile, b, version, vtype)
58
if vtype != 'FIRMWARE_VERSION_TYPE_OFFICIAL':
59
# not a new stable
60
continue
61
new_dir_parent = os.path.join(basedir, vehicle, 'stable-%s' % version)
62
new_dir = os.path.join(new_dir_parent, b)
63
if os.path.exists(new_dir):
64
continue
65
if not os.path.exists(new_dir_parent):
66
os.mkdir(new_dir_parent)
67
print('Creating %s' % new_dir)
68
old_dir = os.path.join(beta_dir, b)
69
shutil.copytree(old_dir, new_dir)
70
71
72
def make_all_stable(basedir):
73
'''make stable directory for all vehicles'''
74
for v in VEHICLES:
75
make_stable(basedir, v)
76
for b in BETA_DIRS:
77
make_stable_from_beta(basedir, v, b)
78
79
80
if __name__ == "__main__":
81
import argparse
82
parser = argparse.ArgumentParser(description='gen_stable.py')
83
parser.add_argument('basedir', type=str, default="-", help='base binaries directory')
84
args = parser.parse_args()
85
86
make_all_stable(args.basedir)
87
88