comparison sat/tools/config.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents 3c7a64d6f49f
children
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
32 from sat.core import exceptions 32 from sat.core import exceptions
33 33
34 log = getLogger(__name__) 34 log = getLogger(__name__)
35 35
36 36
37 def fixConfigOption(section, option, value, silent=True): 37 def fix_config_option(section, option, value, silent=True):
38 """Force a configuration option value 38 """Force a configuration option value
39 39
40 the option will be written in the first found user config file, a new user 40 the option will be written in the first found user config file, a new user
41 config will be created if none is found. 41 config will be created if none is found.
42 42
73 log.warning(_("Config auto-update: {option} set to {value} in the file " 73 log.warning(_("Config auto-update: {option} set to {value} in the file "
74 "{config_file}.").format(option=option, value=value, 74 "{config_file}.").format(option=option, value=value,
75 config_file=target_file)) 75 config_file=target_file))
76 76
77 77
78 def parseMainConf(log_filenames=False): 78 def parse_main_conf(log_filenames=False):
79 """Look for main .ini configuration file, and parse it 79 """Look for main .ini configuration file, and parse it
80 80
81 @param log_filenames(bool): if True, log filenames of read config files 81 @param log_filenames(bool): if True, log filenames of read config files
82 """ 82 """
83 config = ConfigParser(defaults=C.DEFAULT_CONFIG) 83 config = ConfigParser(defaults=C.DEFAULT_CONFIG)
97 ) 97 )
98 98
99 return config 99 return config
100 100
101 101
102 def getConfig(config, section, name, default=None): 102 def config_get(config, section, name, default=None):
103 """Get a configuration option 103 """Get a configuration option
104 104
105 @param config (ConfigParser): the configuration instance 105 @param config (ConfigParser): the configuration instance
106 @param section (str): section of the config file (None or '' for DEFAULT) 106 @param section (str): section of the config file (None or '' for DEFAULT)
107 @param name (str): name of the option 107 @param name (str): name of the option
143 except ValueError as e: 143 except ValueError as e:
144 raise exceptions.ParsingError("Error while parsing data: {}".format(e)) 144 raise exceptions.ParsingError("Error while parsing data: {}".format(e))
145 return value 145 return value
146 146
147 147
148 def getConf( 148 def get_conf(
149 conf: ConfigParser, 149 conf: ConfigParser,
150 prefix: str, 150 prefix: str,
151 section: str, 151 section: str,
152 name: str, 152 name: str,
153 default: Any 153 default: Any
166 @param default: default value to use if varilable is set neither in environment, 166 @param default: default value to use if varilable is set neither in environment,
167 nor in config 167 nor in config
168 """ 168 """
169 # XXX: This is a temporary method until parameters are refactored 169 # XXX: This is a temporary method until parameters are refactored
170 value = os.getenv(f"LIBERVIA_{prefix}_{name}".upper()) 170 value = os.getenv(f"LIBERVIA_{prefix}_{name}".upper())
171 return value or getConfig(conf, section, f"{prefix}_{name}", default) 171 return value or config_get(conf, section, f"{prefix}_{name}", default)