1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4""" 5Copyright (c) 2024 Huawei Device Co., Ltd. 6Licensed under the Apache License, Version 2.0 (the "License"); 7you may not use this file except in compliance with the License. 8You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12Unless required by applicable law or agreed to in writing, software 13distributed under the License is distributed on an "AS IS" BASIS, 14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15See the License for the specific language governing permissions and 16limitations under the License. 17 18Description: Process fileinfo file, modify the first path to a local absolute path 19""" 20 21import sys 22import os 23 24 25def add_path_to_file(input_file, output_file, prefix_path): 26 fd = os.open(output_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o644) 27 with os.fdopen(fd, 'w') as outfile, open(input_file, 'r') as infile: 28 for line in infile: 29 outfile.write(f"{prefix_path}{line}") 30 31 32def main(input_file, output_file, prefix_path): 33 add_path_to_file(input_file, output_file, prefix_path) 34 35 36if __name__ == '__main__': 37 if len(sys.argv) != 4: 38 print(f"Usage: {sys.argv[0]} <input_file> <output_file> <prefix_path>") 39 sys.exit(1) 40 main(sys.argv[1], sys.argv[2], sys.argv[3]) 41