-
Notifications
You must be signed in to change notification settings - Fork 79
/
run_setup.py
executable file
·110 lines (89 loc) · 3.34 KB
/
run_setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python
'''
*******************************************************
Copyright (c) MLRS project
GPL3
https://www.gnu.org/licenses/gpl-3.0.de.html
OlliW @ www.olliw.eu
*******************************************************
run_setup.py
1. run git submodule update --init --recursive
2. calls run_copy_st_drivers.py to populate the target ST Driver folders
3. calls fmav_generate_c_library.py to generate MAVLink library files
4. calls dronecan_generate_c_library.py to generate DroneCAN library files
version 31.10.2024
********************************************************
'''
import os
import subprocess
import re
import sys
mLRSProjectdirectory = os.path.dirname(os.path.abspath(__file__))
mLRSdirectory = os.path.join(mLRSProjectdirectory,'mLRS')
python_cmd = '' # 'python' or 'python3' depending on installation
silent = False
def os_system(arg):
if silent:
res = subprocess.call(arg, stdout=subprocess.DEVNULL)
else:
res = subprocess.call(arg)
if res != 0:
print('# ERROR (errno =',res,') DONE #')
print('Press Enter to continue')
input()
exit(1)
def _check_python_version(required_version):
try:
res = subprocess.check_output([required_version, "--version"], text=True)
major_version = re.findall(r'\d', res)[0]
return int(major_version)
except:
return 0
def check_python():
# check if Python is installed and find which Python cmd to use
global python_cmd
if _check_python_version('python') == 3:
python_cmd = 'python'
elif _check_python_version('python3') == 3:
python_cmd = 'python3'
else:
print("ERROR: Python 3 not found on your system. Please make sure Python 3 is available.")
print('Press Enter to continue')
input()
exit(1)
def git_submodules_update():
print('----------------------------------------')
print(' run git submodule update --init --recursive')
print('----------------------------------------')
os_system(['git', 'submodule', 'update', '--init', '--recursive'])
print('# DONE #')
def copy_st_drivers():
print('----------------------------------------')
print(' run run_copy_st_drivers.py')
print('----------------------------------------')
os.chdir(os.path.join(mLRSProjectdirectory,'tools'))
os_system([python_cmd, os.path.join('.' , 'run_copy_st_drivers.py'), '-silent'])
print('# DONE #')
def generate_mavlink_c_library():
print('----------------------------------------')
print(' run fmav_generate_c_library.py')
print('----------------------------------------')
os.chdir(os.path.join(mLRSdirectory,'Common','mavlink'))
os_system([python_cmd, os.path.join('.','fmav_generate_c_library.py')])
print('# DONE #')
def generate_dronecan_c_library():
print('----------------------------------------')
print(' run dronecan_generate_c_library.py')
print('----------------------------------------')
os.chdir(os.path.join(mLRSdirectory,'Common','dronecan'))
os_system([python_cmd, os.path.join('.','dronecan_generate_c_library.py'), '-np'])
print('# DONE #')
if '-s' in sys.argv or '--silent' in sys.argv:
silent = True
check_python()
git_submodules_update()
copy_st_drivers()
generate_mavlink_c_library()
generate_dronecan_c_library()
print('Press Enter to continue')
input()