mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2025-12-06 07:12:04 +01:00
use new yaml config loader in client
This commit is contained in:
parent
b1a3a68e35
commit
90ccbf9d0d
79
boswatch/config_yaml.py
Normal file
79
boswatch/config_yaml.py
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""!
|
||||
____ ____ ______ __ __ __ _____
|
||||
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
|
||||
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
|
||||
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
|
||||
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
|
||||
German BOS Information Script
|
||||
by Bastian Schroll
|
||||
|
||||
@file: config_yaml.py
|
||||
@date: 27.02.2019
|
||||
@author: Bastian Schroll
|
||||
@description: Module for the configuration in yaml format
|
||||
"""
|
||||
import logging
|
||||
import yaml
|
||||
|
||||
logging.debug("- %s loaded", __name__)
|
||||
|
||||
__sharePoints = {}
|
||||
|
||||
|
||||
def loadConfigFile(configPath, sharePoint=""):
|
||||
"""!loads a given configuration
|
||||
|
||||
@param configPath: Path to the config file
|
||||
@param sharePoint: If you want to share the config set name here
|
||||
@return python dict of config or None"""
|
||||
logging.debug("load config file from: %s", configPath)
|
||||
try:
|
||||
|
||||
with open(configPath) as f:
|
||||
# use safe_load instead load
|
||||
config = yaml.safe_load(f)
|
||||
if sharePoint:
|
||||
_shareConfig(config, sharePoint)
|
||||
return config
|
||||
except: # pragma: no cover
|
||||
logging.exception("cannot load config file")
|
||||
return None
|
||||
|
||||
|
||||
def loadConfigSharepoint(sharePoint):
|
||||
"""!loads a given configuration from an sharepoint
|
||||
|
||||
@param sharePoint: Name of the sharepoint
|
||||
@return python dict of config or None"""
|
||||
try:
|
||||
return __sharePoints[sharePoint]
|
||||
except KeyError:
|
||||
logging.error("no sharePoint named: %s", sharePoint)
|
||||
except: # pragma: no cover
|
||||
logging.exception("error while reading shared config")
|
||||
return None
|
||||
|
||||
|
||||
def _shareConfig(config, sharePoint):
|
||||
"""!Shares the configuration
|
||||
|
||||
Shares the local _config to the class wide global _sharedConfig
|
||||
@param config: Python dict of the configuration
|
||||
@param sharePoint: Name of the global share point
|
||||
@return True or False"""
|
||||
if sharePoint in __sharePoints:
|
||||
logging.error("cannot share config - name is always in use: %s", sharePoint)
|
||||
return False
|
||||
else:
|
||||
__sharePoints[sharePoint] = config
|
||||
logging.debug("add config sharePoint: %s", sharePoint)
|
||||
return True
|
||||
|
||||
|
||||
def getAllSharepoints():
|
||||
"""!Return a python dict of all set sharepoints
|
||||
|
||||
@return Sharepoint dict"""
|
||||
return __sharePoints
|
||||
|
|
@ -43,7 +43,7 @@ try:
|
|||
import time
|
||||
|
||||
logging.debug("Import BOSWatch modules")
|
||||
from boswatch.config import Config
|
||||
from boswatch import config_yaml
|
||||
from boswatch.network.client import TCPClient
|
||||
from boswatch.decoder.decoder import Decoder
|
||||
from boswatch.utils import header
|
||||
|
|
@ -69,14 +69,14 @@ try:
|
|||
parser.add_argument("-t", "--test", help="Client will send some testdata", action="store_true") # todo implement testmode
|
||||
args = parser.parse_args()
|
||||
|
||||
bwConfig = Config()
|
||||
if bwConfig.loadConfigFile(paths.CONFIG_PATH + args.config, "clientConfig") is False:
|
||||
bwConfig = config_yaml.loadConfigFile(paths.CONFIG_PATH + args.config, "clientConfig")
|
||||
if bwConfig is None:
|
||||
logging.exception("cannot load config file")
|
||||
print("cannot load config file")
|
||||
exit(1) # without config cannot _run
|
||||
|
||||
bwClient = TCPClient()
|
||||
if bwClient.connect(bwConfig.getStr("Server", "IP"), bwConfig.getInt("Server", "PORT")):
|
||||
if bwClient.connect(bwConfig["servers"][0]["ip"], bwConfig["servers"][0]["port"]):
|
||||
|
||||
while 1:
|
||||
for i in range(0, 5):
|
||||
|
|
|
|||
|
|
@ -8,27 +8,27 @@
|
|||
# by Bastian Schroll
|
||||
|
||||
client:
|
||||
name: "BW3 Client"
|
||||
inputSource: "stick"
|
||||
name: BW3 Client # name of the BW3 Client instance
|
||||
inputSource: stick # possible is 'stick' or 'audio'
|
||||
useBroadcast: yes # use broadcast function to find server
|
||||
|
||||
server:
|
||||
- name: "Server one"
|
||||
ip: "127.0.0.1"
|
||||
servers: # only used if useBroadcast = no
|
||||
- name: Server one
|
||||
ip: 127.0.0.1
|
||||
port: 8080
|
||||
|
||||
- name: "Server two"
|
||||
ip: "11.12.13.14"
|
||||
- name: Server two
|
||||
ip: 11.12.13.14
|
||||
port: 5000
|
||||
|
||||
# stick or audio
|
||||
inputSource:
|
||||
stick:
|
||||
device: 0
|
||||
frequency: "85.000M"
|
||||
frequency: 85.000M
|
||||
PPMError: 0
|
||||
Squelch: 0
|
||||
Gain: 100
|
||||
audio:
|
||||
audio: # not implemented yet
|
||||
|
||||
decoder:
|
||||
fms: yes
|
||||
|
|
@ -36,14 +36,3 @@ decoder:
|
|||
poc512: yes
|
||||
poc1200: yes
|
||||
poc2400: yes
|
||||
|
||||
doubleFilter:
|
||||
- name: "Filter one"
|
||||
MaxEntry: 30
|
||||
IgnoreTime: 10
|
||||
CheckMsg: no
|
||||
- name: "Filter two"
|
||||
MaxEntry: 30
|
||||
IgnoreTime: 10
|
||||
CheckMsg: no
|
||||
|
||||
|
|
|
|||
28
yaml_test.py
28
yaml_test.py
|
|
@ -1,28 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""!
|
||||
____ ____ ______ __ __ __ _____
|
||||
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
|
||||
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
|
||||
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
|
||||
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
|
||||
German BOS Information Script
|
||||
by Bastian Schroll
|
||||
"""
|
||||
|
||||
import yaml
|
||||
import pprint
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
|
||||
with open('config/client.yaml') as f:
|
||||
# use safe_load instead load
|
||||
dataMap = yaml.safe_load(f)
|
||||
|
||||
pp.pprint(dataMap)
|
||||
|
||||
|
||||
#print(dataMap["decoder"]["fms"])
|
||||
|
||||
for server in dataMap["server"]:
|
||||
print(server["ip"])
|
||||
|
||||
Loading…
Reference in a new issue