satisfy pycodestyle checker
This commit is contained in:
@ -1,12 +1,14 @@
|
|||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
class InvalidDataObjectException(Exception):
|
class InvalidDataObjectException(Exception):
|
||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
|
|
||||||
|
|
||||||
class AbstractDataObject(object):
|
class AbstractDataObject(object):
|
||||||
invalidChars = re.compile("[#+\s]")
|
invalidChars = re.compile(r'[#+\s]')
|
||||||
|
|
||||||
def __init__(self, topicPart):
|
def __init__(self, topicPart):
|
||||||
self.topicPart = topicPart
|
self.topicPart = topicPart
|
||||||
|
@ -4,7 +4,6 @@ from AbstractDataObject import AbstractDataObject
|
|||||||
|
|
||||||
|
|
||||||
class FlatDataObject(AbstractDataObject):
|
class FlatDataObject(AbstractDataObject):
|
||||||
|
|
||||||
def __init__(self, serverName, nameSpaceIndex, variableName, value):
|
def __init__(self, serverName, nameSpaceIndex, variableName, value):
|
||||||
super().__init__(serverName + '/' + str(nameSpaceIndex) + '/' + variableName)
|
super().__init__(serverName + '/' + str(nameSpaceIndex) + '/' + variableName)
|
||||||
self.serverName = serverName
|
self.serverName = serverName
|
||||||
|
@ -4,13 +4,14 @@ import threading
|
|||||||
import ssl
|
import ssl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def mqttOnConnectCallback(client, userdata, flags, rc):
|
def mqttOnConnectCallback(client, userdata, flags, rc):
|
||||||
userdata.onConnect()
|
userdata.onConnect()
|
||||||
|
|
||||||
|
|
||||||
def mqttOnMessageCallback(client, userdata, message):
|
def mqttOnMessageCallback(client, userdata, message):
|
||||||
userdata.onMessage(message.topic, message.payload)
|
userdata.onMessage(message.topic, message.payload)
|
||||||
|
|
||||||
|
|
||||||
def mqttOnDisconnectCallback(client, userdata, rc):
|
def mqttOnDisconnectCallback(client, userdata, rc):
|
||||||
userdata.onDisconnect(rc)
|
userdata.onDisconnect(rc)
|
||||||
|
|
||||||
@ -52,7 +53,6 @@ class AbstractMqttPublisher(threading.Thread):
|
|||||||
ciphers=None # this does not mean "no cipher" but it means "default ciphers"
|
ciphers=None # this does not mean "no cipher" but it means "default ciphers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
self.client.connect(self.config["broker"], int(self.config["port"]))
|
self.client.connect(self.config["broker"], int(self.config["port"]))
|
||||||
self.client.loop_start()
|
self.client.loop_start()
|
||||||
logger.info("mqtt loop started")
|
logger.info("mqtt loop started")
|
||||||
@ -80,4 +80,3 @@ class AbstractMqttPublisher(threading.Thread):
|
|||||||
|
|
||||||
def onMessage(self, topic, payload):
|
def onMessage(self, topic, payload):
|
||||||
logger.warning("mqtt unexpected message received: {} -> {}".format(topic, str(payload)))
|
logger.warning("mqtt unexpected message received: {} -> {}".format(topic, str(payload)))
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import json
|
|||||||
|
|
||||||
LOOP_SLICE = 0.1 # seconds
|
LOOP_SLICE = 0.1 # seconds
|
||||||
|
|
||||||
|
|
||||||
class MqttPublish(AbstractMqttPublisher):
|
class MqttPublish(AbstractMqttPublisher):
|
||||||
def __init__(self, config, stats, queue):
|
def __init__(self, config, stats, queue):
|
||||||
super().__init__(config)
|
super().__init__(config)
|
||||||
@ -32,4 +33,3 @@ class MqttPublish(AbstractMqttPublisher):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.stats.incMqttErrors()
|
self.stats.incMqttErrors()
|
||||||
logger.error(f"Exception {type(e)} received in MQTT local loop: {e}")
|
logger.error(f"Exception {type(e)} received in MQTT local loop: {e}")
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ from loguru import logger
|
|||||||
from FlatDataObject import FlatDataObject
|
from FlatDataObject import FlatDataObject
|
||||||
from StructuredDataObject import StructuredDataObject
|
from StructuredDataObject import StructuredDataObject
|
||||||
|
|
||||||
|
|
||||||
class OpcUaRequester(threading.Thread):
|
class OpcUaRequester(threading.Thread):
|
||||||
def __init__(self, config, stats, queue):
|
def __init__(self, config, stats, queue):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -25,7 +26,6 @@ class OpcUaRequester(threading.Thread):
|
|||||||
self.killBill = False
|
self.killBill = False
|
||||||
self.killEvent = threading.Event()
|
self.killEvent = threading.Event()
|
||||||
|
|
||||||
|
|
||||||
async def opcUaRequesterInnerLoop(self):
|
async def opcUaRequesterInnerLoop(self):
|
||||||
while not self.killBill:
|
while not self.killBill:
|
||||||
try:
|
try:
|
||||||
@ -69,4 +69,3 @@ class OpcUaRequester(threading.Thread):
|
|||||||
|
|
||||||
self.killEvent.set()
|
self.killEvent.set()
|
||||||
logger.info("kill events triggered")
|
logger.info("kill events triggered")
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ from AbstractDataObject import AbstractDataObject
|
|||||||
import json
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
class StatisticsDataObject(AbstractDataObject):
|
class StatisticsDataObject(AbstractDataObject):
|
||||||
def __init__(self, topic, payload):
|
def __init__(self, topic, payload):
|
||||||
super().__init__(topic)
|
super().__init__(topic)
|
||||||
@ -63,4 +64,3 @@ class StatisticsCollector(threading.Thread):
|
|||||||
self.stats['uptime'] = int((currentTime - startTime).total_seconds())
|
self.stats['uptime'] = int((currentTime - startTime).total_seconds())
|
||||||
self.queue.put(StatisticsDataObject(self.topic, self.stats))
|
self.queue.put(StatisticsDataObject(self.topic, self.stats))
|
||||||
self.killEvent.wait(timeout=float(self.period))
|
self.killEvent.wait(timeout=float(self.period))
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ from AbstractDataObject import AbstractDataObject
|
|||||||
|
|
||||||
|
|
||||||
class StructuredDataObject(AbstractDataObject):
|
class StructuredDataObject(AbstractDataObject):
|
||||||
|
|
||||||
def __init__(self, topicPart):
|
def __init__(self, topicPart):
|
||||||
super().__init__(topicPart)
|
super().__init__(topicPart)
|
||||||
self.keyValuePairs = []
|
self.keyValuePairs = []
|
||||||
|
@ -12,12 +12,14 @@ import signal
|
|||||||
|
|
||||||
deathBell = threading.Event()
|
deathBell = threading.Event()
|
||||||
|
|
||||||
|
|
||||||
def exceptHook(args):
|
def exceptHook(args):
|
||||||
global deathBell
|
global deathBell
|
||||||
logger.error("Exception in thread caught: {}".format(args))
|
logger.error("Exception in thread caught: {}".format(args))
|
||||||
deathBell.set()
|
deathBell.set()
|
||||||
logger.error("rang the death bell")
|
logger.error("rang the death bell")
|
||||||
|
|
||||||
|
|
||||||
def terminateHook(sig, frame):
|
def terminateHook(sig, frame):
|
||||||
global deathBell
|
global deathBell
|
||||||
logger.error("SIGINT received")
|
logger.error("SIGINT received")
|
||||||
|
Reference in New Issue
Block a user