1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4# Copyright (c) 2022 Huawei Device Co., Ltd. 5# 6# HDF is dual licensed: you can use it either under the terms of 7# the GPL, or the BSD license, at your option. 8# See the LICENSE file in the root of this repository for complete details. 9 10 11import os 12from string import Template 13 14import hdf_utils 15from .mk_file_add_config import judge_driver_config_exists 16 17 18def get_template_info(template_path): 19 template_path = os.path.join(template_path, 20 'driver_add_kconfig_config.template') 21 return hdf_utils.read_file(template_path) 22 23 24def kconfig_file_operation(path, module, driver, template_path): 25 config_add_config = get_template_info(template_path) 26 kconfig_gn_path = path 27 date_lines = hdf_utils.read_file_lines(kconfig_gn_path) 28 judge_result = judge_driver_config_exists(date_lines, driver_name=driver) 29 if judge_result: 30 return 31 temp_handle = Template(config_add_config) 32 temp_replace = { 33 "model_name_upper": module.upper(), 34 "model_name_lower": module.lower(), 35 "driver_name_upper": driver.upper(), 36 "driver_name_lower": driver.lower() 37 } 38 new_line = temp_handle.substitute(temp_replace) 39 if module == "display": 40 replace_str = "depends on DRIVERS_HDF_%s" 41 old_str = replace_str % module.upper() 42 new_str = replace_str % "disp".upper() 43 new_line = new_line.replace(old_str, new_str) 44 45 date_lines = date_lines + [new_line] 46 hdf_utils.write_file_lines(kconfig_gn_path, date_lines)