mirror of
https://github.com/naruxde/revpipyload.git
synced 2025-11-08 23:23:52 +01:00
replace_io aus Datei importieren wird direkt vararbeitet
This commit is contained in:
@@ -5,6 +5,7 @@ __copyright__ = "Copyright (C) 2018 Sven Sager"
|
||||
__license__ = "GPLv3"
|
||||
import os
|
||||
import proginit
|
||||
from configparser import ConfigParser
|
||||
from re import match as rematch
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
@@ -117,6 +118,115 @@ def _zeroprocimg():
|
||||
)
|
||||
|
||||
|
||||
def revpimodio_replaceio(revpi, filename):
|
||||
"""Importiert und ersetzt IOs in RevPiModIO.
|
||||
|
||||
@param revpi RevPiModIO Instanz
|
||||
@param filename Dateiname der Ersetzungsdatei
|
||||
@return True, wenn alle IOs ersetzt werden konnten
|
||||
|
||||
"""
|
||||
cp = ConfigParser()
|
||||
try:
|
||||
with open(filename, "r") as fh:
|
||||
cp.read_file(fh)
|
||||
except Exception as e:
|
||||
proginit.logger.error(
|
||||
"could not read replace_io file '{0}' | {1}".format(filename, e)
|
||||
)
|
||||
return False
|
||||
|
||||
# Pre-check
|
||||
lst_replace = []
|
||||
rc = True
|
||||
for io in cp:
|
||||
if io == "DEFAULT":
|
||||
continue
|
||||
|
||||
dict_replace = {
|
||||
"replace": cp[io].get("replace", ""),
|
||||
"frm": cp[io].get("frm"),
|
||||
"bmk": cp[io].get("bmk", ""),
|
||||
"byteorder": cp[io].get("byteorder", "little"),
|
||||
}
|
||||
|
||||
if dict_replace["replace"] in revpi.io:
|
||||
|
||||
# Byteorder prüfen
|
||||
if not (dict_replace["byteorder"] == "little" or
|
||||
dict_replace["byteorder"] == "big"):
|
||||
proginit.logger.error(
|
||||
"byteorder of '{0}' must be 'little' or 'big'".format(io)
|
||||
)
|
||||
rc = False
|
||||
continue
|
||||
|
||||
if dict_replace["frm"] == "?":
|
||||
|
||||
# Convert defaultvalue from config file
|
||||
try:
|
||||
dict_replace["default"] = cp[io].getboolean("defaultvalue")
|
||||
except Exception:
|
||||
proginit.logger.error(
|
||||
"could not convert '{0}' defaultvalue '{1}' to boolean"
|
||||
"".format(io, cp[io].get("defaultvalue"))
|
||||
)
|
||||
rc = False
|
||||
continue
|
||||
|
||||
# Get bitaddress
|
||||
try:
|
||||
dict_replace["bitaddress"] = cp[io].getint("bitaddress", 0)
|
||||
except Exception:
|
||||
proginit.logger.error(
|
||||
"could not convert '{0}' bitaddress '{1}' to integer"
|
||||
"".format(io, cp[io].get("bitaddress"))
|
||||
)
|
||||
rc = False
|
||||
continue
|
||||
|
||||
else:
|
||||
# Convert defaultvalue from config file
|
||||
try:
|
||||
dict_replace["default"] = cp[io].getint("defaultvalue")
|
||||
except Exception:
|
||||
proginit.logger.error(
|
||||
"could not convert '{0}' defaultvalue '{1}' to integer"
|
||||
"".format(io, cp[io].get("defaultvalue"))
|
||||
)
|
||||
rc = False
|
||||
continue
|
||||
|
||||
else:
|
||||
proginit.logger.error(
|
||||
"can not find io '{0}' to replace with '{1}'"
|
||||
"".format(dict_replace["replace"], io)
|
||||
)
|
||||
rc = False
|
||||
continue
|
||||
|
||||
# Replace_IO übernehmen
|
||||
lst_replace.append(dict_replace)
|
||||
|
||||
if not rc:
|
||||
# Abbrechen, wenn IO-Verarbeitung einen Fehler hatte
|
||||
return False
|
||||
|
||||
# Replace IOs
|
||||
for dict_replace in lst_replace:
|
||||
|
||||
# FIXME: Hier können Fehler auftreten !!!
|
||||
|
||||
revpi.io[dict_replace["replace"]].replace_io(
|
||||
io,
|
||||
frm=dict_replace["frm"],
|
||||
bmk=dict_replace["bmk"],
|
||||
bit=dict_replace["bitaddress"],
|
||||
byteorder=dict_replace["byteorder"],
|
||||
defaultvalue=dict_replace["default"]
|
||||
)
|
||||
|
||||
|
||||
def refullmatch(regex, string):
|
||||
"""re.fullmatch wegen alter python version aus wheezy nachgebaut.
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ __license__ = "GPLv3"
|
||||
import pickle
|
||||
import proginit
|
||||
import revpimodio2
|
||||
from .helper import revpimodio_replaceio
|
||||
from xmlrpc.client import Binary
|
||||
|
||||
|
||||
@@ -108,14 +109,12 @@ class ProcimgServer():
|
||||
return e
|
||||
|
||||
# Replace IOs of RevPiModIO
|
||||
if self.replace_ios:
|
||||
try:
|
||||
self.rpi.import_replaced_ios(self.replace_ios)
|
||||
except Exception as e:
|
||||
proginit.logger.error(
|
||||
"could not load replaced ios into RevPiModIO - using "
|
||||
"defaults | {0}".format(e)
|
||||
)
|
||||
if self.replace_ios and \
|
||||
not revpimodio_replaceio(self.rpi, self.replace_ios):
|
||||
proginit.logger.error(
|
||||
"could not load all or some replaced ios into RevPiModIO - "
|
||||
"see log file"
|
||||
)
|
||||
|
||||
# NOTE: Warum das?
|
||||
self.rpi.syncoutputs(device=0)
|
||||
|
||||
@@ -28,7 +28,7 @@ begrenzt werden!
|
||||
__author__ = "Sven Sager"
|
||||
__copyright__ = "Copyright (C) 2018 Sven Sager"
|
||||
__license__ = "GPLv3"
|
||||
__version__ = "0.7.5"
|
||||
__version__ = "0.7.6"
|
||||
import gzip
|
||||
import logsystem
|
||||
import picontrolserver
|
||||
|
||||
Reference in New Issue
Block a user