Refactor code to be more readable #46
@@ -1,36 +1,41 @@
|
|||||||
#===========================================================================
|
"""Config file parsing."""
|
||||||
#
|
|
||||||
# Config file
|
|
||||||
#
|
|
||||||
#===========================================================================
|
|
||||||
|
|
||||||
__doc__ = """Config file parsing.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from .. import util
|
from .. import util
|
||||||
from ..util import config as C
|
from ..util import config as C
|
||||||
|
|
||||||
#===========================================================================
|
|
||||||
|
|
||||||
# Config file section name and defaults.
|
# Config file section name and defaults.
|
||||||
configEntries = [
|
configEntries = [
|
||||||
# ( name, converter function, default value )
|
# ( name, converter function, default value )
|
||||||
C.Entry( "httpPort", int, 22042 ),
|
C.Entry("httpPort", int, 22042),
|
||||||
C.Entry( "mqttEnergy", str ),
|
C.Entry("mqttEnergy", str),
|
||||||
C.Entry( "mqttPower", str ),
|
C.Entry("mqttPower", str),
|
||||||
C.Entry( "logFile", util.path.expand ),
|
C.Entry("logFile", util.path.expand),
|
||||||
C.Entry( "logLevel", int, 20 ), # INFO
|
C.Entry("logLevel", int, 20), # INFO
|
||||||
]
|
]
|
||||||
|
|
||||||
#===========================================================================
|
def parse(configDir, configFile='eagle.py'):
|
||||||
def parse( configDir, configFile='eagle.py' ):
|
"""
|
||||||
return C.readAndCheck( configDir, configFile, configEntries )
|
Parse the configuration file.
|
||||||
|
|
||||||
#===========================================================================
|
Args:
|
||||||
def log( config, logFile=None ):
|
configDir (str): The directory containing the configuration file.
|
||||||
if not logFile:
|
configFile (str): The name of the configuration file.
|
||||||
logFile = config.logFile
|
|
||||||
|
|
||||||
return util.log.get( "eagle", config.logLevel, logFile )
|
|
||||||
|
|
||||||
#===========================================================================
|
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