Add config getters for logging, history and behavior settings
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
This commit is contained in:
+30
-3
@@ -72,6 +72,18 @@ class ConfigLoader:
|
|||||||
|
|
||||||
return value.lower() in ('true', 'yes', '1', 'on')
|
return value.lower() in ('true', 'yes', '1', 'on')
|
||||||
|
|
||||||
|
def get_float(self, section, key, fallback=0.0):
|
||||||
|
"""Get a float configuration value"""
|
||||||
|
value = self.get(section, key)
|
||||||
|
if value is None:
|
||||||
|
return fallback
|
||||||
|
|
||||||
|
try:
|
||||||
|
return float(value)
|
||||||
|
except ValueError:
|
||||||
|
logger.warning(f'Invalid float value for [{section}] {key}: {value}')
|
||||||
|
return fallback
|
||||||
|
|
||||||
def get_host(self):
|
def get_host(self):
|
||||||
"""Get connection host"""
|
"""Get connection host"""
|
||||||
return self.get('connection', 'host')
|
return self.get('connection', 'host')
|
||||||
@@ -129,8 +141,11 @@ class ConfigLoader:
|
|||||||
return password
|
return password
|
||||||
|
|
||||||
def get_log_level(self):
|
def get_log_level(self):
|
||||||
"""Get logging level"""
|
"""Get logging level (None if not configured or invalid)"""
|
||||||
level_str = self.get('logging', 'level', 'INFO')
|
level_str = self.get('logging', 'level')
|
||||||
|
if not level_str:
|
||||||
|
return None
|
||||||
|
|
||||||
levels = {
|
levels = {
|
||||||
'DEBUG': logging.DEBUG,
|
'DEBUG': logging.DEBUG,
|
||||||
'INFO': logging.INFO,
|
'INFO': logging.INFO,
|
||||||
@@ -138,7 +153,19 @@ class ConfigLoader:
|
|||||||
'ERROR': logging.ERROR,
|
'ERROR': logging.ERROR,
|
||||||
'CRITICAL': logging.CRITICAL
|
'CRITICAL': logging.CRITICAL
|
||||||
}
|
}
|
||||||
return levels.get(level_str.upper(), logging.INFO)
|
return levels.get(level_str.upper())
|
||||||
|
|
||||||
|
def get_max_history(self, default):
|
||||||
|
"""Get command history length from [ui] section"""
|
||||||
|
return self.get_int('ui', 'max_history', default)
|
||||||
|
|
||||||
|
def get_quit_timeout(self, default):
|
||||||
|
"""Get quit confirmation timeout from [behavior] section"""
|
||||||
|
return self.get_float('behavior', 'quit_timeout', default)
|
||||||
|
|
||||||
|
def get_respawn_delay(self, default):
|
||||||
|
"""Get respawn delay from [behavior] section"""
|
||||||
|
return self.get_float('behavior', 'respawn_delay', default)
|
||||||
|
|
||||||
|
|
||||||
def create_example_config():
|
def create_example_config():
|
||||||
|
|||||||
Reference in New Issue
Block a user