Parameterprüfung für Instantiierung eingeführt

Debug-Parameter für alle Vererbungen übernommen
This commit is contained in:
2019-05-01 12:25:45 +02:00
parent 6782e9431a
commit 2463eb019d
8 changed files with 92 additions and 26 deletions

View File

@@ -38,6 +38,28 @@ MEM = 302
warnings.simplefilter(action="always")
def acheck(check_type, **kwargs):
"""Check type of given arguments.
Use the argument name as keyword and the argument itself as value.
@param check_type Type to check
@param kwargs Arguments to check
"""
for var_name in kwargs:
none_okay = var_name.endswith("_noneok")
if not (isinstance(kwargs[var_name], check_type) or
none_okay and kwargs[var_name] is None):
msg = "Argument '{0}' must be {1}{2}".format(
var_name.rstrip("_noneok"), str(check_type),
" or <class 'NoneType'>" if none_okay else ""
)
raise TypeError(msg)
def consttostr(value):
"""Gibt <class 'str'> fuer Konstanten zurueck.

View File

@@ -446,7 +446,7 @@ class ProcimgWriter(Thread):
RuntimeWarning
)
if self._modio._debug and e is not None:
warnings.warn(str(e))
warnings.warn(str(e), RuntimeWarning)
def get_maxioerrors(self):
"""Gibt die Anzahl der maximal erlaubten Fehler zurueck.

View File

@@ -9,6 +9,7 @@ from json import load as jload
from multiprocessing import cpu_count
from os import access, F_OK, R_OK
from queue import Empty
from revpimodio2 import acheck
from signal import signal, SIG_DFL, SIGINT, SIGTERM
from threading import Thread, Event, Lock
from timeit import default_timer
@@ -45,8 +46,18 @@ class RevPiModIO(object):
@param procimg Abweichender Pfad zum Prozessabbild
@param configrsc Abweichender Pfad zur piCtory Konfigurationsdatei
@param simulator Laedt das Modul als Simulator und vertauscht IOs
@param debug Gibt bei allen Fehlern komplette Meldungen aus
"""
# Parameterprüfung
acheck(
bool, autorefresh=autorefresh, monitoring=monitoring,
syncoutputs=syncoutputs, simulator=simulator, debug=debug
)
acheck(
str, procimg_noneok=procimg, configrsc_noneok=configrsc
)
self._autorefresh = autorefresh
self._configrsc = configrsc
self._monitoring = monitoring
@@ -336,7 +347,7 @@ class RevPiModIO(object):
RuntimeWarning
)
if self._debug and e is not None:
warnings.warn(str(e))
warnings.warn(str(e), RuntimeWarning)
def _set_cycletime(self, milliseconds):
"""Setzt Aktualisierungsrate der Prozessabbild-Synchronisierung.
@@ -819,7 +830,7 @@ class RevPiModIO(object):
)
mylist = [dev]
e = None
global_ex = None
workokay = True
for dev in mylist:
if not dev._selfupdate:
@@ -831,7 +842,7 @@ class RevPiModIO(object):
self._myfh.seek(dev._slc_outoff.start)
self._myfh.write(dev._ba_devdata[dev._slc_out])
except IOError as e:
e = e
global_ex = e
workokay = False
finally:
self._myfh_lck.release()
@@ -842,11 +853,11 @@ class RevPiModIO(object):
try:
self._myfh.flush()
except IOError as e:
e = e
global_ex = e
workokay = False
if not workokay:
self._gotioerror("writeprocimg", e)
self._gotioerror("writeprocimg", global_ex)
return workokay
@@ -875,7 +886,8 @@ class RevPiModIOSelected(RevPiModIO):
def __init__(
self, deviceselection, autorefresh=False, monitoring=False,
syncoutputs=True, procimg=None, configrsc=None, simulator=False):
syncoutputs=True, procimg=None, configrsc=None,
simulator=False, debug=False):
"""Instantiiert nur fuer angegebene Devices die Grundfunktionen.
Der Parameter deviceselection kann eine einzelne
@@ -887,7 +899,8 @@ class RevPiModIOSelected(RevPiModIO):
"""
super().__init__(
autorefresh, monitoring, syncoutputs, procimg, configrsc, simulator
autorefresh, monitoring, syncoutputs, procimg, configrsc,
simulator, debug
)
# Device liste erstellen
@@ -941,7 +954,7 @@ class RevPiModIODriver(RevPiModIOSelected):
def __init__(
self, virtdev, autorefresh=False, monitoring=False,
syncoutputs=True, procimg=None, configrsc=None):
syncoutputs=True, procimg=None, configrsc=None, debug=False):
"""Instantiiert die Grundfunktionen.
Parameter 'monitoring' und 'simulator' stehen hier nicht zur
@@ -953,7 +966,8 @@ class RevPiModIODriver(RevPiModIOSelected):
"""
# Parent mit monitoring=False und simulator=True laden
super().__init__(
virtdev, autorefresh, False, syncoutputs, procimg, configrsc, True
virtdev, autorefresh, False, syncoutputs, procimg, configrsc,
True, debug
)

View File

@@ -489,7 +489,7 @@ class RevPiNetIO(_RevPiModIO):
def __init__(
self, address, autorefresh=False, monitoring=False,
syncoutputs=True, simulator=False):
syncoutputs=True, simulator=False, debug=False):
"""Instantiiert die Grundfunktionen.
@param address: IP-Adresse <class 'str'> / (IP, Port) <class 'tuple'>
@@ -497,6 +497,7 @@ class RevPiNetIO(_RevPiModIO):
@param monitoring In- und Outputs werden gelesen, niemals geschrieben
@param syncoutputs Aktuell gesetzte Outputs vom Prozessabbild einlesen
@param simulator Laedt das Modul als Simulator und vertauscht IOs
@param debug Gibt bei allen Fehlern komplette Meldungen aus
"""
check_ip = compile(
@@ -544,7 +545,8 @@ class RevPiNetIO(_RevPiModIO):
syncoutputs,
"{0}:{1}".format(*self._address),
None,
simulator
simulator,
debug
)
# Netzwerkfilehandler anlegen
@@ -655,7 +657,7 @@ class RevPiNetIOSelected(RevPiNetIO):
def __init__(
self, address, deviceselection, autorefresh=False,
monitoring=False, syncoutputs=True, simulator=False):
monitoring=False, syncoutputs=True, simulator=False, debug=False):
"""Instantiiert nur fuer angegebene Devices die Grundfunktionen.
Der Parameter deviceselection kann eine einzelne
@@ -668,7 +670,7 @@ class RevPiNetIOSelected(RevPiNetIO):
"""
super().__init__(
address, autorefresh, monitoring, syncoutputs, simulator
address, autorefresh, monitoring, syncoutputs, simulator, debug
)
# Device liste erstellen
@@ -722,7 +724,7 @@ class RevPiNetIODriver(RevPiNetIOSelected):
def __init__(
self, address, virtdev, autorefresh=False, monitoring=False,
syncoutputs=True):
syncoutputs=True, debug=False):
"""Instantiiert die Grundfunktionen.
Parameter 'monitoring' und 'simulator' stehen hier nicht zur
@@ -735,5 +737,5 @@ class RevPiNetIODriver(RevPiNetIOSelected):
"""
# Parent mit monitoring=False und simulator=True laden
super().__init__(
address, virtdev, autorefresh, False, syncoutputs, True
address, virtdev, autorefresh, False, syncoutputs, True, debug
)