mirror of
https://github.com/naruxde/revpimodio2.git
synced 2025-11-08 22:03:53 +01:00
Code style
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# python3-RevPiModIO
|
||||
#
|
||||
# Webpage: https://revpimodio.org/
|
||||
# (c) Sven Sager, License: LGPLv3
|
||||
#
|
||||
"""Stellt alle Klassen fuer den RevolutionPi zur Verfuegung.
|
||||
|
||||
Webpage: https://revpimodio.org/
|
||||
|
||||
Stellt Klassen fuer die einfache Verwendung des Revolution Pis der
|
||||
Kunbus GmbH (https://revolution.kunbus.de/) zur Verfuegung. Alle I/Os werden
|
||||
aus der piCtory Konfiguration eingelesen und mit deren Namen direkt zugreifbar
|
||||
@@ -23,8 +19,9 @@ __all__ = [
|
||||
"RevPiNetIO", "RevPiNetIOSelected", "RevPiNetIODriver"
|
||||
]
|
||||
__author__ = "Sven Sager <akira@revpimodio.org>"
|
||||
__copyright__ = "Copyright (C) 2018 Sven Sager"
|
||||
__license__ = "LGPLv3"
|
||||
__name__ = "revpimodio2"
|
||||
__package__ = "revpimodio2"
|
||||
__version__ = "2.2.2"
|
||||
|
||||
# Global package values
|
||||
@@ -71,6 +68,7 @@ def consttostr(value):
|
||||
else:
|
||||
return ""
|
||||
|
||||
|
||||
# Benötigte Klassen importieren
|
||||
from .modio import RevPiModIO, RevPiModIOSelected, RevPiModIODriver
|
||||
from .netio import RevPiNetIO, RevPiNetIOSelected, RevPiNetIODriver
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# python3-RevPiModIO
|
||||
#
|
||||
# Webpage: https://revpimodio.org/
|
||||
# (c) Sven Sager, License: LGPLv3
|
||||
#
|
||||
"""Bildet die App Sektion von piCtory ab."""
|
||||
__author__ = "Sven Sager"
|
||||
__copyright__ = "Copyright (C) 2018 Sven Sager"
|
||||
__license__ = "LGPLv3"
|
||||
|
||||
|
||||
class App(object):
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# python3-RevPiModIO
|
||||
#
|
||||
# Webpage: https://revpimodio.org/
|
||||
# (c) Sven Sager, License: LGPLv3
|
||||
#
|
||||
"""Modul fuer die Verwaltung der Devices."""
|
||||
__author__ = "Sven Sager"
|
||||
__copyright__ = "Copyright (C) 2018 Sven Sager"
|
||||
__license__ = "LGPLv3"
|
||||
|
||||
from threading import Thread, Event, Lock
|
||||
from .helper import ProcimgWriter
|
||||
|
||||
@@ -65,7 +63,7 @@ class DeviceList(object):
|
||||
@return Gefundenes <class 'Device'>-Objekt"""
|
||||
if type(key) == int:
|
||||
if key not in self.__dict_position:
|
||||
raise KeyError("no device on position {}".format(key))
|
||||
raise KeyError("no device on position {0}".format(key))
|
||||
return self.__dict_position[key]
|
||||
else:
|
||||
return getattr(self, key)
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# python3-RevPiModIO
|
||||
#
|
||||
# Webpage: https://revpimodio.org/
|
||||
# (c) Sven Sager, License: LGPLv3
|
||||
#
|
||||
"""RevPiModIO Helperklassen und Tools."""
|
||||
__author__ = "Sven Sager"
|
||||
__copyright__ = "Copyright (C) 2018 Sven Sager"
|
||||
__license__ = "LGPLv3"
|
||||
|
||||
import queue
|
||||
import warnings
|
||||
from math import ceil
|
||||
@@ -413,12 +411,12 @@ class ProcimgWriter(Thread):
|
||||
self._ioerror += 1
|
||||
if self._maxioerrors != 0 and self._ioerror >= self._maxioerrors:
|
||||
raise RuntimeError(
|
||||
"reach max io error count {} on process image".format(
|
||||
"reach max io error count {0} on process image".format(
|
||||
self._maxioerrors
|
||||
)
|
||||
)
|
||||
warnings.warn(
|
||||
"count {} io errors on process image".format(self._ioerror),
|
||||
"count {0} io errors on process image".format(self._ioerror),
|
||||
RuntimeWarning
|
||||
)
|
||||
|
||||
@@ -443,7 +441,7 @@ class ProcimgWriter(Thread):
|
||||
# Lockobjekt holen und Fehler werfen, wenn nicht schnell genug
|
||||
if not self.lck_refresh.acquire(timeout=self._adjwait):
|
||||
warnings.warn(
|
||||
"cycle time of {} ms exceeded on lock".format(
|
||||
"cycle time of {0} ms exceeded on lock".format(
|
||||
int(self._refresh * 1000)
|
||||
),
|
||||
RuntimeWarning
|
||||
@@ -496,8 +494,8 @@ class ProcimgWriter(Thread):
|
||||
# Verzögerte Events prüfen
|
||||
if self.__eventwork:
|
||||
for tup_fire in list(self.__dict_delay.keys()):
|
||||
if tup_fire[0].overwrite \
|
||||
and getattr(self._modio.io, tup_fire[1]).value != \
|
||||
if tup_fire[0].overwrite and \
|
||||
getattr(self._modio.io, tup_fire[1]).value != \
|
||||
tup_fire[2]:
|
||||
del self.__dict_delay[tup_fire]
|
||||
else:
|
||||
@@ -518,7 +516,7 @@ class ProcimgWriter(Thread):
|
||||
self._adjwait -= 0.001
|
||||
if self._adjwait < 0:
|
||||
warnings.warn(
|
||||
"cycle time of {} ms exceeded".format(
|
||||
"cycle time of {0} ms exceeded".format(
|
||||
int(self._refresh * 1000)
|
||||
),
|
||||
RuntimeWarning
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# python3-RevPiModIO
|
||||
#
|
||||
# Webpage: https://revpimodio.org/
|
||||
# (c) Sven Sager, License: LGPLv3
|
||||
#
|
||||
"""RevPiModIO Modul fuer die Verwaltung der IOs."""
|
||||
__author__ = "Sven Sager"
|
||||
__copyright__ = "Copyright (C) 2018 Sven Sager"
|
||||
__license__ = "LGPLv3"
|
||||
|
||||
import struct
|
||||
from re import match as rematch
|
||||
from threading import Event
|
||||
@@ -69,7 +67,7 @@ class IOList(object):
|
||||
if key in self.__dict_iorefname:
|
||||
return self.__dict_iorefname[key]
|
||||
else:
|
||||
raise AttributeError("can not find io '{}'".format(key))
|
||||
raise AttributeError("can not find io '{0}'".format(key))
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""Ruft angegebenen IO ab.
|
||||
@@ -86,7 +84,7 @@ class IOList(object):
|
||||
"""
|
||||
if type(key) == int:
|
||||
if key not in self.__dict_iobyte:
|
||||
raise KeyError("byte '{}' does not exist".format(key))
|
||||
raise KeyError("byte '{0}' does not exist".format(key))
|
||||
return self.__dict_iobyte[key]
|
||||
elif type(key) == slice:
|
||||
return [
|
||||
@@ -151,14 +149,14 @@ class IOList(object):
|
||||
if oldio._bitaddress >= 0:
|
||||
if io._bitaddress == oldio._bitaddress:
|
||||
raise MemoryError(
|
||||
"bit {} already assigned to '{}'".format(
|
||||
"bit {0} already assigned to '{1}'".format(
|
||||
io._bitaddress, oldio._name
|
||||
)
|
||||
)
|
||||
else:
|
||||
# Bereits überschriebene bytes sind ungültig
|
||||
raise MemoryError(
|
||||
"new io '{}' overlaps memory of '{}'".format(
|
||||
"new io '{0}' overlaps memory of '{1}'".format(
|
||||
io._name, oldio._name
|
||||
)
|
||||
)
|
||||
@@ -194,7 +192,7 @@ class IOList(object):
|
||||
if isinstance(new_io, IOBase):
|
||||
if hasattr(self, new_io._name):
|
||||
raise AttributeError(
|
||||
"attribute {} already exists - can not set io".format(
|
||||
"attribute {0} already exists - can not set io".format(
|
||||
new_io._name
|
||||
)
|
||||
)
|
||||
@@ -298,7 +296,7 @@ class IOBase(object):
|
||||
else:
|
||||
raise ValueError(
|
||||
"given bytes for default value must have a length "
|
||||
"of {} but {} was given"
|
||||
"of {0} but {1} was given"
|
||||
"".format(self._length, len(valuelist[1]))
|
||||
)
|
||||
else:
|
||||
@@ -312,7 +310,7 @@ class IOBase(object):
|
||||
if len(buff) <= self._length:
|
||||
self._defaultvalue = \
|
||||
buff + bytes(self._length - len(buff))
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
else:
|
||||
@@ -328,7 +326,7 @@ class IOBase(object):
|
||||
else:
|
||||
try:
|
||||
self._defaultvalue = bool(int(valuelist[1]))
|
||||
except:
|
||||
except Exception:
|
||||
self._defaultvalue = False
|
||||
|
||||
def __bool__(self):
|
||||
@@ -367,7 +365,7 @@ class IOBase(object):
|
||||
# Prüfen ob Funktion callable ist
|
||||
if not callable(func):
|
||||
raise AttributeError(
|
||||
"registered function '{}' is not callable".format(func)
|
||||
"registered function '{0}' is not callable".format(func)
|
||||
)
|
||||
if type(delay) != int or delay < 0:
|
||||
raise AttributeError(
|
||||
@@ -391,20 +389,21 @@ class IOBase(object):
|
||||
if edge == BOTH or regfunc.edge == BOTH:
|
||||
if self._bitaddress < 0:
|
||||
raise AttributeError(
|
||||
"io '{}' with function '{}' already in list."
|
||||
"io '{0}' with function '{1}' already in list."
|
||||
"".format(self._name, func)
|
||||
)
|
||||
else:
|
||||
raise AttributeError(
|
||||
"io '{}' with function '{}' already in list with "
|
||||
"edge '{}' - edge '{}' not allowed anymore".format(
|
||||
"io '{0}' with function '{1}' already in list "
|
||||
"with edge '{2}' - edge '{3}' not allowed anymore"
|
||||
"".format(
|
||||
self._name, func,
|
||||
consttostr(regfunc.edge), consttostr(edge)
|
||||
)
|
||||
)
|
||||
elif regfunc.edge == edge:
|
||||
raise AttributeError(
|
||||
"io '{}' with function '{}' for given edge '{}' "
|
||||
"io '{0}' with function '{1}' for given edge '{2}' "
|
||||
"already in list".format(
|
||||
self._name, func, consttostr(edge)
|
||||
)
|
||||
@@ -584,31 +583,31 @@ class IOBase(object):
|
||||
value
|
||||
else:
|
||||
raise ValueError(
|
||||
"'{}' requires a <class 'bytes'> object of length "
|
||||
"{}, but {} was given".format(
|
||||
"'{0}' requires a <class 'bytes'> object of "
|
||||
"length {1}, but {2} was given".format(
|
||||
self._name, self._length, len(value)
|
||||
)
|
||||
)
|
||||
else:
|
||||
raise ValueError(
|
||||
"'{}' requires a <class 'bytes'> object, not {}"
|
||||
"'{0}' requires a <class 'bytes'> object, not {1}"
|
||||
"".format(self._name, type(value))
|
||||
)
|
||||
|
||||
elif self._iotype == INP:
|
||||
if self._parentdevice._modio._simulator:
|
||||
raise AttributeError(
|
||||
"can not write to output '{}' in simulator mode"
|
||||
"can not write to output '{0}' in simulator mode"
|
||||
"".format(self._name)
|
||||
)
|
||||
else:
|
||||
raise AttributeError(
|
||||
"can not write to input '{}'".format(self._name)
|
||||
"can not write to input '{0}'".format(self._name)
|
||||
)
|
||||
|
||||
elif self._iotype == MEM:
|
||||
raise AttributeError(
|
||||
"can not write to memory '{}'".format(self._name)
|
||||
"can not write to memory '{0}'".format(self._name)
|
||||
)
|
||||
|
||||
def unreg_event(self, func=None, edge=None):
|
||||
@@ -679,7 +678,7 @@ class IOBase(object):
|
||||
# Prüfen ob Device in autorefresh ist
|
||||
if not self._parentdevice._selfupdate:
|
||||
raise RuntimeError(
|
||||
"autorefresh is not activated for device '{}|{}' - there "
|
||||
"autorefresh is not activated for device '{0}|{1}' - there "
|
||||
"will never be new data".format(
|
||||
self._parentdevice._position, self._parentdevice._name
|
||||
)
|
||||
@@ -825,7 +824,7 @@ class IntIO(IOBase):
|
||||
))
|
||||
else:
|
||||
raise ValueError(
|
||||
"'{}' need a <class 'int'> value, but {} was given"
|
||||
"'{0}' need a <class 'int'> value, but {1} was given"
|
||||
"".format(self._name, type(value))
|
||||
)
|
||||
|
||||
@@ -873,7 +872,7 @@ class StructIO(IOBase):
|
||||
max_bits = parentio._length * 8
|
||||
if not (0 <= bitaddress < max_bits):
|
||||
raise AttributeError(
|
||||
"bitaddress must be a value between 0 and {}"
|
||||
"bitaddress must be a value between 0 and {0}"
|
||||
"".format(max_bits - 1)
|
||||
)
|
||||
bitlength = 1
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# python3-RevPiModIO
|
||||
#
|
||||
# Webpage: https://revpimodio.org/
|
||||
# (c) Sven Sager, License: LGPLv3
|
||||
#
|
||||
"""RevPiModIO Hauptklasse fuer piControl0 Zugriff."""
|
||||
__author__ = "Sven Sager"
|
||||
__copyright__ = "Copyright (C) 2018 Sven Sager"
|
||||
__license__ = "LGPLv3"
|
||||
|
||||
import warnings
|
||||
from json import load as jload
|
||||
from os import access, F_OK, R_OK
|
||||
@@ -187,7 +185,7 @@ class RevPiModIO(object):
|
||||
else:
|
||||
# Device-Type nicht gefunden
|
||||
warnings.warn(
|
||||
"device type '{}' unknown".format(device["type"]),
|
||||
"device type '{0}' unknown".format(device["type"]),
|
||||
Warning
|
||||
)
|
||||
dev_new = None
|
||||
@@ -298,12 +296,12 @@ class RevPiModIO(object):
|
||||
self._ioerror += 1
|
||||
if self._maxioerrors != 0 and self._ioerror >= self._maxioerrors:
|
||||
raise RuntimeError(
|
||||
"reach max io error count {} on process image".format(
|
||||
"reach max io error count {0} on process image".format(
|
||||
self._maxioerrors
|
||||
)
|
||||
)
|
||||
warnings.warn(
|
||||
"got io error during {} and count {} errors now".format(
|
||||
"got io error during {0} and count {1} errors now".format(
|
||||
action, self._ioerror
|
||||
),
|
||||
RuntimeWarning
|
||||
@@ -385,7 +383,7 @@ class RevPiModIO(object):
|
||||
# Prüfen ob Funktion callable ist
|
||||
if not callable(func):
|
||||
raise RuntimeError(
|
||||
"registered function '{}' ist not callable".format(func)
|
||||
"registered function '{0}' ist not callable".format(func)
|
||||
)
|
||||
|
||||
# Zykluszeit übernehmen
|
||||
@@ -478,7 +476,7 @@ class RevPiModIO(object):
|
||||
if self._configrsc is not None:
|
||||
if not access(self._configrsc, F_OK | R_OK):
|
||||
raise RuntimeError(
|
||||
"can not access pictory configuration at {}".format(
|
||||
"can not access pictory configuration at {0}".format(
|
||||
self._configrsc))
|
||||
else:
|
||||
# piCtory Konfiguration an bekannten Stellen prüfen
|
||||
@@ -489,7 +487,7 @@ class RevPiModIO(object):
|
||||
break
|
||||
if self._configrsc is None:
|
||||
raise RuntimeError(
|
||||
"can not access known pictory configurations at {} - "
|
||||
"can not access known pictory configurations at {0} - "
|
||||
"use 'configrsc' parameter so specify location"
|
||||
"".format(", ".join(lst_rsc))
|
||||
)
|
||||
@@ -497,7 +495,7 @@ class RevPiModIO(object):
|
||||
with open(self._configrsc, "r") as fhconfigrsc:
|
||||
try:
|
||||
jdata = jload(fhconfigrsc)
|
||||
except:
|
||||
except Exception:
|
||||
raise RuntimeError(
|
||||
"can not read piCtory configuration - check your hardware "
|
||||
"configuration http://revpi_ip/"
|
||||
@@ -529,7 +527,8 @@ class RevPiModIO(object):
|
||||
# Prüfen ob Funktion callable ist
|
||||
if not (cleanupfunc is None or callable(cleanupfunc)):
|
||||
raise RuntimeError(
|
||||
"registered function '{}' ist not callable".format(cleanupfunc)
|
||||
"registered function '{0}' ist not callable"
|
||||
"".format(cleanupfunc)
|
||||
)
|
||||
self.__cleanupfunc = cleanupfunc
|
||||
signal(SIGINT, self.__evt_exit)
|
||||
@@ -628,7 +627,7 @@ class RevPiModIO(object):
|
||||
|
||||
if dev._selfupdate:
|
||||
raise RuntimeError(
|
||||
"can not read process image, while device '{}|{}'"
|
||||
"can not read process image, while device '{0}|{1}'"
|
||||
"is in autorefresh mode".format(dev._position, dev._name)
|
||||
)
|
||||
mylist = [dev]
|
||||
@@ -703,7 +702,7 @@ class RevPiModIO(object):
|
||||
|
||||
if dev._selfupdate:
|
||||
raise RuntimeError(
|
||||
"can not sync outputs, while device '{}|{}'"
|
||||
"can not sync outputs, while device '{0}|{1}'"
|
||||
"is in autorefresh mode".format(dev._position, dev._name)
|
||||
)
|
||||
mylist = [dev]
|
||||
@@ -746,7 +745,7 @@ class RevPiModIO(object):
|
||||
|
||||
if dev._selfupdate:
|
||||
raise RuntimeError(
|
||||
"can not write process image, while device '{}|{}'"
|
||||
"can not write process image, while device '{0}|{1}'"
|
||||
"is in autorefresh mode".format(dev._position, dev._name)
|
||||
)
|
||||
mylist = [dev]
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# python3-RevPiModIO
|
||||
#
|
||||
# Webpage: https://revpimodio.org/
|
||||
# (c) Sven Sager, License: LGPLv3
|
||||
#
|
||||
"""RevPiModIO Hauptklasse fuer Netzwerkzugriff."""
|
||||
__author__ = "Sven Sager"
|
||||
__copyright__ = "Copyright (C) 2018 Sven Sager"
|
||||
__license__ = "LGPLv3"
|
||||
|
||||
import socket
|
||||
import warnings
|
||||
from json import loads as jloads
|
||||
@@ -79,7 +77,7 @@ class NetFH(Thread):
|
||||
so = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
so.connect(self._address)
|
||||
except:
|
||||
except Exception:
|
||||
so.close()
|
||||
else:
|
||||
# Alten Socket trennen
|
||||
@@ -141,7 +139,7 @@ class NetFH(Thread):
|
||||
self._slavesock.send(_sysexit)
|
||||
else:
|
||||
self._slavesock.shutdown(socket.SHUT_RDWR)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
self._slavesock.close()
|
||||
|
||||
@@ -178,7 +176,7 @@ class NetFH(Thread):
|
||||
def get_name(self):
|
||||
"""Verbindugnsnamen zurueckgeben.
|
||||
@return <class 'str'> IP:PORT"""
|
||||
return "{}:{}".format(*self._address)
|
||||
return "{0}:{1}".format(*self._address)
|
||||
|
||||
def get_timeout(self):
|
||||
"""Gibt aktuellen Timeout zurueck.
|
||||
@@ -423,7 +421,7 @@ class RevPiNetIO(_RevPiModIO):
|
||||
autorefresh,
|
||||
monitoring,
|
||||
syncoutputs,
|
||||
"{}:{}".format(*self._address),
|
||||
"{0}:{1}".format(*self._address),
|
||||
None,
|
||||
simulator
|
||||
)
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# python3-RevPiModIO
|
||||
#
|
||||
# Webpage: https://revpimodio.org/
|
||||
# (c) Sven Sager, License: LGPLv3
|
||||
#
|
||||
"""Bildet die Summary-Sektion von piCtory ab."""
|
||||
__author__ = "Sven Sager"
|
||||
__copyright__ = "Copyright (C) 2018 Sven Sager"
|
||||
__license__ = "LGPLv3"
|
||||
|
||||
|
||||
class Summary(object):
|
||||
|
||||
Reference in New Issue
Block a user