• 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
20
21
22def _merge_txt_file(ohos_notice, a_notice, output_notice):
23    if not os.path.exists(ohos_notice):
24        print("Warning, can not find the ohos notice file: {}.".format(
25            ohos_notice))
26        return
27
28    if not os.path.exists(a_notice):
29        print("Warning, can not find the notice file: {}.".format(a_notice))
30        shutil.move(ohos_notice, a_notice)
31        return
32
33    with open(output_notice, 'a') as a_file:
34        with open(ohos_notice, 'r', errors='ignore') as _file:
35            data = _file.readlines()
36            del data[0]
37            for line in data:
38                a_file.write(line)
39        with open(a_notice, 'r', errors='ignore') as _file:
40            data = _file.readlines()
41            del data[0]
42            for line in data:
43                a_file.write(line)
44
45    if os.path.exists(ohos_notice):
46        os.remove(ohos_notice)
47
48
49def main():
50    """notice file merge."""
51    parser = argparse.ArgumentParser()
52    parser.add_argument('--ohos-notice', required=True)
53    parser.add_argument('--a-notice', required=True)
54    parser.add_argument('--output-notice', required=True)
55    args = parser.parse_args()
56
57    # merge NOTICE.txt file
58    _merge_txt_file(args.ohos_notice, args.a_notice, args.output_notice)
59
60    return 0
61
62
63if __name__ == '__main__':
64    sys.exit(main())
65