Refactor config.py
All checks were successful
Build and publish Image / build-and-push (push) Successful in 8s
All checks were successful
Build and publish Image / build-and-push (push) Successful in 8s
This commit is contained in:
@@ -1,36 +1,41 @@
|
||||
#===========================================================================
|
||||
#
|
||||
# Config file
|
||||
#
|
||||
#===========================================================================
|
||||
|
||||
__doc__ = """Config file parsing.
|
||||
"""
|
||||
"""Config file parsing."""
|
||||
|
||||
from .. import util
|
||||
from ..util import config as C
|
||||
|
||||
#===========================================================================
|
||||
|
||||
# Config file section name and defaults.
|
||||
configEntries = [
|
||||
# ( name, converter function, default value )
|
||||
C.Entry( "httpPort", int, 22042 ),
|
||||
C.Entry( "mqttEnergy", str ),
|
||||
C.Entry( "mqttPower", str ),
|
||||
C.Entry( "logFile", util.path.expand ),
|
||||
C.Entry( "logLevel", int, 20 ), # INFO
|
||||
]
|
||||
# ( name, converter function, default value )
|
||||
C.Entry("httpPort", int, 22042),
|
||||
C.Entry("mqttEnergy", str),
|
||||
C.Entry("mqttPower", str),
|
||||
C.Entry("logFile", util.path.expand),
|
||||
C.Entry("logLevel", int, 20), # INFO
|
||||
]
|
||||
|
||||
#===========================================================================
|
||||
def parse( configDir, configFile='eagle.py' ):
|
||||
return C.readAndCheck( configDir, configFile, configEntries )
|
||||
def parse(configDir, configFile='eagle.py'):
|
||||
"""
|
||||
Parse the configuration file.
|
||||
|
||||
#===========================================================================
|
||||
def log( config, logFile=None ):
|
||||
if not logFile:
|
||||
logFile = config.logFile
|
||||
|
||||
return util.log.get( "eagle", config.logLevel, logFile )
|
||||
Args:
|
||||
configDir (str): The directory containing the configuration file.
|
||||
configFile (str): The name of the configuration file.
|
||||
|
||||
#===========================================================================
|
||||
Returns:
|
||||
dict: The parsed configuration.
|
||||
"""
|
||||
return C.readAndCheck(configDir, configFile, configEntries)
|
||||
|
||||
def log(config, logFile=None):
|
||||
"""
|
||||
Get the logger configuration.
|
||||
|
||||
Args:
|
||||
config (dict): The configuration dictionary.
|
||||
logFile (str): The log file path.
|
||||
|
||||
Returns:
|
||||
logger: The logger object.
|
||||
"""
|
||||
logFile = logFile or config['logFile']
|
||||
return util.log.get("eagle", config['logLevel'], logFile)
|
||||
Reference in New Issue
Block a user