-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_getter.py
56 lines (44 loc) · 1.59 KB
/
config_getter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
# !/usr/bin/env python
"""
-------------------------------------------------
File : config_getter.py
Author : CoderPig
date : 2023-01-30 14:43
Desc : 读取配置文件配置
-------------------------------------------------
"""
import configparser
import os
import os.path
from util.logger_util import default_logger
logger = default_logger()
config_file = os.path.join(os.path.split(os.path.realpath(__file__))[0], 'config.ini')
def get_config(key, section='config'):
config = configparser.ConfigParser()
config.read(config_file, encoding='utf8')
return config.get(section, key)
def get_configs(section='config', key_args=()):
"""
获取多个配置项的元组
:param section: 配置块名称
:param key_args: 配置key
:return:
"""
config = configparser.ConfigParser()
config.read(config_file, encoding='utf8')
result_tuple = tuple(config.get(section, key) for key in key_args) if key_args else ()
return result_tuple
def update_configs(section='config', key_value_dict=dict):
config = configparser.ConfigParser()
config.read(config_file, encoding='utf8')
for key, value in key_value_dict.items():
config.set(section, key, value)
config.write(open(config_file, 'w+', encoding='utf8'))
def update_config(key, value, section='config'):
config = configparser.ConfigParser()
config.read(config_file, encoding='utf8')
config.set(section, key, value)
config.write(open(config_file, 'w+', encoding='utf8'))
if __name__ == '__main__':
print(get_config("video_subtitle_host"))