• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import os
17import sys
18import optparse
19import shutil
20
21# d.ts directories to be deleted 需要排除的目录名称的列表
22remove_list = ["@internal", "common", "form", "liteWearable", "config", "syscapCheck"]
23
24
25# traversal all fill in project folder
26# 2、复制文件:将输入路径中的文件和目录复制到输出路径,并且跳过某些指定的目录
27def copy_files(input_path, output_path):
28    for file in os.listdir(input_path):
29        src = os.path.join(input_path, file)
30        dst = os.path.join(output_path, file)
31        if os.path.isdir(src) and (not file in remove_list):
32            shutil.copytree(src, dst, dirs_exist_ok=True)
33        elif os.path.isfile(src):
34            shutil.copy(src, dst)
35
36
37# 1、参数解析:通过 optparse 库解析命令行参数,获取输入路径 (--input) 和输出路径 (--output)。
38def parse_args(args):
39    parser = optparse.OptionParser()
40    parser.add_option('--input', help='d.ts document input path')
41    parser.add_option('--output', help='d.ts document output path')
42    options, _ = parser.parse_args(args)
43    return options
44
45
46def main(argv):
47    options = parse_args(argv)
48    if not os.path.exists(options.output):
49        os.makedirs(options.output)
50    copy_files(options.input, options.output)
51
52
53# 从指定的输入路径复制文件到输出路径,并在复制过程中 排除特定的文件夹。
54if __name__ == "__main__":
55    exit(main(sys.argv))
56