some refactorings

This commit is contained in:
Bastian Schroll 2019-03-11 07:47:51 +01:00
parent 45062bd888
commit 4f389723c0
9 changed files with 67 additions and 85 deletions

View file

@ -34,6 +34,7 @@ class ConfigYAML:
yield item
def __str__(self):
"""!Returns the string representation of the internal config dict"""
return str(self._config)
def loadConfigFile(self, configPath):
@ -54,6 +55,12 @@ class ConfigYAML:
return False
def get(self, *args, default=None):
"""!Get a single value from the config
or a value set in a new configYAML class instance
@param *args: Config section (one ore more strings)
@param default: Default value if section not found (None)
@return: A single value, a value set in an configYAML instance, the default value"""
tmp = self._config
try:
for arg in args:

View file

@ -58,38 +58,6 @@ class Packet:
logging.warning("field not found: %s", fieldName)
return None
def addClientData(self, config):
"""!Add the client information to the decoded data
This function adds the following data to the bwPacket:
- clientName
- clientVersion
- clientBuildDate
- clientBranch
- inputSource
- frequency"""
logging.debug("add client data to bwPacket")
self.set("clientName", config.get("client", "name"))
self.set("clientVersion", version.client)
self.set("clientBuildDate", version.date)
self.set("clientBranch", version.branch)
self.set("inputSource", config.get("client", "inoutSource"))
self.set("frequency", config.get("inputSource", "sdr", "frequency"))
def addServerData(self, config):
"""!Add the server information to the decoded data
This function adds the following data to the bwPacket:
- serverName
- serverVersion
- serverBuildDate
- serverBranch"""
logging.debug("add server data to bwPacket")
self.set("serverName", config.get("server", "name"))
self.set("serverVersion", version.server)
self.set("serverBuildDate", version.date)
self.set("serverBranch", version.branch)
def printInfo(self):
"""!Print a info message to the log on INFO level.
Contains the most useful info about this packet.

54
boswatch/utils/misc.py Normal file
View file

@ -0,0 +1,54 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
German BOS Information Script
by Bastian Schroll
@file: misc.py
@date: 11.03.2019
@author: Bastian Schroll
@description: Some misc functions
"""
import logging
from boswatch import version
logging.debug("- %s loaded", __name__)
def addClientDataToPacket(bwPacket, config):
"""!Add the client information to the decoded data
This function adds the following data to the bwPacket:
- clientName
- clientVersion
- clientBuildDate
- clientBranch
- inputSource
- frequency"""
logging.debug("add client data to bwPacket")
bwPacket.set("clientName", config.get("client", "name"))
bwPacket.set("clientVersion", version.client)
bwPacket.set("clientBuildDate", version.date)
bwPacket.set("clientBranch", version.branch)
bwPacket.set("inputSource", config.get("client", "inoutSource"))
bwPacket.set("frequency", config.get("inputSource", "sdr", "frequency"))
def addServerDataToPacket(bwPacket, config):
"""!Add the server information to the decoded data
This function adds the following data to the bwPacket:
- serverName
- serverVersion
- serverBuildDate
- serverBranch"""
logging.debug("add server data to bwPacket")
bwPacket.set("serverName", config.get("server", "name"))
bwPacket.set("serverVersion", version.server)
bwPacket.set("serverBuildDate", version.date)
bwPacket.set("serverBranch", version.branch)