• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#
4# Copyright (c) 2023 Huawei Device Co., Ltd.
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17
18import json
19import os
20import stat
21import zipfile
22
23import requests
24from tqdm import tqdm
25import yaml
26
27
28def get_tool(url):
29    print(f"Getting RKDevTool from {url}")
30    r = requests.get(url, stream=True)
31    total = int(r.headers.get('content-length'), 0)
32    flags = os.O_WRONLY | os.O_CREAT
33    modes = stat.S_IWUSR | stat.S_IRUSR
34
35    with os.fdopen(os.open(r".\RKDevTool.zip", flags, modes), "wb") as f, tqdm(
36        desc="RKDevTool.zip",
37        total=total,
38        unit='iB',
39        unit_scale=True,
40        unit_divisor=1024,
41    ) as bar:
42        for byte in r.iter_content(chunk_size=1024):
43            size = f.write(byte)
44            bar.update(size)
45    with zipfile.ZipFile(".\\RKDevTool.zip", 'r') as zfile:
46        zfile.extractall(path=".\\RKDevTool")
47
48
49if __name__ == "__main__":
50    with open(r".\get_resource\config.yaml", 'r') as config_file:
51        data = yaml.safe_load(config_file.read())
52    get_tool(data['url_tools'])