2015-07-01 14:11:11 +02:00
|
|
|
#!/usr/bin/python
|
2015-07-13 10:19:45 +02:00
|
|
|
# -*- coding: UTF-8 -*-
|
2015-07-01 14:11:11 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
|
|
"""
|
2015-07-02 15:16:24 +02:00
|
|
|
little Helper to replace fast and easy the standard wildcards
|
|
|
|
|
for direct use in plugins to save code
|
2015-07-01 14:11:11 +02:00
|
|
|
|
2015-07-02 15:16:24 +02:00
|
|
|
@author: Bastian Schroll
|
2015-07-28 19:44:14 +02:00
|
|
|
@author: Jens Herrmann
|
2015-07-01 14:11:11 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import logging
|
2015-07-02 11:51:28 +02:00
|
|
|
|
2016-11-01 10:18:47 +01:00
|
|
|
from includes import globalVars
|
|
|
|
|
|
2015-07-02 15:16:24 +02:00
|
|
|
from includes.helper import timeHandler
|
2015-07-02 11:51:28 +02:00
|
|
|
|
|
|
|
|
|
2015-07-28 19:44:14 +02:00
|
|
|
def replaceWildcards(text, data, lineBrakeAllowed=False):
|
2015-07-02 11:51:28 +02:00
|
|
|
"""
|
|
|
|
|
Replace all official Wildcards with the Information from the data[] var
|
|
|
|
|
|
|
|
|
|
@type text: string
|
|
|
|
|
@param text: Input text with wildcards
|
|
|
|
|
@type data: map
|
2016-10-02 12:38:47 +02:00
|
|
|
@param data: map of data (structure see readme.md in plugin folder)
|
2015-07-28 19:44:14 +02:00
|
|
|
@type lineBrakeAllowed: Boolean
|
|
|
|
|
@param lineBrakeAllowed: switch to allow lineBreak (%BR%) as wildcard
|
2015-07-02 11:51:28 +02:00
|
|
|
|
|
|
|
|
@return: text with replaced wildcards
|
|
|
|
|
@exception: Exception if Error at replace
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
# replace date and time wildcards
|
2015-07-31 19:09:27 +02:00
|
|
|
text = text.replace("%TIME%", timeHandler.getTime(data["timestamp"])).replace("%DATE%", timeHandler.getDate(data["timestamp"]))
|
2016-10-02 21:28:04 +02:00
|
|
|
|
2015-07-28 19:44:14 +02:00
|
|
|
# replace some special chars
|
|
|
|
|
if lineBrakeAllowed == True:
|
|
|
|
|
text = text.replace("%BR%", "\r\n")
|
|
|
|
|
text = text.replace("%LPAR%", "(")
|
|
|
|
|
text = text.replace("%RPAR%", ")")
|
2015-07-02 11:51:28 +02:00
|
|
|
|
|
|
|
|
# replace FMS data
|
|
|
|
|
if "fms" in data: text = text.replace("%FMS%", data["fms"])
|
|
|
|
|
if "status" in data: text = text.replace("%STATUS%", data["status"])
|
|
|
|
|
if "direction" in data: text = text.replace("%DIR%", data["direction"])
|
|
|
|
|
if "directionText" in data: text = text.replace("%DIRT%", data["directionText"])
|
|
|
|
|
if "tsi" in data: text = text.replace("%TSI%", data["tsi"])
|
|
|
|
|
|
|
|
|
|
# replace ZVEI data
|
|
|
|
|
if "zvei" in data: text = text.replace("%ZVEI%", data["zvei"])
|
|
|
|
|
|
|
|
|
|
# replace POC data
|
|
|
|
|
if "ric" in data: text = text.replace("%RIC%", data["ric"])
|
|
|
|
|
if "function" in data: text = text.replace("%FUNC%", data["function"])
|
|
|
|
|
if "functionChar" in data: text = text.replace("%FUNCCHAR%", data["functionChar"])
|
2016-11-01 10:18:47 +01:00
|
|
|
if data["function"] == "1": text = text.replace("%FUNCTEXT%", globalVars.config.get("POC","rica"))
|
|
|
|
|
if data["function"] == "2": text = text.replace("%FUNCTEXT%", globalVars.config.get("POC","ricb"))
|
|
|
|
|
if data["function"] == "3": text = text.replace("%FUNCTEXT%", globalVars.config.get("POC","ricc"))
|
|
|
|
|
if data["function"] == "4": text = text.replace("%FUNCTEXT%", globalVars.config.get("POC","ricd"))
|
2015-07-02 11:51:28 +02:00
|
|
|
if "msg" in data: text = text.replace("%MSG%", data["msg"])
|
|
|
|
|
if "bitrate" in data: text = text.replace("%BITRATE%", str(data["bitrate"]))
|
|
|
|
|
|
|
|
|
|
# replace description (exists by all)
|
|
|
|
|
if "description" in data: text = text.replace("%DESCR%", data["description"])
|
|
|
|
|
|
2015-07-07 13:17:18 +02:00
|
|
|
logging.debug("wildcards been replaced")
|
|
|
|
|
|
2015-07-02 11:51:28 +02:00
|
|
|
return text
|
|
|
|
|
|
|
|
|
|
except:
|
2015-07-08 09:42:52 +02:00
|
|
|
logging.warning("error in wildcard replacement")
|
|
|
|
|
logging.debug("error in wildcard replacement", exc_info=True)
|