fix: Load all class attributes regardless of configuration

Partly, class attributes were not instantiated if certain sections of
the configuration file were missing.
This commit is contained in:
2023-06-30 09:42:36 +02:00
parent 10c9978a4d
commit 279cf39e93

View File

@@ -238,40 +238,24 @@ class RevPiPyLoad:
restart_plcprogram = True restart_plcprogram = True
# Konfiguration verarbeiten [MQTT] # Konfiguration verarbeiten [MQTT]
self.mqtt = 0 self.mqtt = self.globalconfig.getboolean("MQTT", "mqtt", fallback=False)
if "MQTT" in self.globalconfig: self.mqttbasetopic = self.globalconfig.get("MQTT", "basetopic", fallback="")
self.mqtt = \ self.mqttsendinterval = self.globalconfig.getint("MQTT", "sendinterval", fallback=30)
self.globalconfig["MQTT"].getboolean("mqtt", False) self.mqttbroker_address = self.globalconfig.get("MQTT", "broker_address", fallback="localhost")
self.mqttbasetopic = \ self.mqttport = self.globalconfig.getint("MQTT", "port", fallback=1883)
self.globalconfig["MQTT"].get("basetopic", "") self.mqtttls_set = self.globalconfig.getboolean("MQTT", "tls_set", fallback=False)
self.mqttsendinterval = \ self.mqttusername = self.globalconfig.get("MQTT", "username", fallback="")
self.globalconfig["MQTT"].getint("sendinterval", 30) self.mqttpassword = self.globalconfig.get("MQTT", "password", fallback="")
self.mqttbroker_address = \ self.mqttclient_id = self.globalconfig.get("MQTT", "client_id", fallback="")
self.globalconfig["MQTT"].get("broker_address", "localhost") self.mqttsend_on_event = self.globalconfig.getboolean("MQTT", "send_on_event", fallback=False)
self.mqttport = \ self.mqttwrite_outputs = self.globalconfig.getboolean("MQTT", "write_outputs", fallback=False)
self.globalconfig["MQTT"].getint("port", 1883)
self.mqtttls_set = \
self.globalconfig["MQTT"].getboolean("tls_set", False)
self.mqttusername = \
self.globalconfig["MQTT"].get("username", "")
self.mqttpassword = \
self.globalconfig["MQTT"].get("password", "")
self.mqttclient_id = \
self.globalconfig["MQTT"].get("client_id", "")
self.mqttsend_on_event = \
self.globalconfig["MQTT"].getboolean("send_on_event", False)
self.mqttwrite_outputs = \
self.globalconfig["MQTT"].getboolean("write_outputs", False)
# Konfiguration verarbeiten [PLCSERVER] # Konfiguration verarbeiten [PLCSERVER]
self.plcserver = False self.plcserver = self.globalconfig.getboolean("PLCSERVER", "plcserver", fallback=False)
if "PLCSERVER" in self.globalconfig:
self.plcserver = \
self.globalconfig["PLCSERVER"].getboolean("plcserver", False)
# Berechtigungen laden # Berechtigungen laden
if not self.plcserveracl.loadaclfile( if self.plcserver \
self.globalconfig["PLCSERVER"].get("aclfile", "")): and not self.plcserveracl.loadaclfile(self.globalconfig.get("PLCSERVER", "aclfile", fallback="")):
proginit.logger.warning( proginit.logger.warning(
"can not load plcserver acl - wrong format" "can not load plcserver acl - wrong format"
) )
@@ -279,41 +263,33 @@ class RevPiPyLoad:
self.stop_plcserver() self.stop_plcserver()
# Bind IP lesen und anpassen # Bind IP lesen und anpassen
self.plcserverbindip = \ self.plcserverbindip = self.globalconfig.get("PLCSERVER", "bindip", fallback="127.0.0.1")
self.globalconfig["PLCSERVER"].get("bindip", "127.0.0.1")
if self.plcserverbindip == "*": if self.plcserverbindip == "*":
self.plcserverbindip = "" self.plcserverbindip = ""
elif self.plcserverbindip == "": elif self.plcserverbindip == "":
self.plcserverbindip = "127.0.0.1" self.plcserverbindip = "127.0.0.1"
self.plcserverport = \ self.plcserverport = self.globalconfig.getint("PLCSERVER", "port", fallback=55234)
self.globalconfig["PLCSERVER"].getint("port", 55234) self.plcwatchdog = self.globalconfig.getboolean("PLCSERVER", "watchdog", fallback=True)
self.plcwatchdog = self.globalconfig.getboolean(
"PLCSERVER", "watchdog", fallback=True
)
# Konfiguration verarbeiten [XMLRPC] # Konfiguration verarbeiten [XMLRPC]
self.xmlrpc = False self.xmlrpc = self.globalconfig.getboolean("XMLRPC", "xmlrpc", fallback=False)
if "XMLRPC" in self.globalconfig:
self.xmlrpc = \
self.globalconfig["XMLRPC"].getboolean("xmlrpc", False)
if not self.xmlrpcacl.loadaclfile( if not self.xmlrpcacl.loadaclfile(
self.globalconfig["XMLRPC"].get("aclfile", "")): self.globalconfig.get("XMLRPC", "aclfile", fallback="")):
proginit.logger.warning( proginit.logger.warning(
"can not load xmlrpc acl - wrong format" "can not load xmlrpc acl - wrong format"
) )
# Bind IP lesen und anpassen # Bind IP lesen und anpassen
self.xmlrpcbindip = \ self.xmlrpcbindip = \
self.globalconfig["XMLRPC"].get("bindip", "127.0.0.1") self.globalconfig.get("XMLRPC", "bindip", fallback="127.0.0.1")
if self.xmlrpcbindip == "*": if self.xmlrpcbindip == "*":
self.xmlrpcbindip = "" self.xmlrpcbindip = ""
elif self.xmlrpcbindip == "": elif self.xmlrpcbindip == "":
self.xmlrpcbindip = "127.0.0.1" self.xmlrpcbindip = "127.0.0.1"
self.xmlrpcport = \ self.xmlrpcport = self.globalconfig.getint("XMLRPC", "port", fallback=55123)
self.globalconfig["XMLRPC"].getint("port", 55123)
# Workdirectory wechseln # Workdirectory wechseln
if not os.access(self.plcworkdir, os.R_OK | os.W_OK | os.X_OK): if not os.access(self.plcworkdir, os.R_OK | os.W_OK | os.X_OK):