diff --git a/boswatch.py b/boswatch.py index 96c6b0c..e22d507 100755 --- a/boswatch.py +++ b/boswatch.py @@ -24,7 +24,7 @@ import os # for log mkdir import time # for time.sleep() import subprocess # for starting rtl_fm and multimon-ng -from includes import globals # Global variables +from includes import globalVars # Global variables from includes import MyTimedRotatingFileHandler # extension of TimedRotatingFileHandler from includes import signalHandler # TERM-Handler for use script as a daemon from includes import checkSubprocesses # check startup of the subprocesses diff --git a/exampleAddOns/alarmMonitorRPi/alarmMonitor.py b/exampleAddOns/alarmMonitorRPi/alarmMonitor.py index 0081bc7..d8d95c4 100644 --- a/exampleAddOns/alarmMonitorRPi/alarmMonitor.py +++ b/exampleAddOns/alarmMonitorRPi/alarmMonitor.py @@ -36,7 +36,7 @@ import json # for data from threading import Thread import pygame -import globals +import globalData try: # diff --git a/exampleAddOns/alarmMonitorRPi/displayServices.py b/exampleAddOns/alarmMonitorRPi/displayServices.py index 9074a62..f17bf50 100644 --- a/exampleAddOns/alarmMonitorRPi/displayServices.py +++ b/exampleAddOns/alarmMonitorRPi/displayServices.py @@ -14,27 +14,27 @@ alarmMonitor - displayServices # def autoTurnOffDisplay(): """ - Asynchronous function to turn of the display backlight - + Asynchronous function to turn of the display backlight + @requires: globals.showDisplay - status of backlight @requires: globals.enableDisplayUntil - given timestamp to turn off backlight @requires: globals.running - service runs as long as this is True In case of an exception the function set globals.abort to True. This will terminate the main program. - + @return: nothing @exception: SystemExit exception in case of an error """ - + import sys import time import logging import ConfigParser - import globals + import globalData logging.debug("autoTurnOffDisplay-thread started") - + try: # Running will be set to False if main program is shutting down while globals.running == True: @@ -59,12 +59,12 @@ def autoTurnOffDisplay(): # # Only works as an asynchronous thread # will call "exit(0)" when function is finished -# +# def eventHandler(): """ Asynchronous function to handle pygames events in particular the touchscreen events - + @requires: globals.showDisplay - status of backlight @requires: globals.enableDisplayUntil - timestamp to turn off backlight @requires: globals.running - service runs as long as this is True @@ -72,7 +72,7 @@ def eventHandler(): In case of an exception the function set globals.abort to True. This will terminate the main program. - + @return: nothing @exception: SystemExit exception in case of an error """ @@ -81,10 +81,10 @@ def eventHandler(): import logging import ConfigParser import pygame - import globals + import globalData logging.debug("eventHandler-thread started") - + try: clock = pygame.time.Clock() @@ -93,13 +93,13 @@ def eventHandler(): # This limits the while loop to a max of 2 times per second. # Leave this out and we will use all CPU we can. clock.tick(2) - + # current time for this loop: curtime = int(time.time()) for event in pygame.event.get(): # event-handler for QUIT - if event.type == pygame.QUIT: + if event.type == pygame.QUIT: globals.running = False # if touchscreen pressed @@ -109,7 +109,7 @@ def eventHandler(): # touching the screen will stop alarmSound in every case pygame.mixer.stop() - + # touching the dark display will turn it on for n sec if globals.showDisplay == False: logging.info("turn ON display") @@ -136,7 +136,7 @@ def eventHandler(): globals.navigation = "alarmPage" ## end if showDisplay ## end if event MOUSEBUTTONDOWN - ## end for event + ## end for event except: logging.error("unknown error in eventHandler-thread") logging.debug("unknown error in eventHandler-thread", exc_info=True) @@ -146,8 +146,8 @@ def eventHandler(): finally: logging.debug("exit eventHandler-thread") exit(0) - - + + # # Only works as an asynchronous thread # will call "exit(0)" when function is finished @@ -155,21 +155,21 @@ def eventHandler(): def displayPainter(): """ Asynchronous function to build the display content - + @requires: globals.showDisplay - status of backlight @requires: globals.enableDisplayUntil - given timestamp when backlight will turned off @requires: globals.running - service runs as long as this is True @requires: globals.data - data of the last alarm - @requires: globals.lastAlarm - timestamp of the last processing (see alarmRICs and keepAliveRICs) + @requires: globals.lastAlarm - timestamp of the last processing (see alarmRICs and keepAliveRICs) @requires: configuration has to be set in the config.ini In case of an exception the function set globals.abort to True. This will terminate the main program. - + @return: nothing @exception: SystemExit exception in case of an error """ - + import sys import time import logging @@ -178,10 +178,10 @@ def displayPainter(): import pygame from wrapline import wrapline from roundrects import round_rect - import globals + import globalData logging.debug("displayPainter-thread called") - + try: # use GPIO pin numbering convention GPIO.setmode(GPIO.BCM) @@ -197,41 +197,41 @@ def displayPainter(): # disable mouse cursor pygame.mouse.set_visible(False) - + #define fonts fontHeader = pygame.font.Font(None, 30) fontHeader.set_bold(True) fontHeader.set_underline(True) fontTime = pygame.font.Font(None, 15) - + fontRIC = pygame.font.Font(None, 30) fontRIC.set_bold(True) fontMsg = pygame.font.Font(None, 20) fontHistory = pygame.font.Font(None, 15) - + fontStatus = pygame.font.Font(None, 20) fontStatus.set_bold(True) fontStatusContent = pygame.font.Font(None, 20) fontButton = pygame.font.Font(None, 20) - + clock = pygame.time.Clock() - + # Build Lists out of config-entries functionCharTestAlarm = [x.strip() for x in globals.config.get("AlarmMonitor","functionCharTestAlarm").replace(";", ",").split(",")] logging.debug("displayPainter-thread started") - + # Running will be set to False if main program is shutting down while globals.running == True: # This limits the while loop to a max of 2 times per second. # Leave this out and we will use all CPU we can. clock.tick(2) - + # current time for this loop: curtime = int(time.time()) - + if globals.showDisplay == True: # Enable LCD display GPIO.output(globals.config.getint("Display","GPIOPinForBacklight"), GPIO.HIGH) @@ -246,7 +246,7 @@ def displayPainter(): (width, height) = fontHeader.size("Alarm-Monitor") x = (int(globals.config.getint("Display","displayWidth")) - width)/2 screen.blit(header, (x, 20)) - + # show time of last alarm if globals.lastAlarm > 0: try: @@ -270,7 +270,7 @@ def displayPainter(): logging.debug("unknown error in lastAlarm", exc_info=True) pass ## end if globals.lastAlarm > 0 - + # show remaining time before display will be turned off: restZeit = globals.enableDisplayUntil - curtime +1 zeit = fontTime.render(str(restZeit), 1, pygame.Color(globals.config.get("AlarmMonitor","colourDimGrey"))) @@ -286,9 +286,9 @@ def displayPainter(): y = 50 for data in reversed(globals.alarmHistory): # Layout: - # Date Description + # Date Description # Time Msg - + # Prepare date/time block dateString = time.strftime("%d.%m.%y", time.localtime(data['timestamp'])) timeString = time.strftime("%H:%M:%S", time.localtime(data['timestamp'])) @@ -297,7 +297,7 @@ def displayPainter(): else: (shifting, height) = fontHistory.size(timeString) shifting += 5 - + # get colour if data['functionChar'] in functionCharTestAlarm: colour = globals.config.get("AlarmMonitor","colourYellow") @@ -317,7 +317,7 @@ def displayPainter(): y += height except KeyError: pass - + # Paint Msg try: textLines = wrapline(data['msg'].replace("*", " * "), fontHistory, (globals.config.getint("Display","displayWidth") - shifting - 40)) @@ -327,16 +327,16 @@ def displayPainter(): y += height except KeyError: pass - + # line spacing for next dataset y += 2 - + ## end for globals.alarmHistory - + except KeyError: pass ## end if globals.navigation == "historyPage" - + elif globals.navigation == "statusPage": (width, height) = fontStatusContent.size("Anzahl Test-Alarme:") y = 70 @@ -347,7 +347,7 @@ def displayPainter(): screen.blit(title, (20, y)) screen.blit(content, (20 +x, y)) y += height + 10 - + # Last Alarm title = fontStatusContent.render("Letzte Nachricht:", 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite"))) if globals.lastAlarm > 0: @@ -371,19 +371,19 @@ def displayPainter(): screen.blit(title, (20, y)) screen.blit(content, (20 +x, y)) y += height + 10 - + # Number of DAU-Msgs title = fontStatusContent.render("Anzahl DAU-Tests:", 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite"))) content = fontStatusContent.render(str(globals.countKeepAlive), 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey"))) screen.blit(title, (20, y)) screen.blit(content, (20 +x, y)) y += height + 10 - + ## end if globals.navigation == "statusPage" - + else: y = 50 - + # Paint Date/Time try: dateTimeString = time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(globals.data['timestamp'])) @@ -394,7 +394,7 @@ def displayPainter(): y += height + 10 except KeyError: pass - + # Paint Description try: textLines = wrapline(globals.data['description'], fontRIC, (globals.config.getint("Display","displayWidth") - 40)) @@ -405,7 +405,7 @@ def displayPainter(): y += height + 5 except KeyError: pass - + # Paint Msg try: y += 10 @@ -418,19 +418,19 @@ def displayPainter(): except KeyError: pass ## end if default navigation - + # paint navigation buttons buttonWidth = 80 buttonHeight = 25 buttonY = globals.config.getint("Display","displayHeight") - buttonHeight - 2 - + round_rect(screen, ( 20, buttonY, buttonWidth, buttonHeight), pygame.Color(globals.config.get("AlarmMonitor","colourDimGrey")), 10, 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey"))) buttonText = fontButton.render("Verlauf", 1, pygame.Color(globals.config.get("AlarmMonitor","colourBlack"))) (width, height) = fontButton.size("Verlauf") textX = 20 + (buttonWidth - width)/2 textY = buttonY + (buttonHeight - height)/2 screen.blit(buttonText, (textX, textY)) - + round_rect(screen, (120, buttonY, buttonWidth, buttonHeight), pygame.Color(globals.config.get("AlarmMonitor","colourDimGrey")), 10, 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey"))) buttonText = fontButton.render("Status", 1, pygame.Color(globals.config.get("AlarmMonitor","colourBlack"))) (width, height) = fontButton.size("Status") @@ -444,12 +444,12 @@ def displayPainter(): textX = 220 + (buttonWidth - width)/2 textY = buttonY + (buttonHeight - height)/2 screen.blit(buttonText, (textX, textY)) - + ## end if globals.showDisplay == True else: GPIO.output(globals.config.getint("Display","GPIOPinForBacklight"), GPIO.LOW) - + # Update display... pygame.display.update() ## end while globals.running == True @@ -465,4 +465,4 @@ def displayPainter(): GPIO.output(globals.config.getint("Display","GPIOPinForBacklight"), GPIO.LOW) GPIO.cleanup() pygame.quit() - exit(0) \ No newline at end of file + exit(0) diff --git a/exampleAddOns/alarmMonitorRPi/globals.py b/exampleAddOns/alarmMonitorRPi/globalData.py similarity index 93% rename from exampleAddOns/alarmMonitorRPi/globals.py rename to exampleAddOns/alarmMonitorRPi/globalData.py index 2ca83f4..b80bbbd 100644 --- a/exampleAddOns/alarmMonitorRPi/globals.py +++ b/exampleAddOns/alarmMonitorRPi/globalData.py @@ -1,35 +1,35 @@ -#!/usr/bin/python -# -*- coding: UTF-8 -*- -# - -# configparser (Configparser) -config = 0 - -# control-params (Boolean) -running = True -showDisplay = False -abort = False - -# color of display-boarder -screenBackground = "" - -# navigation = "" -navigation = "alarmPage" - -# enable display until (Timestamp) -enableDisplayUntil = 0 - -# data-structure (Dict) -data = {} - -# last alarm shown (Timestamp) -lastAlarm = 0 - -# alarm history (List) -alarmHistory = [] - -# statusPage -startTime = 0 -countAlarm = 0 -countTestAlarm = 0 +#!/usr/bin/python +# -*- coding: UTF-8 -*- +# + +# configparser (Configparser) +config = 0 + +# control-params (Boolean) +running = True +showDisplay = False +abort = False + +# color of display-boarder +screenBackground = "" + +# navigation = "" +navigation = "alarmPage" + +# enable display until (Timestamp) +enableDisplayUntil = 0 + +# data-structure (Dict) +data = {} + +# last alarm shown (Timestamp) +lastAlarm = 0 + +# alarm history (List) +alarmHistory = [] + +# statusPage +startTime = 0 +countAlarm = 0 +countTestAlarm = 0 countKeepAlive = 0 \ No newline at end of file diff --git a/includes/alarmHandler.py b/includes/alarmHandler.py index 464fcd4..ccd8368 100644 --- a/includes/alarmHandler.py +++ b/includes/alarmHandler.py @@ -13,7 +13,7 @@ Handler for the filter and plugins at an alarm import logging # Global logger import time # timestamp -from includes import globals # Global variables +from includes import globalVars # Global variables ## # diff --git a/includes/checkSubprocesses.py b/includes/checkSubprocesses.py index 43c91bd..e48aa25 100644 --- a/includes/checkSubprocesses.py +++ b/includes/checkSubprocesses.py @@ -10,7 +10,7 @@ Used in boswatch.py at startup and designated for watching-service import logging -from includes import globals # Global variables +from includes import globalVars # Global variables def checkRTL(): diff --git a/includes/decoders/fms.py b/includes/decoders/fms.py index dd606bb..0a04df7 100644 --- a/includes/decoders/fms.py +++ b/includes/decoders/fms.py @@ -12,7 +12,7 @@ FMS Decoder import logging # Global logger import re # Regex for validation -from includes import globals # Global variables +from includes import globalVars # Global variables from includes import doubleFilter # double alarm filter ## diff --git a/includes/decoders/poc.py b/includes/decoders/poc.py index 8b3d727..4b20d56 100644 --- a/includes/decoders/poc.py +++ b/includes/decoders/poc.py @@ -13,7 +13,7 @@ POCSAG Decoder import logging # Global logger import re # Regex for validation -from includes import globals # Global variables +from includes import globalVars # Global variables from includes import doubleFilter # double alarm filter ## diff --git a/includes/decoders/zvei.py b/includes/decoders/zvei.py index 652df5a..7258428 100644 --- a/includes/decoders/zvei.py +++ b/includes/decoders/zvei.py @@ -12,7 +12,7 @@ ZVEI Decoder import logging # Global logger import re # Regex for validation -from includes import globals # Global variables +from includes import globalVars # Global variables from includes import doubleFilter # double alarm filter ## diff --git a/includes/descriptionList.py b/includes/descriptionList.py index 7d4abdb..b81e8ab 100644 --- a/includes/descriptionList.py +++ b/includes/descriptionList.py @@ -12,7 +12,7 @@ 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 import globalVars # Global variables from includes.helper import stringConverter diff --git a/includes/doubleFilter.py b/includes/doubleFilter.py index 4cd6bf4..8975208 100644 --- a/includes/doubleFilter.py +++ b/includes/doubleFilter.py @@ -14,7 +14,7 @@ and the time ignoring the id in case of a double alarm import logging # Global logger import time # timestamp for doublealarm -from includes import globals # Global variables +from includes import globalVars # Global variables # # ListStructure [0..n] = (ID, TimeStamp, msg) diff --git a/includes/globals.py b/includes/globalVars.py similarity index 100% rename from includes/globals.py rename to includes/globalVars.py diff --git a/includes/helper/configHandler.py b/includes/helper/configHandler.py index 9a6cf59..52dab13 100644 --- a/includes/helper/configHandler.py +++ b/includes/helper/configHandler.py @@ -10,7 +10,7 @@ for direct use in plugins to save code """ import logging -from includes import globals +from includes import globalVars def checkConfig(section=""): diff --git a/includes/pluginLoader.py b/includes/pluginLoader.py index 95350cf..d8f474c 100644 --- a/includes/pluginLoader.py +++ b/includes/pluginLoader.py @@ -14,7 +14,7 @@ import imp import os from ConfigParser import NoOptionError # we need this exception -from includes import globals # Global variables +from includes import globalVars # Global variables def loadPlugins(): """ diff --git a/includes/regexFilter.py b/includes/regexFilter.py index 3061e26..b2a6745 100644 --- a/includes/regexFilter.py +++ b/includes/regexFilter.py @@ -12,7 +12,7 @@ Functions for the RegEX filter import logging # Global logger import re #Regex for Filter Check -from includes import globals # Global variables +from includes import globalVars # Global variables from includes.helper import freqConverter # converter functions diff --git a/includes/shellHeader.py b/includes/shellHeader.py index 8510da5..e12f018 100644 --- a/includes/shellHeader.py +++ b/includes/shellHeader.py @@ -10,7 +10,7 @@ Shows the header in shell if quiet mode is not active @requires: none """ -from includes import globals +from includes import globalVars def printHeader(args): """ diff --git a/plugins/BosMon/BosMon.py b/plugins/BosMon/BosMon.py index 0e80231..0045407 100644 --- a/plugins/BosMon/BosMon.py +++ b/plugins/BosMon/BosMon.py @@ -17,7 +17,7 @@ import httplib #for the HTTP request import urllib #for the HTTP request with parameters import base64 #for the HTTP request with User/Password -from includes import globals # Global variables +from includes import globalVars # Global variables from includes.helper import configHandler diff --git a/plugins/FFAgent/FFAgent.py b/plugins/FFAgent/FFAgent.py index 28e74c0..dffcb71 100644 --- a/plugins/FFAgent/FFAgent.py +++ b/plugins/FFAgent/FFAgent.py @@ -15,7 +15,7 @@ import hmac, hashlib import json, requests import string -from includes import globals # Global variables +from includes import globalVars # Global variables from includes.helper import timeHandler from includes.helper import configHandler diff --git a/plugins/MySQL/MySQL.py b/plugins/MySQL/MySQL.py index defce9b..303549d 100644 --- a/plugins/MySQL/MySQL.py +++ b/plugins/MySQL/MySQL.py @@ -16,7 +16,7 @@ import logging # Global logger import mysql import mysql.connector -from includes import globals # Global variables +from includes import globalVars # Global variables from includes.helper import configHandler diff --git a/plugins/Pushover/Pushover.py b/plugins/Pushover/Pushover.py index ca33d29..79941b0 100644 --- a/plugins/Pushover/Pushover.py +++ b/plugins/Pushover/Pushover.py @@ -13,7 +13,7 @@ import time import logging # Global logger import httplib #for the HTTP request import urllib -from includes import globals # Global variables +from includes import globalVars # Global variables from includes.helper import timeHandler from includes.helper import configHandler diff --git a/plugins/README.md b/plugins/README.md index 073a2b3..48f5f81 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -66,7 +66,7 @@ test2 = 123456 #### 3.2 Read data from config.ini To read yout configuration data you must import the `globals.py` where the global config-object is located: ```python -from includes import globals # Global variables +from includes import globalVars # Global variables ``` Now you can get your configuration data with: diff --git a/plugins/SMS/SMS.py b/plugins/SMS/SMS.py index cc826c2..eb56af3 100644 --- a/plugins/SMS/SMS.py +++ b/plugins/SMS/SMS.py @@ -18,7 +18,7 @@ config.ini # Imports # import logging # Global logger -from includes import globals # Global variables +from includes import globalVars # Global variables # Helper function, uncomment to use #from includes.helper import timeHandler diff --git a/plugins/Sms77/Sms77.py b/plugins/Sms77/Sms77.py index 8ad1b2e..5859bf7 100644 --- a/plugins/Sms77/Sms77.py +++ b/plugins/Sms77/Sms77.py @@ -13,7 +13,7 @@ import time import logging # Global logger import httplib #for the HTTP request import urllib -from includes import globals # Global variables +from includes import globalVars # Global variables from includes.helper import timeHandler from includes.helper import configHandler diff --git a/plugins/Telegram/Telegram.py b/plugins/Telegram/Telegram.py index 46a1c8b..1922042 100644 --- a/plugins/Telegram/Telegram.py +++ b/plugins/Telegram/Telegram.py @@ -12,7 +12,7 @@ Plugin to send FMS-, ZVEI- and POCSAG-messages via Telegram # import logging # Global logger import httplib, urllib, telegram, googlemaps -from includes import globals # Global variables +from includes import globalVars # Global variables # Helper function, uncomment to use from includes.helper import configHandler diff --git a/plugins/eMail/eMail.py b/plugins/eMail/eMail.py index 8304261..e6ea139 100644 --- a/plugins/eMail/eMail.py +++ b/plugins/eMail/eMail.py @@ -16,7 +16,7 @@ from email.mime.text import MIMEText # Import the email modules we'll need from email.utils import formatdate # need for confirm to RFC2822 standard from email.utils import make_msgid # need for confirm to RFC2822 standard -from includes import globals # Global variables +from includes import globalVars # Global variables from includes.helper import timeHandler # helper function from includes.helper import configHandler # helper function diff --git a/plugins/firEmergency/firEmergency.py b/plugins/firEmergency/firEmergency.py index 2b287a1..0a1522b 100644 --- a/plugins/firEmergency/firEmergency.py +++ b/plugins/firEmergency/firEmergency.py @@ -15,7 +15,7 @@ firEmergency configuration: import logging # Global logger import socket -from includes import globals # Global variables +from includes import globalVars # Global variables from includes.helper import configHandler from includes.helper import stringConverter diff --git a/plugins/httpRequest/httpRequest.py b/plugins/httpRequest/httpRequest.py index 41d71bc..e7074b2 100644 --- a/plugins/httpRequest/httpRequest.py +++ b/plugins/httpRequest/httpRequest.py @@ -14,7 +14,7 @@ import logging # Global logger import httplib #for the HTTP request from urlparse import urlparse #for split the URL into url and path -from includes import globals # Global variables +from includes import globalVars # Global variables from includes.helper import wildcardHandler from includes.helper import configHandler diff --git a/plugins/jsonSocket/jsonSocket.py b/plugins/jsonSocket/jsonSocket.py index 84f256a..10d66fd 100644 --- a/plugins/jsonSocket/jsonSocket.py +++ b/plugins/jsonSocket/jsonSocket.py @@ -14,7 +14,7 @@ import logging # Global logger import socket # for connection import json # for data-transfer -from includes import globals # Global variables +from includes import globalVars # Global variables from includes.helper import configHandler diff --git a/plugins/notifyMyAndroid/notifyMyAndroid.py b/plugins/notifyMyAndroid/notifyMyAndroid.py index 43a4415..0f2c366 100644 --- a/plugins/notifyMyAndroid/notifyMyAndroid.py +++ b/plugins/notifyMyAndroid/notifyMyAndroid.py @@ -16,7 +16,7 @@ import json # for data-transfer import csv # for loading the APIKeys -from includes import globals # Global variables +from includes import globalVars # Global variables from includes.helper import configHandler from includes.helper import timeHandler diff --git a/plugins/template/template.py b/plugins/template/template.py index 962791c..46cc104 100644 --- a/plugins/template/template.py +++ b/plugins/template/template.py @@ -17,7 +17,7 @@ For more information take a look into the other plugins # Imports # import logging # Global logger -from includes import globals # Global variables +from includes import globalVars # Global variables # Helper function, uncomment to use #from includes.helper import timeHandler