1
1
#!/usr/bin/env python3
2
2
3
3
#
4
- # Copyright (c) 2023 Project CHIP Authors
4
+ # Copyright (c) 2024 Project CHIP Authors
5
5
#
6
6
# Licensed under the Apache License, Version 2.0 (the "License");
7
7
# you may not use this file except in compliance with the License.
16
16
# limitations under the License.
17
17
#
18
18
19
+ #
19
20
# The script parses integrations/docker/images/chip-build/Dockerfile file
20
21
# from the Matter repository and looks for ENV ZAP_VERSION= string to find
21
22
# currently recommended ZAP version. After that the package matching this version
@@ -86,11 +87,11 @@ def download_recommended_zap_package(version, package_name, location):
86
87
month = f'{ int (splitted_version [1 ]):02d} '
87
88
day = f'{ int (splitted_version [2 ]):02d} '
88
89
merged_version = f"{ splitted_version [0 ]} .{ month } .{ day } "
89
-
90
90
url = f"https://github.com/project-chip/zap/releases/download/v{ merged_version } -nightly/{ package_name } .zip"
91
91
print (f"Downloading { url } into { os .path .join (location , f'{ package_name } .zip' )} " )
92
92
wget .download (url , out = location )
93
93
print ("\n " )
94
+
94
95
except Exception as e :
95
96
raise RuntimeError ("Invalid URL to download ZAP tool package {}" .format (e ))
96
97
@@ -102,6 +103,7 @@ def clear_old_artifacts(location, overwrite):
102
103
consent = input ("The ZAP directory already exists in this location. Do you agree to overwrite it? Yes[y]/No[n]:" )
103
104
if consent .lower () != 'yes' and consent .lower () != 'y' :
104
105
raise RuntimeError ("Couldn't download ZAP package, as the file already exists in this location." )
106
+
105
107
shutil .rmtree (location )
106
108
107
109
@@ -118,19 +120,26 @@ def set_executable(location, package_name, filename):
118
120
119
121
120
122
def unzip_zap_package (location , package_name ):
123
+ package = location + f"/{ package_name } .zip"
124
+ destination = location + "/" + package_name
125
+
121
126
try :
122
- zip = ZipFile (os .path .join (location , f"{ package_name } .zip" ))
123
- zip .extractall (os .path .join (location , package_name ))
124
- zip .close ()
127
+ if (platform .system () == 'Darwin' ):
128
+ subprocess .check_call (['unzip' , package , '-d' , destination ])
129
+ else :
130
+ zip = ZipFile (os .path .join (location , f"{ package_name } .zip" ))
131
+ zip .extractall (os .path .join (location , package_name ))
132
+ zip .close ()
133
+
125
134
except Exception as e :
126
135
raise RuntimeError ("Encountered problem when trying to unzip the ZAP tool package. {}" .format (e ))
136
+
127
137
finally :
128
138
remove_zip (location , package_name )
129
139
130
140
131
141
def print_paths_warning (paths_to_print ):
132
142
messages = ["Please add the following location(s) to the system PATH:" ] + paths_to_print
133
-
134
143
longest_message = max (messages , key = len )
135
144
136
145
for item in range (len (messages )):
@@ -160,6 +169,7 @@ def install_zap_package(version, location, overwrite):
160
169
zap_cli_executable = 'zap-cli'
161
170
else :
162
171
raise RuntimeError (f"Couldn't find the proper ZAP tool package for the currently used operating system: { current_os } " )
172
+
163
173
clear_old_artifacts (os .path .join (location , package ), overwrite )
164
174
download_recommended_zap_package (version , package , location )
165
175
unzip_zap_package (location , package )
@@ -175,12 +185,9 @@ def install_zap_package(version, location, overwrite):
175
185
176
186
177
187
def main ():
178
- parser = argparse .ArgumentParser (
179
- description = 'Script helping to download the ZAP tool in the currently recommended revision.' )
180
- parser .add_argument (
181
- "-l" , "--location" , help = "Path to the location that should be used for storing ZAP tool package." , type = str , required = True )
182
- parser .add_argument (
183
- "-o" , "--overwrite" , help = "Overwrite files without asking, in case they already exist in given location" , action = "store_true" )
188
+ parser = argparse .ArgumentParser (description = 'Script helping to download the ZAP tool in the currently recommended revision.' )
189
+ parser .add_argument ("-l" , "--location" , help = "Path to the location that should be used for storing ZAP tool package." , type = str , required = True )
190
+ parser .add_argument ("-o" , "--overwrite" , help = "Overwrite files without asking, in case they already exist in given location" , action = "store_true" )
184
191
args = parser .parse_args ()
185
192
186
193
location = os .path .abspath (args .location )
0 commit comments