This commit is contained in:
Florian 2023-03-21 09:30:13 -07:00 committed by GitHub
commit af41b132a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,12 +18,15 @@ GitHUB: https://github.com/Schrolli91/BOSWatch
import logging
import logging.handlers
import argparse # for parse the args
import ConfigParser # for parse the config file
import os # for log mkdir
import sys # for py version
import time # for time.sleep()
import subprocess # for starting rtl_fm and multimon-ng
import argparse # for parse the args
import ConfigParser # for parse the config file
import os # for log mkdir
import time # for time.sleep()
import subprocess # for starting rtl_fm and multimon-ng
## New for reloading csv
import pyinotify
import threading
from includes import globalVars # Global variables
from includes import MyTimedRotatingFileHandler # extension of TimedRotatingFileHandler
@ -68,6 +71,42 @@ except:
print "ERROR: cannot parsing the arguments"
exit(1)
#
# define a function for observing csv-files
#
def csv_watch(dir):
wm = pyinotify.WatchManager()
mask = pyinotify.IN_CREATE | pyinotify.IN_MODIFY
t = threading.currentThread()
logging.debug("CSV-Watch-Dir: %s", dir)
class EventHandler(pyinotify.ProcessEvent):
def process_IN_CREATE(self, event):
try:
logging.debug("Reloading csv...")
if globalVars.config.getboolean("FMS","idDescribed") or globalVars.config.getboolean("ZVEI","idDescribed") or globalVars.config.getboolean("POC","idDescribed"):
from includes import descriptionList
descriptionList.loadDescriptionLists()
except:
# It's an error, but we could work without that stuff...
logging.error("cannot reload description lists")
logging.debug("cannot reload description lists", exc_info=True)
def process_IN_MODIFY(self, event):
try:
logging.debug("Reloading csv...")
if globalVars.config.getboolean("FMS","idDescribed") or globalVars.config.getboolean("ZVEI","idDescribed") or globalVars.config.getboolean("POC","idDescribed"):
from includes import descriptionList
descriptionList.loadDescriptionLists()
except:
# It's an error, but we could work without that stuff...
logging.error("cannot reload description lists")
logging.debug("cannot reload description lists", exc_info=True)
handler = EventHandler()
notifier = pyinotify.Notifier(wm, handler)
wdd = wm.add_watch(dir, mask, rec=True)
notifier.loop()
#
# Main program
@ -158,14 +197,23 @@ try:
logging.error("cannot clear Logfiles")
logging.debug("cannot clear Logfiles", exc_info=True)
#
# start a new oberserver.thread
#
try:
thread = threading.Thread(target = csv_watch, args = (globalVars.script_path+'/csv/',))
thread.daemon = True # start it as daemon to avoid trouble when exiting Boswatch
thread.start()
logging.debug("Thread for csv-watch started")
except:
logging.error("Unable to start thread to observe csv-directory.", exc_info=True)
#
# For debug display/log args
#
try:
logging.debug("SW Version: %s",globalVars.versionNr)
logging.debug("Branch: %s",globalVars.branch)
logging.debug("Build Date: %s",globalVars.buildDate)
logging.debug("Python Vers: %s",sys.version)
logging.debug("BOSWatch given arguments")
if args.test:
logging.debug(" - Test-Mode!")
@ -225,9 +273,6 @@ try:
configHandler.checkConfig("FMS")
configHandler.checkConfig("ZVEI")
configHandler.checkConfig("POC")
configHandler.checkConfig("Plugins")
configHandler.checkConfig("Filters")
#NMAHandler is outputed below
except:
# we couldn't work without config -> exit
logging.critical("cannot read config file")
@ -248,7 +293,6 @@ try:
logging.error("cannot set loglevel of fileHandler")
logging.debug("cannot set loglevel of fileHandler", exc_info=True)
# initialization was fine, continue with main program...
#
@ -380,7 +424,7 @@ try:
logging.info("Testdata: %s", testData.rstrip(' \t\n\r'))
from includes import decoder
decoder.decode(freqConverter.freqToHz(args.freq), testData)
#time.sleep(1)
time.sleep(5)
logging.debug("test finished")
except KeyboardInterrupt: