mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2026-01-20 15:40:24 +01:00
edit specific get methods to the config (Int, Str, Bool)
This commit is contained in:
parent
6e011301d4
commit
0b1bd7a59b
|
|
@ -59,7 +59,37 @@ class Config:
|
|||
logging.debug("configuration sharePoint: %s", sharePoint)
|
||||
return True
|
||||
|
||||
def get(self, section, key, sharePoint=""):
|
||||
def getInt(self, section, key, sharePoint=""):
|
||||
"""!Method to read a single config entry as integer
|
||||
|
||||
@param section: Section to read from
|
||||
@param key: Value to read
|
||||
@param sharePoint: Name of the global config share (empty is only local)
|
||||
@return The value or None"""
|
||||
value = self._get(section, key, sharePoint)
|
||||
if value is None:
|
||||
return int(0)
|
||||
return int(value)
|
||||
|
||||
def getBool(self, section, key, sharePoint=""):
|
||||
"""!Method to read a single config entry as boolean
|
||||
|
||||
@param section: Section to read from
|
||||
@param key: Value to read
|
||||
@param sharePoint: Name of the global config share (empty is only local)
|
||||
@return The value or None"""
|
||||
return bool(self._get(section, key, sharePoint))
|
||||
|
||||
def getStr(self, section, key, sharePoint=""):
|
||||
"""!Method to read a single config entry as string
|
||||
|
||||
@param section: Section to read from
|
||||
@param key: Value to read
|
||||
@param sharePoint: Name of the global config share (empty is only local)
|
||||
@return The value or None"""
|
||||
return str(self._get(section, key, sharePoint))
|
||||
|
||||
def _get(self, section, key, sharePoint=""):
|
||||
"""!Method to read a single config entry
|
||||
|
||||
@param section: Section to read from
|
||||
|
|
@ -72,9 +102,9 @@ class Config:
|
|||
except KeyError:
|
||||
logging.error("no sharePoint named: %s", sharePoint)
|
||||
except configparser.NoSectionError:
|
||||
logging.error("no shared config section: %s", section)
|
||||
logging.warning("no shared config section: %s", section)
|
||||
except configparser.NoOptionError:
|
||||
logging.error("no shared config option: %s", key)
|
||||
logging.warning("no shared config option: %s", key)
|
||||
except: # pragma: no cover
|
||||
logging.exception("error while reading shared config")
|
||||
return None
|
||||
|
|
@ -83,9 +113,15 @@ class Config:
|
|||
try:
|
||||
return self._config.get(section, key)
|
||||
except configparser.NoSectionError:
|
||||
logging.error("no local config section: %s", section)
|
||||
logging.warning("no local config section: %s", section)
|
||||
except configparser.NoOptionError:
|
||||
logging.error("no local config option: %s", key)
|
||||
logging.warning("no local config option: %s", key)
|
||||
except: # pragma: no cover
|
||||
logging.exception("error while reading local config")
|
||||
return None
|
||||
|
||||
def getAllSharepoints(self):
|
||||
"""!Return a python dict of all set sharepoints
|
||||
|
||||
@return Sharepoint dict"""
|
||||
return self._sharePoints
|
||||
|
|
|
|||
|
|
@ -71,12 +71,12 @@ class Packet:
|
|||
- frequency"""
|
||||
config = Config()
|
||||
logging.debug("add client data to bwPacket")
|
||||
self.set("clientName", config.get("Client", "Name", "clientConfig"))
|
||||
self.set("clientName", config.getStr("Client", "Name", "clientConfig"))
|
||||
self.set("clientVersion", version.client)
|
||||
self.set("clientBuildDate", version.date)
|
||||
self.set("clientBranch", version.branch)
|
||||
self.set("inputSource", config.get("Server", "InputSource", "clientConfig"))
|
||||
self.set("frequency", config.get("Stick", "Frequency", "clientConfig"))
|
||||
self.set("inputSource", config.getStr("Server", "InputSource", "clientConfig"))
|
||||
self.set("frequency", config.getStr("Stick", "Frequency", "clientConfig"))
|
||||
|
||||
def addServerData(self):
|
||||
"""!Add the server information to the decoded data
|
||||
|
|
@ -88,7 +88,16 @@ class Packet:
|
|||
- serverBranch"""
|
||||
config = Config()
|
||||
logging.debug("add server data to bwPacket")
|
||||
self.set("serverName", config.get("Server", "Name", "serverConfig"))
|
||||
self.set("serverName", config.getStr("Server", "Name", "serverConfig"))
|
||||
self.set("serverVersion", version.server)
|
||||
self.set("serverBuildDate", version.date)
|
||||
self.set("serverBranch", version.branch)
|
||||
|
||||
@staticmethod
|
||||
def infoToLog(bwPacket):
|
||||
"""!Print a info message to the log on INFO level.
|
||||
Contains the most useful info about this packet.
|
||||
@todo not complete yet - must be edit to print nice formatted messages on console
|
||||
|
||||
@param bwPacket: BOSWatch packet instance"""
|
||||
logging.info("%s packet received", bwPacket.get("mode"))
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ class Plugin:
|
|||
def __init__(self, pluginName):
|
||||
"""!init preload some needed locals and then call onLoad() directly"""
|
||||
self._pluginName = pluginName
|
||||
logging.debug("load %s", self._pluginName)
|
||||
self._pluginsActive += 1
|
||||
|
||||
# for time counting
|
||||
|
|
@ -44,52 +43,52 @@ class Plugin:
|
|||
self._alarmErrorCount = 0
|
||||
self._teardownErrorCount = 0
|
||||
|
||||
logging.debug("[%s] onLoad()", pluginName)
|
||||
self.onLoad()
|
||||
|
||||
def __del__(self):
|
||||
"""!Destructor calls onUnload() directly"""
|
||||
logging.debug("unload %s", self._pluginName)
|
||||
logging.debug("[%s] onUnload()", self._pluginName)
|
||||
self._pluginsActive -= 1
|
||||
self.onUnload()
|
||||
|
||||
# logging.debug("[%s] statistics:", self._pluginName)
|
||||
# logging.debug("- runs %d", self._runCount)
|
||||
# logging.debug("- setup errors %d", self._setupErrorCount)
|
||||
# logging.debug("- alarm errors %d", self._alarmErrorCount)
|
||||
# logging.debug("- teardown errors %d", self._teardownErrorCount)
|
||||
|
||||
def _loadConfig(self):
|
||||
pass
|
||||
|
||||
def _run(self, bwPacket):
|
||||
"""!start an complete running turn of an plugin.
|
||||
Calls setup(), alarm() and teardown() in this order.
|
||||
The alarm() method serves the BOSWatch packet to the plugin.
|
||||
|
||||
@param bwPacket: A BOSWatch packet instance"""
|
||||
self._runCount += 1
|
||||
logging.debug("[%s] run #%s", self._pluginName, self._runCount)
|
||||
logging.debug("[%s] run #%d", self._pluginName, self._runCount)
|
||||
|
||||
self._tmpTime = time.time()
|
||||
try:
|
||||
logging.debug("[%s] setup", self._pluginName)
|
||||
logging.debug("[%s] setup()", self._pluginName)
|
||||
self.setup()
|
||||
except:
|
||||
self._setupErrorCount += 1
|
||||
logging.exception("[%s] error in setup", self._pluginName)
|
||||
logging.exception("[%s] error in setup()", self._pluginName)
|
||||
|
||||
self._setupTime = time.time() - self._tmpTime
|
||||
self._tmpTime = time.time()
|
||||
try:
|
||||
logging.debug("[%s] alarm", self._pluginName)
|
||||
logging.debug("[%s] alarm()", self._pluginName)
|
||||
self.alarm(bwPacket)
|
||||
except:
|
||||
self._alarmErrorCount += 1
|
||||
logging.exception("[%s] error in alarm", self._pluginName)
|
||||
logging.exception("[%s] error in alarm()", self._pluginName)
|
||||
|
||||
self._alarmTime = time.time() - self._tmpTime
|
||||
self._tmpTime = time.time()
|
||||
try:
|
||||
logging.debug("[%s] teardown", self._pluginName)
|
||||
logging.debug("[%s] teardown()", self._pluginName)
|
||||
self.teardown()
|
||||
except:
|
||||
self._teardownErrorCount += 1
|
||||
logging.exception("[%s] error in teardown", self._pluginName)
|
||||
logging.exception("[%s] error in teardown()", self._pluginName)
|
||||
|
||||
self._teardownTime = time.time() - self._tmpTime
|
||||
self._sumTime = self._setupTime + self._alarmTime + self._teardownTime
|
||||
|
|
|
|||
Loading…
Reference in a new issue