15f9996aaSopenharmony_ci#!/usr/bin/env python
25f9996aaSopenharmony_ci# -*- coding: utf-8 -*-
35f9996aaSopenharmony_ci# Copyright (c) 2022 Huawei Device Co., Ltd.
45f9996aaSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
55f9996aaSopenharmony_ci# you may not use this file except in compliance with the License.
65f9996aaSopenharmony_ci# You may obtain a copy of the License at
75f9996aaSopenharmony_ci#
85f9996aaSopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
95f9996aaSopenharmony_ci#
105f9996aaSopenharmony_ci# Unless required by applicable law or agreed to in writing, software
115f9996aaSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
125f9996aaSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135f9996aaSopenharmony_ci# See the License for the specific language governing permissions and
145f9996aaSopenharmony_ci# limitations under the License.
155f9996aaSopenharmony_ci
165f9996aaSopenharmony_ciimport sys
175f9996aaSopenharmony_ciimport os
185f9996aaSopenharmony_ciimport argparse
195f9996aaSopenharmony_ciimport shutil
205f9996aaSopenharmony_ciimport subprocess
215f9996aaSopenharmony_ciimport multiprocessing
225f9996aaSopenharmony_cisys.path.append(
235f9996aaSopenharmony_ci    os.path.dirname(os.path.dirname(os.path.dirname(
245f9996aaSopenharmony_ci        os.path.abspath(__file__)))))
255f9996aaSopenharmony_ci
265f9996aaSopenharmony_ci
275f9996aaSopenharmony_cidef copytree(source: str, destination: str):
285f9996aaSopenharmony_ci    shutil.copytree(source, destination, dirs_exist_ok=True)
295f9996aaSopenharmony_ci
305f9996aaSopenharmony_ci
315f9996aaSopenharmony_cidef copy_file(fuzz_config_file_path: str, fuzz_config_file_output_path: str):
325f9996aaSopenharmony_ci    if not os.path.exists(fuzz_config_file_path):
335f9996aaSopenharmony_ci        raise Exception("fuzz_config_file_path '{}' doesn't exist.".format(fuzz_config_file_path))
345f9996aaSopenharmony_ci    target_file_path = os.path.join(fuzz_config_file_output_path, os.path.basename(fuzz_config_file_path))
355f9996aaSopenharmony_ci    try:
365f9996aaSopenharmony_ci        p = multiprocessing.Process(target=copytree, args=(fuzz_config_file_path, target_file_path))
375f9996aaSopenharmony_ci        p.start()
385f9996aaSopenharmony_ci        p.join()
395f9996aaSopenharmony_ci    except Exception as e:
405f9996aaSopenharmony_ci        subprocess.call(["cp", "-rf", fuzz_config_file_path, fuzz_config_file_output_path])
415f9996aaSopenharmony_ci
425f9996aaSopenharmony_ci
435f9996aaSopenharmony_cidef main():
445f9996aaSopenharmony_ci    parser = argparse.ArgumentParser()
455f9996aaSopenharmony_ci    parser.add_argument('--fuzz-config-file-path', required=True)
465f9996aaSopenharmony_ci    parser.add_argument('--fuzz-config-file-output-path', required=True)
475f9996aaSopenharmony_ci    args = parser.parse_args()
485f9996aaSopenharmony_ci
495f9996aaSopenharmony_ci    copy_file(args.fuzz_config_file_path, args.fuzz_config_file_output_path)
505f9996aaSopenharmony_ci    return 0
515f9996aaSopenharmony_ci
525f9996aaSopenharmony_ci
535f9996aaSopenharmony_ciif __name__ == '__main__':
545f9996aaSopenharmony_ci    sys.exit(main())
55