• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright 2024 Huawei Technologies Co., Ltd
4#
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
17import os
18import sys
19import shutil
20import argparse
21import subprocess
22
23
24def untar_file(tar_file_path, extract_path):
25    try:
26        tar_cmd = ['tar', '-zxf', tar_file_path, '-C', extract_path]
27        subprocess.run(tar_cmd, check=True)
28    except Exception as e:
29        print("tar error!")
30        return
31
32
33def clear_dir(old_dir):
34    if os.path.exists(old_dir):
35        shutil.rmtree(old_dir)
36
37
38def move_dir(src_dir, dst_dir):
39    shutil.copytree(src_dir, dst_dir)
40
41
42def main():
43    args_parser = argparse.ArgumentParser()
44    args_parser.add_argument('--gen-dir', help='generate path of log', required=True)
45    args_parser.add_argument('--source-dir', help='generate path of log', required=True)
46    args = args_parser.parse_args()
47
48    tar_file_path = os.path.join(args.source_dir, "v2.0.0.tar.gz")
49    target_dir = os.path.join(args.gen_dir, "flatbuffers-2.0.0")
50
51    clear_dir(os.path.join(args.source_dir, "include"))
52    untar_file(tar_file_path, args.gen_dir)
53    move_dir(os.path.join(target_dir, "include"), os.path.join(args.source_dir, "include"))
54
55
56if __name__ == '__main__':
57    sys.exit(main())
58