From 02efb9552aeb46888eabe74d968e020f55297fdb Mon Sep 17 00:00:00 2001 From: JHCD Date: Fri, 31 Jul 2015 19:50:27 +0200 Subject: [PATCH] reduce entries in globals.py only entries for use in more than one .py-file have to stay here... --- includes/descriptionList.py | 27 +++++++++++++++++++-------- includes/doubleFilter.py | 16 ++++++++++------ includes/filter.py | 22 +++++++++++++--------- includes/globals.py | 17 +++-------------- 4 files changed, 45 insertions(+), 37 deletions(-) diff --git a/includes/descriptionList.py b/includes/descriptionList.py index 3a5b662..7d4abdb 100644 --- a/includes/descriptionList.py +++ b/includes/descriptionList.py @@ -1,5 +1,5 @@ #!/usr/bin/python -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- """ Function to expand the dataset with a description. @@ -10,13 +10,18 @@ Function to expand the dataset with a description. """ import logging # Global logger - import csv # for loading the description files from includes import globals # Global variables from includes.helper import stringConverter +# local variables +fmsDescribtionList = {} +zveiDescribtionList = {} +ricDescribtionList = {} + + ## # # Local function will load the csv-file @@ -67,15 +72,18 @@ def loadDescriptionLists(): if globals.config.getint("FMS", "idDescribed"): logging.debug("- load FMS description list") - globals.fmsDescribtionList = loadCSV("fms", "fms") + global fmsDescribtionList + fmsDescribtionList = loadCSV("fms", "fms") if globals.config.getint("ZVEI", "idDescribed"): logging.debug("- load ZVEI description list") - globals.zveiDescribtionList = loadCSV("zvei", "zvei") + global zveiDescribtionList + zveiDescribtionList = loadCSV("zvei", "zvei") if globals.config.getint("POC", "idDescribed"): logging.debug("- load pocsag description list") - globals.ricDescribtionList = loadCSV("poc", "ric") + global ricDescribtionList + ricDescribtionList = loadCSV("poc", "ric") except: logging.error("cannot load description lists") @@ -98,11 +106,14 @@ def getDescription(typ, id): logging.debug("look up description lists") try: if typ == "FMS": - resultStr = globals.fmsDescribtionList[id] + global fmsDescribtionList + resultStr = fmsDescribtionList[id] elif typ == "ZVEI": - resultStr = globals.zveiDescribtionList[id] + global zveiDescribtionList + resultStr = zveiDescribtionList[id] elif typ == "POC": - resultStr = globals.ricDescribtionList[id] + global ricDescribtionList + resultStr = ricDescribtionList[id] else: logging.warning("Invalid Typ: %s", typ) diff --git a/includes/doubleFilter.py b/includes/doubleFilter.py index 7c6b6cb..4cd6bf4 100644 --- a/includes/doubleFilter.py +++ b/includes/doubleFilter.py @@ -1,5 +1,5 @@ #!/usr/bin/python -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- """ doubleFilter is the central function to filter out double alarms. @@ -19,6 +19,8 @@ from includes import globals # Global variables # # ListStructure [0..n] = (ID, TimeStamp, msg) # +doubleList = [] + def checkID(typ, id, msg=""): """ @@ -29,11 +31,12 @@ def checkID(typ, id, msg=""): @return: True if check was OK @return: False if double was found """ + global doubleList timestamp = int(time.time()) # Get Timestamp logging.debug("checkID: %s (%s)", id, msg) - for i in range(len(globals.doubleList)): - (xID, xTimestamp, xMsg) = globals.doubleList[i] + for i in range(len(doubleList)): + (xID, xTimestamp, xMsg) = doubleList[i] # given ID found? # return False if the first entry in double_ignore_time is found, we will not check for younger ones... if id == xID and timestamp < xTimestamp + globals.config.getint("BOSWatch", "doubleFilter_ignore_time"): @@ -59,12 +62,13 @@ def newEntry(id, msg = ""): @return: nothing """ + global doubleList timestamp = int(time.time()) # Get Timestamp - globals.doubleList.append((id, timestamp, msg.strip())) + doubleList.append((id, timestamp, msg.strip())) logging.debug("Added %s to doubleList", id) # now check if list has more than n entries: - if len(globals.doubleList) > globals.config.getint("BOSWatch", "doubleFilter_ignore_entries"): + if len(doubleList) > globals.config.getint("BOSWatch", "doubleFilter_ignore_entries"): # we have to kill the oldest one - globals.doubleList.pop(0) + doubleList.pop(0) diff --git a/includes/filter.py b/includes/filter.py index 922dfa7..7a5856b 100644 --- a/includes/filter.py +++ b/includes/filter.py @@ -1,5 +1,5 @@ #!/usr/bin/python -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- """ Functions for the RegEX filter @@ -10,22 +10,25 @@ Functions for the RegEX filter """ import logging # Global logger - import re #Regex for Filter Check from includes import globals # Global variables - from includes import converter # converter functions +# local variables +filterList = [] + + def loadFilters(): """ - load all filters from the config.ini into globals.filterList + load all filters from the config.ini into filterList @requires: Configuration has to be set in the config.ini @return: nothing """ + global filterList try: logging.debug("loading filters") # For each entry in config.ini [Filters] section @@ -37,15 +40,15 @@ def loadFilters(): if not filter[3] == "*": filter[3] = converter.freqToHz(filter[3]) - # insert splitet data into globals.filterList - globals.filterList.append({"name": key, "typ": filter[0], "dataField": filter[1], "plugin": filter[2], "freq": filter[3], "regex": filter[4]}) + # insert splitet data into filterList + filterList.append({"name": key, "typ": filter[0], "dataField": filter[1], "plugin": filter[2], "freq": filter[3], "regex": filter[4]}) except: logging.error("cannot read config file") logging.debug("cannot read config file", exc_info=True) return -def checkFilters(typ,data,plugin,freq): +def checkFilters(typ, data, plugin, freq): """ Check the Typ/Plugin combination with the RegEX filter If no filter for the combination is found, function returns True. @@ -63,12 +66,13 @@ def checkFilters(typ,data,plugin,freq): @return: nothing """ + global filterList try: logging.debug("search Filter for %s to %s at %s Hz", typ, plugin, freq) foundFilter = False - # go to all filter in globals.filterList - for i in globals.filterList: + # go to all filter in filterList + for i in filterList: # if typ/plugin/freq combination is found if i["typ"] == typ and (i["plugin"] == plugin or i['plugin'] == "*") and (i["freq"] == freq or i['freq'] == "*"): foundFilter = True diff --git a/includes/globals.py b/includes/globals.py index ad3251e..8135ec6 100644 --- a/includes/globals.py +++ b/includes/globals.py @@ -1,5 +1,5 @@ #!/usr/bin/python -# -*- coding: UTF-8 -*- +# -*- coding: utf-8 -*- """ Global variables @@ -10,23 +10,12 @@ Global variables # version info versionNr = "2.1-dev" -buildDate = "2015/07/30" +buildDate = "2015/07/31" # Global variables config = 0 script_path = "" log_path = "" -# double alarm -doubleList = [] - # pluginLoader -pluginList = {} - -# filter -filterList = [] - -# idDescribing -fmsDescribtionList = {} -zveiDescribtionList = {} -ricDescribtionList = {} \ No newline at end of file +pluginList = {} \ No newline at end of file