• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2021 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 sys
17import os
18import argparse
19import shutil
20sys.path.append(
21    os.path.dirname(os.path.dirname(os.path.dirname(
22        os.path.abspath(__file__)))))
23from scripts.util.file_utils import write_file  # noqa: E402
24from scripts.util import build_utils  # noqa: E402
25
26def copy_file(suite_path, template_path, target_path):
27    file_list = []
28    name_list = []
29    template_path = os.path.join(template_path, "src")
30
31    if not os.path.exists(suite_path):
32        raise Exception("suite path '{}' doesn't exist.".format(suite_path))
33
34    if os.path.exists(target_path):
35        shutil.rmtree(target_path)
36    os.makedirs(target_path)
37    shutil.copytree(template_path, os.path.join(target_path, "src"))
38
39    js_dest_path = os.path.join(target_path,
40        "src", "main", "js", "default", "test")
41    for root, dirs, files in os.walk(suite_path):
42        for item in files:
43            if item.endswith('.js'):
44                name_list.append(item)
45                file_list.append(os.path.join(root, item))
46
47    for file in file_list:
48        shutil.copy2(file, js_dest_path)
49    write_list_file(js_dest_path, name_list)
50
51def write_list_file(dest_path, name_list):
52    with open(os.path.join(dest_path, "List.test.js"), 'a') \
53        as list_data:
54        for name in name_list:
55            list_data.write("require('./%s')\n" % name)
56
57def main():
58    parser = argparse.ArgumentParser()
59    parser.add_argument('--suite_path', required=True)
60    parser.add_argument('--template_path', required=True)
61    parser.add_argument('--target_path', required=True)
62    args = parser.parse_args()
63
64    copy_file(args.suite_path, args.template_path, args.target_path)
65    return 0
66
67
68if __name__ == '__main__':
69    sys.exit(main())
70