From 1fc2980f6d8a0b6214325c9cfde9c899aad33873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Schotth=C3=B6fer?= Date: Tue, 26 Jan 2021 13:39:40 +0100 Subject: [PATCH] Make configuration section optional --- config/config.template.ini | 2 +- includes/locationCoordinates.py | 41 +++++++++++++++++---------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/config/config.template.ini b/config/config.template.ini index c097993..8c4ed23 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -127,7 +127,7 @@ geo_enable = 0 geo_format = #C(\d{2})(\d{5}),(\d{2})(\d{5})# geo_order = LON, lon, LAT, lat -[LocationCoordinates] +#[LocationCoordinates] # Regex Coordinate replacement (only for POC) # All fields in data structure can be used, also dynamically added fields that have been evaluated in "schemaPOCMsg". # Multiple search criteria can be given, then all of them must be hit (AND-condition). diff --git a/includes/locationCoordinates.py b/includes/locationCoordinates.py index ef95ecd..f5a18c9 100644 --- a/includes/locationCoordinates.py +++ b/includes/locationCoordinates.py @@ -20,27 +20,28 @@ filterList = [] def loadFilters(): try: - logging.debug("Loading location coordinates") - - for key,val in globalVars.config.items("LocationCoordinates"): - logging.debug(" - %s = %s", key, val) - filterData = val.split(";") - - # at least 3 items needed (field1;pattern1;lat,lon), and in any case an uneven count of items - if len(filterData) < 3 and len(filterData) % 2 == 0: - logging.debug("Invalid argument count; skipping") - else: - # first store all regular expressions in list - filterItem = [] - i = 0 - - while i < len(filterData) - 2: - filterItem.append({"field": filterData[i], "pattern": filterData[i+1]}) + if globalVars.config.has_section("LocationCoordinates"): + logging.debug("Loading location coordinates") + + for key,val in globalVars.config.items("LocationCoordinates"): + logging.debug(" - %s = %s", key, val) + filterData = val.split(";") + + # at least 3 items needed (field1;pattern1;lat,lon), and in any case an uneven count of items + if len(filterData) < 3 and len(filterData) % 2 == 0: + logging.debug("Invalid argument count; skipping") + else: + # first store all regular expressions in list + filterItem = [] + i = 0 - # step to next field - i += 2 - # then transfer to filterList; include coordinates - filterList.append({"name": key, "filterItem": filterItem, "coordinates": filterData[len(filterData) - 1]}) + while i < len(filterData) - 2: + filterItem.append({"field": filterData[i], "pattern": filterData[i+1]}) + + # step to next field + i += 2 + # then transfer to filterList; include coordinates + filterList.append({"name": key, "filterItem": filterItem, "coordinates": filterData[len(filterData) - 1]}) except: logging.error("cannot read config file") logging.debug("cannot read config file", exc_info=True)