1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# Copyright (c) 2024 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 argparse
17import os
18import sys
19import shutil
20
21from util.build_utils import touch
22
23
24def parse_args(args):
25    parser = argparse.ArgumentParser()
26
27    parser.add_argument("--source", help="specify publicity xml")
28    parser.add_argument("--output", required=True, help="specify publicity output")
29
30    options = parser.parse_args(args)
31    return options
32
33
34def main(args):
35    options = parse_args(args)
36
37    dest_dir = os.path.dirname(options.output)
38    if not os.path.exists(dest_dir):
39        os.makedirs(dest_dir, exist_ok=True)
40
41    if os.path.exists(options.output):
42        os.unlink(options.output)
43
44    if not options.source:
45        # touch an empty publicity.xml
46        touch(options.output)
47        return 0
48
49    shutil.copy2(options.source, options.output)
50    return 0
51
52
53if __name__ == "__main__":
54    sys.exit(main(sys.argv[1:]))
55