Skip to content

Commit

Permalink
[nrf noup] Fix zap instalation for MacOs
Browse files Browse the repository at this point in the history
Fix updating get_zap.py script, which ensure zap
will work on the MacOs systems.

Signed-off-by: Patryk Lipinski <patryk.lipinski@nordicsemi.no>
  • Loading branch information
LipinskiPNordicSemi authored and LuDuda committed Mar 8, 2024
1 parent 1e9f9b2 commit 33ec94f
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions scripts/setup/nrfconnect/get_zap.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

#
# Copyright (c) 2023 Project CHIP Authors
# Copyright (c) 2024 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@
# limitations under the License.
#

#
# The script parses integrations/docker/images/chip-build/Dockerfile file
# from the Matter repository and looks for ENV ZAP_VERSION= string to find
# currently recommended ZAP version. After that the package matching this version
Expand Down Expand Up @@ -86,11 +87,11 @@ def download_recommended_zap_package(version, package_name, location):
month = f'{int(splitted_version[1]):02d}'
day = f'{int(splitted_version[2]):02d}'
merged_version = f"{splitted_version[0]}.{month}.{day}"

url = f"https://github.com/project-chip/zap/releases/download/v{merged_version}-nightly/{package_name}.zip"
print(f"Downloading {url} into {os.path.join(location, f'{package_name}.zip')}")
wget.download(url, out=location)
print("\n")

except Exception as e:
raise RuntimeError("Invalid URL to download ZAP tool package {}".format(e))

Expand All @@ -102,6 +103,7 @@ def clear_old_artifacts(location, overwrite):
consent = input("The ZAP directory already exists in this location. Do you agree to overwrite it? Yes[y]/No[n]:")
if consent.lower() != 'yes' and consent.lower() != 'y':
raise RuntimeError("Couldn't download ZAP package, as the file already exists in this location.")

shutil.rmtree(location)


Expand All @@ -118,19 +120,26 @@ def set_executable(location, package_name, filename):


def unzip_zap_package(location, package_name):
package = location + f"/{package_name}.zip"
destination = location + "/" + package_name

try:
zip = ZipFile(os.path.join(location, f"{package_name}.zip"))
zip.extractall(os.path.join(location, package_name))
zip.close()
if (platform.system() == 'Darwin'):
subprocess.check_call(['unzip', package, '-d', destination])
else:
zip = ZipFile(os.path.join(location, f"{package_name}.zip"))
zip.extractall(os.path.join(location, package_name))
zip.close()

except Exception as e:
raise RuntimeError("Encountered problem when trying to unzip the ZAP tool package. {}".format(e))

finally:
remove_zip(location, package_name)


def print_paths_warning(paths_to_print):
messages = ["Please add the following location(s) to the system PATH:"] + paths_to_print

longest_message = max(messages, key=len)

for item in range(len(messages)):
Expand Down Expand Up @@ -160,6 +169,7 @@ def install_zap_package(version, location, overwrite):
zap_cli_executable = 'zap-cli'
else:
raise RuntimeError(f"Couldn't find the proper ZAP tool package for the currently used operating system: {current_os}")

clear_old_artifacts(os.path.join(location, package), overwrite)
download_recommended_zap_package(version, package, location)
unzip_zap_package(location, package)
Expand All @@ -175,12 +185,9 @@ def install_zap_package(version, location, overwrite):


def main():
parser = argparse.ArgumentParser(
description='Script helping to download the ZAP tool in the currently recommended revision.')
parser.add_argument(
"-l", "--location", help="Path to the location that should be used for storing ZAP tool package.", type=str, required=True)
parser.add_argument(
"-o", "--overwrite", help="Overwrite files without asking, in case they already exist in given location", action="store_true")
parser = argparse.ArgumentParser(description='Script helping to download the ZAP tool in the currently recommended revision.')
parser.add_argument("-l", "--location", help="Path to the location that should be used for storing ZAP tool package.", type=str, required=True)
parser.add_argument("-o", "--overwrite", help="Overwrite files without asking, in case they already exist in given location", action="store_true")
args = parser.parse_args()

location = os.path.abspath(args.location)
Expand Down

0 comments on commit 33ec94f

Please sign in to comment.