import sys
import os
import argparse
import shutil
def _merge_txt_file(ohos_notice: str, a_notice: str, output_notice: str):
if not os.path.exists(ohos_notice):
print("Warning, can not find the ohos notice file: {}.".format(
ohos_notice))
return
if not os.path.exists(a_notice):
print("Warning, can not find the notice file: {}.".format(a_notice))
shutil.move(ohos_notice, a_notice)
return
with open(output_notice, 'a') as a_file:
with open(ohos_notice, 'r', errors='ignore') as _file:
data = _file.readlines()
del data[0]
for line in data:
a_file.write(line)
with open(a_notice, 'r', errors='ignore') as _file:
data = _file.readlines()
del data[0]
for line in data:
a_file.write(line)
if os.path.exists(ohos_notice):
os.remove(ohos_notice)
def main() -> int:
"""notice file merge."""
parser = argparse.ArgumentParser()
parser.add_argument('--ohos-notice', required=True)
parser.add_argument('--a-notice', required=True)
parser.add_argument('--output-notice', required=True)
args = parser.parse_args()
_merge_txt_file(args.ohos_notice, args.a_notice, args.output_notice)
return 0
if __name__ == '__main__':
sys.exit(main())