diff --git a/data/etc/revpipyload/replace_ios.conf b/data/etc/revpipyload/replace_ios.conf index c5b331c..94376f0 100644 --- a/data/etc/revpipyload/replace_ios.conf +++ b/data/etc/revpipyload/replace_ios.conf @@ -1,7 +1,9 @@ # Replace IO # [NewIoName] -# parentio_name = OldIoName +# replace = OldIoName # frm = StructFormat -# bitaddress = 0-7 (Only with '?' struct) +# bit = 0-n (Only with '?' struct) # byteorder = little/big +# bmk = JustText + diff --git a/doc/index.html b/doc/index.html index 2e74c52..c6edd36 100644 --- a/doc/index.html +++ b/doc/index.html @@ -45,6 +45,9 @@ Modules revpipyload Revolution Pi Python PLC Loader. +testsystem +Test all config files and print results. + xrpcserver XML-RPC Server anpassungen fuer Absicherung. diff --git a/doc/revpipyload.html b/doc/revpipyload.html index 625fb74..4ec59aa 100644 --- a/doc/revpipyload.html +++ b/doc/revpipyload.html @@ -66,7 +66,7 @@ None

Class Attributes

- +
root
None

Class Methods

diff --git a/doc/testsystem.html b/doc/testsystem.html new file mode 100644 index 0000000..dc7a974 --- /dev/null +++ b/doc/testsystem.html @@ -0,0 +1,108 @@ + + +testsystem + + + +

+testsystem

+

+Test all config files and print results. +

+

+Global Attributes

+ + +
__author__
__copyright__
__license__
newline
+

+Classes

+ + + + + +
TestSystemMain class for test system of revpipyload.
+

+Functions

+ + +
None
+

+ +

TestSystem

+

+Main class for test system of revpipyload. +

+

+Derived from

+None +

+Class Attributes

+ + +
None
+

+Class Methods

+ + +
None
+

+Methods

+ + + + + + + + + + + + + + +
TestSystemInit TestSystem class.
startStart test program and run tests.
test_replace_ioTest replace_io file.
test_sectionsTest config file.
+

+Static Methods

+ + +
None
+ +

+TestSystem (Constructor)

+TestSystem() +

+Init TestSystem class. +

+

+TestSystem.start

+start() +

+Start test program and run tests. +

+

+TestSystem.test_replace_io

+test_replace_io() +

+Test replace_io file. +

+
Returns:
+
+0 if successful testet +
+
+

+TestSystem.test_sections

+test_sections() +

+Test config file. +

+
Returns:
+
+0 if successful testet +
+
+
Up
+
+ \ No newline at end of file diff --git a/eric-revpipyload.api b/eric-revpipyload.api index c3374a7..813f47c 100644 --- a/eric-revpipyload.api +++ b/eric-revpipyload.api @@ -93,7 +93,6 @@ revpipyload.RevPiPyLoad._sigexit?5(signum, frame) revpipyload.RevPiPyLoad._sigloadconfig?5(signum, frame) revpipyload.RevPiPyLoad._signewlogfile?5(signum, frame) revpipyload.RevPiPyLoad.packapp?4(mode="tar", pictory=False) -revpipyload.RevPiPyLoad.root?7 revpipyload.RevPiPyLoad.start?4() revpipyload.RevPiPyLoad.stop?4() revpipyload.RevPiPyLoad.stop_plcmqtt?4() @@ -149,6 +148,14 @@ revpipyload.shared.ipaclmanager.__copyright__?9 revpipyload.shared.ipaclmanager.__license__?9 revpipyload.shared.ipaclmanager.__version__?9 revpipyload.shared.ipaclmanager.refullmatch?4(regex, string) +testsystem.TestSystem.start?4() +testsystem.TestSystem.test_replace_io?4() +testsystem.TestSystem.test_sections?4() +testsystem.TestSystem?1() +testsystem.__author__?9 +testsystem.__copyright__?9 +testsystem.__license__?9 +testsystem.newline?7 xrpcserver.SaveXMLRPCRequestHandler.parse_request?4() xrpcserver.SaveXMLRPCServer._dispatch?5(method, params) xrpcserver.SaveXMLRPCServer.is_alive?4() diff --git a/revpipyload.e4p b/revpipyload.e4p index 63c4f3d..c4f6847 100644 --- a/revpipyload.e4p +++ b/revpipyload.e4p @@ -1,7 +1,7 @@ - + en_US @@ -24,6 +24,7 @@ revpipyload/revpipyload.py revpipyload/shared/__init__.py revpipyload/shared/ipaclmanager.py + revpipyload/testsystem.py revpipyload/xrpcserver.py setup.py diff --git a/revpipyload/mqttserver.py b/revpipyload/mqttserver.py index 5ef06ef..6c9fa65 100644 --- a/revpipyload/mqttserver.py +++ b/revpipyload/mqttserver.py @@ -140,14 +140,16 @@ class MqttServer(Thread): autorefresh=self._send_events, monitoring=True, configrsc=proginit.pargs.configrsc, - procimg=proginit.pargs.procimg + procimg=proginit.pargs.procimg, + replace_io_file=self._replace_ios ) # Schreibenen Zugriff if self._write_outputs: self._rpi_write = revpimodio2.RevPiModIO( configrsc=proginit.pargs.configrsc, - procimg=proginit.pargs.procimg + procimg=proginit.pargs.procimg, + replace_io_file=self._replace_ios ) except Exception as e: @@ -158,18 +160,6 @@ class MqttServer(Thread): ) raise e - # Replace IOs of RevPiModIO - if self._replace_ios: - try: - self._rpi.import_replaced_ios(self._replace_ios) - if self._write_outputs: - self._rpi_write.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) - ) - # Exportierte IOs laden for dev in self._rpi.device: for io in dev.get_allios(export=True): diff --git a/revpipyload/procimgserver.py b/revpipyload/procimgserver.py index 25d3739..d9d7953 100644 --- a/revpipyload/procimgserver.py +++ b/revpipyload/procimgserver.py @@ -11,7 +11,6 @@ __license__ = "GPLv3" import pickle import proginit import revpimodio2 -from .helper import revpimodio_replaceio from xmlrpc.client import Binary @@ -99,7 +98,8 @@ class ProcimgServer(): try: self.rpi = revpimodio2.RevPiModIO( configrsc=proginit.pargs.configrsc, - procimg=proginit.pargs.procimg + procimg=proginit.pargs.procimg, + replace_io_file=self.replace_ios ) except Exception as e: self.rpi = None @@ -108,14 +108,6 @@ class ProcimgServer(): ) return e - # Replace IOs of RevPiModIO - 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) diff --git a/revpipyload/proginit.py b/revpipyload/proginit.py index 1594107..a0bf0fd 100644 --- a/revpipyload/proginit.py +++ b/revpipyload/proginit.py @@ -63,6 +63,10 @@ def configure(): "--pictory", dest="configrsc", help="piCtory file to use" ) + parser.add_argument( + "--test", action="store_true", dest="test", + help="Test parameters of config files and print results" + ) parser.add_argument( "-v", "--verbose", action="count", dest="verbose", help="Switch on verbose logging: info -v debug -vv" diff --git a/revpipyload/revpipyload.py b/revpipyload/revpipyload.py index 75818c3..8aed928 100755 --- a/revpipyload/revpipyload.py +++ b/revpipyload/revpipyload.py @@ -394,11 +394,6 @@ class RevPiPyLoad(): # Erweiterte Funktionen anmelden try: import procimgserver - self.xml_ps = procimgserver.ProcimgServer( - self.xsrv, self.replace_ios_config - ) - self.xsrv.register_function(1, self.xml_psstart, "psstart") - self.xsrv.register_function(1, self.xml_psstop, "psstop") except Exception: self.xml_ps = None proginit.logger.warning( @@ -408,6 +403,15 @@ class RevPiPyLoad(): "revpimodio2: 'apt-get install python3-revpimodio2'" "".format(min_revpimodio) ) + try: + self.xml_ps = procimgserver.ProcimgServer( + self.xsrv, self.replace_ios_config + ) + self.xsrv.register_function(1, self.xml_psstart, "psstart") + self.xsrv.register_function(1, self.xml_psstop, "psstop") + except Exception as e: + self.xml_ps = None + proginit.logger.error(e) # XML Modus 2 Einstellungen lesen und Programm herunterladen self.xsrv.register_function( @@ -1214,8 +1218,13 @@ if __name__ == "__main__": # Programmeinstellungen konfigurieren proginit.configure() + if proginit.pargs.test: + from testsystem import TestSystem + root = TestSystem() + else: + root = RevPiPyLoad() + # Programm starten - root = RevPiPyLoad() root.start() # Aufräumen diff --git a/revpipyload/testsystem.py b/revpipyload/testsystem.py new file mode 100644 index 0000000..5ef5a1f --- /dev/null +++ b/revpipyload/testsystem.py @@ -0,0 +1,88 @@ +# -*- coding: utf-8 -*- +"""Test all config files and print results.""" +__author__ = "Sven Sager" +__copyright__ = "Copyright (C) 2019 Sven Sager" +__license__ = "GPLv3" +import proginit +from configparser import ConfigParser + +newline = "\n------------------------------------------------------------\n" + + +class TestSystem: + + """Main class for test system of revpipyload.""" + + def __init__(self): + """Init TestSystem class.""" + self.gc = ConfigParser() + lst_file = self.gc.read(proginit.globalconffile) + if len(lst_file) <= 0: + proginit.logger.error("can not read config file") + + def test_replace_io(self): + """Test replace_io file. + @return 0 if successful testet""" + print("Test replace_io data:") + file = self.gc["DEFAULT"].get("replace_ios") + if file is None: + print("\tFile MISSING") + return 1 + + print("\tFile: {0}\n".format(file)) + + try: + import revpimodio2 + except Exception as e: + print("\tERROR: {0}".format(e)) + return 1 + + try: + rpi = revpimodio2.RevPiModIO( + configrsc=proginit.pargs.configrsc, + procimg=proginit.pargs.procimg, + monitoring=False, + debug=True, + replace_io_file=file, + ) + except Exception as e: + print(e) + return 1 + else: + print("\tPrinting replaced IOs:") + for io in rpi.io: + if isinstance(io, revpimodio2.io.StructIO): + print("\t\tNew io: {0}".format(io.name)) + + rpi.cleanup() + return 0 + + def test_sections(self): + """Test config file. + @return 0 if successful testet""" + print("Parse config file:") + print("\tSection DEFAULT : {0}".format("DEFAULT" in self.gc)) + print("\tSection PLCSLAVE: {0}".format("PLCSLAVE" in self.gc)) + print("\tSection XMLRPC : {0}".format("XMLRPC" in self.gc)) + print("\tSection MQTT : {0}".format("MQTT" in self.gc)) + return 0 + + def start(self): + """Start test program and run tests.""" + program_ec = 0 + + print("--- RevPiPyLoad Testsystem ---\n") + ec = self.test_sections() + program_ec += int(ec) << 0 + print(newline) + + # TODO: Test Values of each section + # print() + + ec = self.test_replace_io() + program_ec += (int(ec) << 7) + print(newline) + + if program_ec != 0: + print("result: {0}".format(program_ec)) + exit(program_ec)