| 123456789101112131415161718192021222324252627282930 |
- #!/usr/bin/python3
- from configparser import RawConfigParser
- def merge_configs(a_conf_file, b_conf_file):
- # 读取 a.conf 文件
- a_conf = RawConfigParser()
- a_conf.read(a_conf_file, encoding='utf-8')
- # 读取 b.conf 文件
- b_conf = RawConfigParser()
- b_conf.read(b_conf_file, encoding='utf-8')
- # 合并配置项到 a.conf
- for section in b_conf.sections():
- if not a_conf.has_section(section):
- a_conf.add_section(section)
- for option in b_conf.options(section):
- # 只有在 a.conf 中不存在该项时才进行合并
- if (not a_conf.has_option(section, option)) or (option == "firmware"):
- value = b_conf.get(section, option)
- a_conf.set(section, option, value)
-
- # 将合并后的配置写入输出文件
- with open(a_conf_file, 'w') as f:
- a_conf.write(f, space_around_delimiters=False)
-
- if __name__ == "__main__":
- merge_configs("/etc/speaker.conf", "/etc/speaker_update.conf")
- merge_configs("/oem/etc/volctrl.conf", "/etc/volctrl_update.conf")
|