7
7
import urllib .request
8
8
import os
9
9
import stat
10
- import sys
10
+ import platform
11
11
import subprocess
12
12
13
13
@@ -50,9 +50,10 @@ class custom_build(build):
50
50
@property
51
51
def platform_suffix (self ):
52
52
"""
53
- Trying to detect the platform to know which `mavsdk_server` executable to download
53
+ Trying to detect the platform to know which `mavsdk_server` executable
54
+ to download
54
55
"""
55
- if sys . platform .startswith ( 'linux' ) and 'MAVSDK_SERVER_ARCH' in os .environ :
56
+ if platform .system () == 'Linux' and 'MAVSDK_SERVER_ARCH' in os .environ :
56
57
if os .environ ['MAVSDK_SERVER_ARCH' ] == "armv6l" :
57
58
return 'linux-armv6-musl'
58
59
elif os .environ ['MAVSDK_SERVER_ARCH' ] == "armv7l" :
@@ -61,24 +62,34 @@ def platform_suffix(self):
61
62
return 'linux-arm64-musl'
62
63
else :
63
64
raise NotImplementedError (
64
- f"Error: unknown MAVSDK_SERVER_ARCH: { os .environ ['MAVSDK_SERVER_ARCH' ]} " )
65
- elif sys .platform .startswith ('linux' ):
65
+ "Error: unknown MAVSDK_SERVER_ARCH: "
66
+ f"{ os .environ ['MAVSDK_SERVER_ARCH' ]} " )
67
+ elif platform .system () == 'Linux' :
66
68
return 'musl_x86_64'
67
- elif sys .platform .startswith ('darwin' ):
68
- return 'macos'
69
- elif sys .platform .startswith ('win' ):
69
+ elif platform .system () == 'Darwin' :
70
+ if platform .processor () == 'i386' :
71
+ return 'macos_x64'
72
+ elif platform .processor () == 'arm' :
73
+ return 'macos_arm64'
74
+ raise NotImplementedError (
75
+ f"Error: unknown macOS processor: { platform .processor ()} " )
76
+ elif platform .system () == 'Windows' \
77
+ and platform .processor () == 'AMD64' :
70
78
return 'win32.exe'
71
79
else :
72
80
raise NotImplementedError (
73
- f"Error: mavsdk_server is not distributed for platform { sys .platform } (yet)! You should set the 'MAVSDK_BUILD_PURE=ON' environment variable and get mavsdk_server manually." )
81
+ "Error: mavsdk_server is not distributed for platform "
82
+ f"{ platform .system ()} (yet)!\n \n You should set the "
83
+ "'MAVSDK_BUILD_PURE=ON' environment variable and get "
84
+ "mavsdk_server manually." )
74
85
75
86
@property
76
87
def mavsdk_server_filepath (self ):
77
88
"""
78
89
The location of the downloaded `mavsdk_server` binary
79
90
For Windows this needs to be a .exe file
80
91
"""
81
- if sys . platform .startswith ( 'win' ) :
92
+ if platform .system () == 'Windows' :
82
93
return 'mavsdk/bin/mavsdk_server.exe'
83
94
else :
84
95
return 'mavsdk/bin/mavsdk_server'
@@ -97,7 +108,8 @@ def mavsdk_server_url(self):
97
108
"""
98
109
Build the url of the `mavsdk_server` binary
99
110
"""
100
- return f"https://github.com/mavlink/MAVSDK/releases/download/{ self .mavsdk_server_tag } /mavsdk_server_{ self .platform_suffix } "
111
+ return "https://github.com/mavlink/MAVSDK/releases/download/" \
112
+ f"{ self .mavsdk_server_tag } /mavsdk_server_{ self .platform_suffix } "
101
113
102
114
def run (self ):
103
115
if 'MAVSDK_BUILD_PURE' not in os .environ :
@@ -107,7 +119,8 @@ def run(self):
107
119
108
120
def download_mavsdk_server (self ):
109
121
print (
110
- f"downloading { self .mavsdk_server_url } into { self .mavsdk_server_filepath } " )
122
+ f"downloading { self .mavsdk_server_url } into "
123
+ f"{ self .mavsdk_server_filepath } " )
111
124
urllib .request .urlretrieve (
112
125
self .mavsdk_server_url ,
113
126
filename = self .mavsdk_server_filepath )
0 commit comments