1 # ============LICENSE_START====================================================
2 # org.onap.vvp/validation-scripts
3 # ===================================================================
4 # Copyright © 2019 AT&T Intellectual Property. All rights reserved.
5 # ===================================================================
7 # Unless otherwise specified, all software contained herein is licensed
8 # under the Apache License, Version 2.0 (the "License");
9 # you may not use this software except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
22 # Unless otherwise specified, all documentation contained herein is licensed
23 # under the Creative Commons License, Attribution 4.0 Intl. (the "License");
24 # you may not use this documentation except in compliance with the License.
25 # You may obtain a copy of the License at
27 # https://creativecommons.org/licenses/by/4.0/
29 # Unless required by applicable law or agreed to in writing, documentation
30 # distributed under the License is distributed on an "AS IS" BASIS,
31 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32 # See the License for the specific language governing permissions and
33 # limitations under the License.
35 # ============LICENSE_END============================================
39 import subprocess # nosec
42 from urllib import request
44 PREBUILT_DOWNLOAD_SITE = "https://download.lfd.uci.edu/pythonlibs/n5jyqt7p/"
46 "yappi-1.0-cp{python_version}-cp{python_version}m-{arch}.whl",
47 "setproctitle-1.1.10-cp{python_version}-cp{python_version}m-{arch}.whl",
52 return os.name == "nt"
56 return sys.version[:3].replace(".", "")
59 def system_architecture():
60 arch = platform.architecture()
61 return "win32" if arch[0] != "64bit" else "win_amd64"
64 def download_url(url):
65 resp = request.urlopen(url) # nosec
70 with open(path, "r") as f:
74 def write_file(data, path, mode="w"):
75 with open(path, mode) as f:
79 def install_prebuilt_binaries_on_windows():
82 temp_dir = tempfile.mkdtemp()
83 for lib in PREBUILT_WIN_LIBS:
84 filename = lib.format(
85 python_version=python_version(), arch=system_architecture()
87 url = PREBUILT_DOWNLOAD_SITE + filename
88 print(f"Downloading {url}")
89 contents = download_url(url)
90 file_path = os.path.join(temp_dir, filename)
91 write_file(contents, file_path, mode="wb")
92 print("Download complete. Installing dependency.")
93 subprocess.call(["pip", "install", file_path]) # nosec
96 if __name__ == "__main__":
97 install_prebuilt_binaries_on_windows()