1 # Copyright 2020 The gRPC Authors
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """Download and unzip the target file to the destination."""
16 from __future__ import print_function
26 if len(sys.argv) != 3:
27 print("Usage: python download_and_unzip.py [zipfile-url] [destination]")
29 download_url = sys.argv[1]
30 destination = sys.argv[2]
32 with tempfile.TemporaryFile() as tmp_file:
33 r = requests.get(download_url)
34 if r.status_code != requests.codes.ok:
35 print("Download %s failed with [%d] \"%s\"" %
36 (download_url, r.status_code, r.text()))
39 tmp_file.write(r.content)
40 print("Successfully downloaded from %s", download_url)
41 with zipfile.ZipFile(tmp_file, 'r') as target_zip_file:
42 target_zip_file.extractall(destination)
43 print("Successfully unzip to %s" % destination)
46 if __name__ == "__main__":