Refactor code to be more readable #46

Closed
erichardson wants to merge 4 commits from refactor-code into master
Showing only changes of commit a35d0cbb58 - Show all commits

View File

@@ -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
]
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
Args:
configDir (str): The directory containing the configuration file.
configFile (str): The name of the configuration file.
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)