rename globals to globalVars

to prevent to redifine an builtin function
This commit is contained in:
Bastian Schroll 2016-10-03 11:56:27 +02:00
parent e8e870849d
commit f8fcda94b6
30 changed files with 115 additions and 115 deletions

View file

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

View file

@ -36,7 +36,7 @@ import json # for data
from threading import Thread
import pygame
import globals
import globalData
try:
#

View file

@ -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)
exit(0)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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=""):

View file

@ -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():
"""

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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