BOSWatch 3
Python Script to receive and decode German BOS Information with rtl_fm and multimon-NG
 
Loading...
Searching...
No Matches
module.moduleBase.ModuleBase Class Reference

Main module class. More...

Public Member Functions

def __init__ (self, moduleName, config)
 init preload some needed locals and then call onLoad() directly
 
def onLoad (self)
 Called by import of the module can be inherited.
 
def doWork (self, bwPacket)
 Called module run can be inherited.
 
def onUnload (self)
 Called on shutdown of boswatch can be inherited.
 

Static Public Member Functions

def registerWildcard (newWildcard, bwPacketField)
 Register a new wildcard.
 

Data Fields

 config
 

Protected Member Functions

def _cleanup (self)
 Cleanup routine calls onUnload() directly.
 
def _run (self, bwPacket)
 start an run of the module.
 
def _getStatistics (self)
 Returns statistical information's from last module run.
 

Protected Attributes

 _moduleName
 
 _cumTime
 
 _moduleTime
 
 _runCount
 
 _moduleErrorCount
 

Static Protected Attributes

list _modulesActive = []
 

Detailed Description

Main module class.

Constructor & Destructor Documentation

◆ __init__()

def module.moduleBase.ModuleBase.__init__ (   self,
  moduleName,
  config 
)

init preload some needed locals and then call onLoad() directly

Reimplemented in module.descriptor.BoswatchModule, module.filter.doubleFilter.BoswatchModule, module.filter.modeFilter.BoswatchModule, module.filter.regexFilter.BoswatchModule, module.geocoding.BoswatchModule, and module.template_module.BoswatchModule.

31 def __init__(self, moduleName, config):
32 r"""!init preload some needed locals and then call onLoad() directly"""
33 self._moduleName = moduleName
34 self.config = config
35 self._modulesActive.append(self)
36
37 # for time counting
38 self._cumTime = 0
39 self._moduleTime = 0
40
41 # for statistics
42 self._runCount = 0
43 self._moduleErrorCount = 0
44
45 logging.debug("[%s] onLoad()", moduleName)
46 self.onLoad()
47

Member Function Documentation

◆ _cleanup()

def module.moduleBase.ModuleBase._cleanup (   self)
protected

Cleanup routine calls onUnload() directly.

48 def _cleanup(self):
49 r"""!Cleanup routine calls onUnload() directly"""
50 logging.debug("[%s] onUnload()", self._moduleName)
51 self._modulesActive.remove(self)
52 self.onUnload()
53

◆ _run()

def module.moduleBase.ModuleBase._run (   self,
  bwPacket 
)
protected

start an run of the module.

    @param bwPacket: A BOSWatch packet instance
    @return bwPacket or False
54 def _run(self, bwPacket):
55 r"""!start an run of the module.
56
57 @param bwPacket: A BOSWatch packet instance
58 @return bwPacket or False"""
59 self._runCount += 1
60 logging.debug("[%s] run #%d", self._moduleName, self._runCount)
61
62 tmpTime = time.time()
63 try:
64 logging.debug("[%s] doWork()", self._moduleName)
65 bwPacket = self.doWork(bwPacket)
66 except:
67 self._moduleErrorCount += 1
68 logging.exception("[%s] alarm error", self._moduleName)
69 self._moduleTime = time.time() - tmpTime
70
71 self._cumTime += self._moduleTime
72
73 logging.debug("[%s] took %0.3f seconds", self._moduleName, self._moduleTime)
74
75 return bwPacket
76

◆ _getStatistics()

def module.moduleBase.ModuleBase._getStatistics (   self)
protected

Returns statistical information's from last module run.

    @return Statistics as pyton dict
77 def _getStatistics(self):
78 r"""!Returns statistical information's from last module run
79
80 @return Statistics as pyton dict"""
81 stats = {"type": "module",
82 "runCount": self._runCount,
83 "cumTime": self._cumTime,
84 "moduleTime": self._moduleTime,
85 "moduleErrorCount": self._moduleErrorCount}
86 return stats
87

◆ onLoad()

def module.moduleBase.ModuleBase.onLoad (   self)

Called by import of the module can be inherited.

Reimplemented in module.descriptor.BoswatchModule, module.filter.doubleFilter.BoswatchModule, module.filter.modeFilter.BoswatchModule, module.filter.regexFilter.BoswatchModule, and module.template_module.BoswatchModule.

88 def onLoad(self):
89 r"""!Called by import of the module
90 can be inherited"""
91 pass
92

◆ doWork()

def module.moduleBase.ModuleBase.doWork (   self,
  bwPacket 
)

Called module run can be inherited.

Parameters
bwPacketbwPacket instance

Reimplemented in module.descriptor.BoswatchModule, module.filter.doubleFilter.BoswatchModule, module.filter.modeFilter.BoswatchModule, module.filter.regexFilter.BoswatchModule, module.geocoding.BoswatchModule, and module.template_module.BoswatchModule.

93 def doWork(self, bwPacket):
94 r"""!Called module run
95 can be inherited
96
97 @param bwPacket: bwPacket instance"""
98 logging.warning("no functionality in module %s", self._moduleName)
99

◆ onUnload()

def module.moduleBase.ModuleBase.onUnload (   self)

Called on shutdown of boswatch can be inherited.

Reimplemented in module.descriptor.BoswatchModule, module.filter.doubleFilter.BoswatchModule, module.filter.modeFilter.BoswatchModule, module.filter.regexFilter.BoswatchModule, and module.template_module.BoswatchModule.

100 def onUnload(self):
101 r"""!Called on shutdown of boswatch
102 can be inherited"""
103 pass
104

◆ registerWildcard()

def module.moduleBase.ModuleBase.registerWildcard (   newWildcard,
  bwPacketField 
)
static

Register a new wildcard.

    @param newWildcard: wildcard where parser searching for
    @param bwPacketField: field from bwPacket where holds replacement data
106 def registerWildcard(newWildcard, bwPacketField):
107 r"""!Register a new wildcard
108
109 @param newWildcard: wildcard where parser searching for
110 @param bwPacketField: field from bwPacket where holds replacement data"""
111 if not newWildcard.startswith("{") or not newWildcard.endswith("}"):
112 logging.error("wildcard not registered - false format: %s", newWildcard)
113 return
114 if bwPacketField == "":
115 logging.error("wildcard not registered - bwPacket field is empty")
116 return
117 wildcard.registerWildcard(newWildcard, bwPacketField)

Field Documentation

◆ _modulesActive

list module.moduleBase.ModuleBase._modulesActive = []
staticprotected

◆ _moduleName

module.moduleBase.ModuleBase._moduleName
protected

◆ config

module.moduleBase.ModuleBase.config

◆ _cumTime

module.moduleBase.ModuleBase._cumTime
protected

◆ _moduleTime

module.moduleBase.ModuleBase._moduleTime
protected

◆ _runCount

module.moduleBase.ModuleBase._runCount
protected

◆ _moduleErrorCount

module.moduleBase.ModuleBase._moduleErrorCount
protected