Make configuration section optional

This commit is contained in:
Marco Schotthöfer 2021-01-26 13:39:40 +01:00
parent 13d76ceab9
commit 1fc2980f6d
2 changed files with 22 additions and 21 deletions

View file

@ -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).

View file

@ -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)