mirror of
https://github.com/naruxde/revpipyload.git
synced 2025-11-08 15:13:52 +01:00
replace_io_file wird von RevPiModIO verarbeitet
Parameter kann per XML-RPC übergeben werden Argument --test hinzugefügt um replace_io_file testen zu können
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -45,6 +45,9 @@ Modules</h3>
|
||||
<td><a style="color:#0000FF" href="revpipyload.html">revpipyload</a></td>
|
||||
<td>Revolution Pi Python PLC Loader.</td>
|
||||
</tr><tr>
|
||||
<td><a style="color:#0000FF" href="testsystem.html">testsystem</a></td>
|
||||
<td>Test all config files and print results.</td>
|
||||
</tr><tr>
|
||||
<td><a style="color:#0000FF" href="xrpcserver.html">xrpcserver</a></td>
|
||||
<td>XML-RPC Server anpassungen fuer Absicherung.</td>
|
||||
</tr>
|
||||
|
||||
@@ -66,7 +66,7 @@ None
|
||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||
Class Attributes</h3>
|
||||
<table>
|
||||
<tr><td>root</td></tr>
|
||||
<tr><td>None</td></tr>
|
||||
</table>
|
||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||
Class Methods</h3>
|
||||
|
||||
108
doc/testsystem.html
Normal file
108
doc/testsystem.html
Normal file
@@ -0,0 +1,108 @@
|
||||
<!DOCTYPE html>
|
||||
<html><head>
|
||||
<title>testsystem</title>
|
||||
<meta charset="UTF-8">
|
||||
</head>
|
||||
<body style="background-color:#FFFFFF;color:#000000"><a NAME="top" ID="top"></a>
|
||||
<h1 style="background-color:#FFFFFF;color:#0000FF">
|
||||
testsystem</h1>
|
||||
<p>
|
||||
Test all config files and print results.
|
||||
</p>
|
||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||
Global Attributes</h3>
|
||||
<table>
|
||||
<tr><td>__author__</td></tr><tr><td>__copyright__</td></tr><tr><td>__license__</td></tr><tr><td>newline</td></tr>
|
||||
</table>
|
||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||
Classes</h3>
|
||||
<table>
|
||||
<tr>
|
||||
<td><a style="color:#0000FF" href="#TestSystem">TestSystem</a></td>
|
||||
<td>Main class for test system of revpipyload.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||
Functions</h3>
|
||||
<table>
|
||||
<tr><td>None</td></tr>
|
||||
</table>
|
||||
<hr /><hr />
|
||||
<a NAME="TestSystem" ID="TestSystem"></a>
|
||||
<h2 style="background-color:#FFFFFF;color:#0000FF">TestSystem</h2>
|
||||
<p>
|
||||
Main class for test system of revpipyload.
|
||||
</p>
|
||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||
Derived from</h3>
|
||||
None
|
||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||
Class Attributes</h3>
|
||||
<table>
|
||||
<tr><td>None</td></tr>
|
||||
</table>
|
||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||
Class Methods</h3>
|
||||
<table>
|
||||
<tr><td>None</td></tr>
|
||||
</table>
|
||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||
Methods</h3>
|
||||
<table>
|
||||
<tr>
|
||||
<td><a style="color:#0000FF" href="#TestSystem.__init__">TestSystem</a></td>
|
||||
<td>Init TestSystem class.</td>
|
||||
</tr><tr>
|
||||
<td><a style="color:#0000FF" href="#TestSystem.start">start</a></td>
|
||||
<td>Start test program and run tests.</td>
|
||||
</tr><tr>
|
||||
<td><a style="color:#0000FF" href="#TestSystem.test_replace_io">test_replace_io</a></td>
|
||||
<td>Test replace_io file.</td>
|
||||
</tr><tr>
|
||||
<td><a style="color:#0000FF" href="#TestSystem.test_sections">test_sections</a></td>
|
||||
<td>Test config file.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||
Static Methods</h3>
|
||||
<table>
|
||||
<tr><td>None</td></tr>
|
||||
</table>
|
||||
<a NAME="TestSystem.__init__" ID="TestSystem.__init__"></a>
|
||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||
TestSystem (Constructor)</h3>
|
||||
<b>TestSystem</b>(<i></i>)
|
||||
<p>
|
||||
Init TestSystem class.
|
||||
</p><a NAME="TestSystem.start" ID="TestSystem.start"></a>
|
||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||
TestSystem.start</h3>
|
||||
<b>start</b>(<i></i>)
|
||||
<p>
|
||||
Start test program and run tests.
|
||||
</p><a NAME="TestSystem.test_replace_io" ID="TestSystem.test_replace_io"></a>
|
||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||
TestSystem.test_replace_io</h3>
|
||||
<b>test_replace_io</b>(<i></i>)
|
||||
<p>
|
||||
Test replace_io file.
|
||||
</p><dl>
|
||||
<dt>Returns:</dt>
|
||||
<dd>
|
||||
0 if successful testet
|
||||
</dd>
|
||||
</dl><a NAME="TestSystem.test_sections" ID="TestSystem.test_sections"></a>
|
||||
<h3 style="background-color:#FFFFFF;color:#FF0000">
|
||||
TestSystem.test_sections</h3>
|
||||
<b>test_sections</b>(<i></i>)
|
||||
<p>
|
||||
Test config file.
|
||||
</p><dl>
|
||||
<dt>Returns:</dt>
|
||||
<dd>
|
||||
0 if successful testet
|
||||
</dd>
|
||||
</dl>
|
||||
<div align="right"><a style="color:#0000FF" href="#top">Up</a></div>
|
||||
<hr />
|
||||
</body></html>
|
||||
@@ -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()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Project SYSTEM "Project-5.1.dtd">
|
||||
<!-- eric project file for project revpipyload -->
|
||||
<!-- Saved: 2019-06-11, 09:23:01 -->
|
||||
<!-- Saved: 2019-06-16, 15:47:42 -->
|
||||
<!-- Copyright (C) 2019 Sven Sager, akira@narux.de -->
|
||||
<Project version="5.1">
|
||||
<Language>en_US</Language>
|
||||
@@ -24,6 +24,7 @@
|
||||
<Source>revpipyload/revpipyload.py</Source>
|
||||
<Source>revpipyload/shared/__init__.py</Source>
|
||||
<Source>revpipyload/shared/ipaclmanager.py</Source>
|
||||
<Source>revpipyload/testsystem.py</Source>
|
||||
<Source>revpipyload/xrpcserver.py</Source>
|
||||
<Source>setup.py</Source>
|
||||
</Sources>
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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()
|
||||
|
||||
# Programm starten
|
||||
if proginit.pargs.test:
|
||||
from testsystem import TestSystem
|
||||
root = TestSystem()
|
||||
else:
|
||||
root = RevPiPyLoad()
|
||||
|
||||
# Programm starten
|
||||
root.start()
|
||||
|
||||
# Aufräumen
|
||||
|
||||
88
revpipyload/testsystem.py
Normal file
88
revpipyload/testsystem.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user