mirror of
https://github.com/naruxde/revpipyload.git
synced 2025-11-08 23:23:52 +01:00
get_config und set_config hinzugefügt
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE Project SYSTEM "Project-5.1.dtd">
|
<!DOCTYPE Project SYSTEM "Project-5.1.dtd">
|
||||||
<!-- eric project file for project revpipyload -->
|
<!-- eric project file for project revpipyload -->
|
||||||
<!-- Saved: 2017-03-05, 13:46:54 -->
|
<!-- Saved: 2017-03-08, 17:50:16 -->
|
||||||
<!-- Copyright (C) 2017 Sven Sager, akira@narux.de -->
|
<!-- Copyright (C) 2017 Sven Sager, akira@narux.de -->
|
||||||
<Project version="5.1">
|
<Project version="5.1">
|
||||||
<Language>en_US</Language>
|
<Language>en_US</Language>
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
<ProgLanguage mixed="0">Python3</ProgLanguage>
|
<ProgLanguage mixed="0">Python3</ProgLanguage>
|
||||||
<ProjectType>Console</ProjectType>
|
<ProjectType>Console</ProjectType>
|
||||||
<Description>Dieser Loader wird über das Init-System geladen und führt das angegebene Pythonprogramm aus. Es ist für den RevolutionPi gedacht um automatisch das SPS-Programm zu starten.</Description>
|
<Description>Dieser Loader wird über das Init-System geladen und führt das angegebene Pythonprogramm aus. Es ist für den RevolutionPi gedacht um automatisch das SPS-Programm zu starten.</Description>
|
||||||
<Version>0.2.2</Version>
|
<Version>0.2.3</Version>
|
||||||
<Author>Sven Sager</Author>
|
<Author>Sven Sager</Author>
|
||||||
<Email>akira@narux.de</Email>
|
<Email>akira@narux.de</Email>
|
||||||
<Eol index="-1"/>
|
<Eol index="-1"/>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
#
|
#
|
||||||
# RevPiPyLoad
|
# RevPiPyLoad
|
||||||
# Version: see global var plcverion
|
# Version: see global var pyloadverion
|
||||||
#
|
#
|
||||||
# Webpage: https://revpimodio.org/revpipyplc/
|
# Webpage: https://revpimodio.org/revpipyplc/
|
||||||
# (c) Sven Sager, License: LGPLv3
|
# (c) Sven Sager, License: LGPLv3
|
||||||
@@ -22,7 +22,7 @@ from xmlrpc.client import Binary
|
|||||||
from xmlrpc.server import SimpleXMLRPCServer
|
from xmlrpc.server import SimpleXMLRPCServer
|
||||||
|
|
||||||
|
|
||||||
pyloadverion = "0.2.2"
|
pyloadverion = "0.2.3"
|
||||||
|
|
||||||
|
|
||||||
class LogReader():
|
class LogReader():
|
||||||
@@ -313,6 +313,7 @@ class RevPiPyLoad(proginit.ProgInit):
|
|||||||
|
|
||||||
self.xsrv.register_function(self.logr.get_applines, "get_applines")
|
self.xsrv.register_function(self.logr.get_applines, "get_applines")
|
||||||
self.xsrv.register_function(self.logr.get_applog, "get_applog")
|
self.xsrv.register_function(self.logr.get_applog, "get_applog")
|
||||||
|
self.xsrv.register_function(self.get_config, "get_config")
|
||||||
self.xsrv.register_function(self.logr.get_plclines, "get_plclines")
|
self.xsrv.register_function(self.logr.get_plclines, "get_plclines")
|
||||||
self.xsrv.register_function(self.logr.get_plclog, "get_plclog")
|
self.xsrv.register_function(self.logr.get_plclog, "get_plclog")
|
||||||
self.xsrv.register_function(self.xml_plcdownload, "plcdownload")
|
self.xsrv.register_function(self.xml_plcdownload, "plcdownload")
|
||||||
@@ -323,6 +324,7 @@ class RevPiPyLoad(proginit.ProgInit):
|
|||||||
self.xsrv.register_function(self.xml_plcupload, "plcupload")
|
self.xsrv.register_function(self.xml_plcupload, "plcupload")
|
||||||
self.xsrv.register_function(self.xml_plcuploadclean, "plcuploadclean")
|
self.xsrv.register_function(self.xml_plcuploadclean, "plcuploadclean")
|
||||||
self.xsrv.register_function(self.xml_reload, "reload")
|
self.xsrv.register_function(self.xml_reload, "reload")
|
||||||
|
self.xsrv.register_function(self.set_config, "set_config")
|
||||||
self.xsrv.register_function(lambda: pyloadverion, "version")
|
self.xsrv.register_function(lambda: pyloadverion, "version")
|
||||||
proginit.logger.debug("created xmlrpc server")
|
proginit.logger.debug("created xmlrpc server")
|
||||||
|
|
||||||
@@ -361,7 +363,20 @@ class RevPiPyLoad(proginit.ProgInit):
|
|||||||
proginit.logger.debug("got reload config signal")
|
proginit.logger.debug("got reload config signal")
|
||||||
self.evt_loadconfig.set()
|
self.evt_loadconfig.set()
|
||||||
|
|
||||||
def packplc(self):
|
def get_config(self):
|
||||||
|
dc = {}
|
||||||
|
dc["autoreload"] = self.autoreload
|
||||||
|
dc["autostart"] = self.autostart
|
||||||
|
dc["plcworkdir"] = self.plcworkdir
|
||||||
|
dc["plcprogram"] = self.plcprog
|
||||||
|
dc["plcslave"] = self.plcslave
|
||||||
|
dc["xmlrpc"] = self.xmlrpc
|
||||||
|
dc["xmlrpcport"] = self.globalconfig["DEFAULT"].get("xmlrpcport", 55123)
|
||||||
|
dc["zeroonerror"] = self.zerooneerror
|
||||||
|
dc["zeroonexit"] = self.zeroonexit
|
||||||
|
return dc
|
||||||
|
|
||||||
|
def packapp(self):
|
||||||
"""Erzeugt aus dem PLC-Programm ein TAR-File."""
|
"""Erzeugt aus dem PLC-Programm ein TAR-File."""
|
||||||
filename = mktemp(suffix=".tar.gz", prefix="plc")
|
filename = mktemp(suffix=".tar.gz", prefix="plc")
|
||||||
try:
|
try:
|
||||||
@@ -372,6 +387,31 @@ class RevPiPyLoad(proginit.ProgInit):
|
|||||||
return ""
|
return ""
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
def set_config(self, dc, loadnow=False):
|
||||||
|
keys = [
|
||||||
|
"autoreload",
|
||||||
|
"autostart",
|
||||||
|
"plcprogram",
|
||||||
|
"plcslave",
|
||||||
|
"xmlrpc",
|
||||||
|
"xmlrpcport",
|
||||||
|
"zeroonerror",
|
||||||
|
"zeroonexit"
|
||||||
|
]
|
||||||
|
|
||||||
|
# Werte übernehmen
|
||||||
|
for key in keys:
|
||||||
|
if key in dc:
|
||||||
|
self.globalconfig.set("DEFAULT", key, str(dc[key]))
|
||||||
|
|
||||||
|
# conf-Datei schreiben
|
||||||
|
fh = open(self.globalconffile, "w")
|
||||||
|
self.globalconfig.write(fh)
|
||||||
|
|
||||||
|
if loadnow:
|
||||||
|
# RevPiPyLoad neu konfigurieren
|
||||||
|
self.evt_loadconfig.set()
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Start plcload and PLC python program."""
|
"""Start plcload and PLC python program."""
|
||||||
proginit.logger.info("starting revpipyload")
|
proginit.logger.info("starting revpipyload")
|
||||||
@@ -414,7 +454,7 @@ class RevPiPyLoad(proginit.ProgInit):
|
|||||||
def xml_plcdownload(self, file=None):
|
def xml_plcdownload(self, file=None):
|
||||||
# TODO: Daten blockweise übertragen
|
# TODO: Daten blockweise übertragen
|
||||||
if file is None:
|
if file is None:
|
||||||
return self.packplc()
|
return self.packapp()
|
||||||
elif os.path.exists(file):
|
elif os.path.exists(file):
|
||||||
fh = open(file, "rb")
|
fh = open(file, "rb")
|
||||||
xmldata = Binary(fh.read())
|
xmldata = Binary(fh.read())
|
||||||
@@ -424,15 +464,20 @@ class RevPiPyLoad(proginit.ProgInit):
|
|||||||
|
|
||||||
def xml_plcexitcode(self):
|
def xml_plcexitcode(self):
|
||||||
proginit.logger.debug("xmlrpc call plcexitcode")
|
proginit.logger.debug("xmlrpc call plcexitcode")
|
||||||
return -1 if self.plc.is_alive() else self.plc.exitcode
|
if self.plc is None:
|
||||||
|
return -2
|
||||||
|
elif self.plc.is_alive():
|
||||||
|
return -1
|
||||||
|
else:
|
||||||
|
return self.plc.exitcode
|
||||||
|
|
||||||
def xml_plcrunning(self):
|
def xml_plcrunning(self):
|
||||||
proginit.logger.debug("xmlrpc call plcrunning")
|
proginit.logger.debug("xmlrpc call plcrunning")
|
||||||
return self.plc.is_alive()
|
return False if self.plc is None else self.plc.is_alive()
|
||||||
|
|
||||||
def xml_plcstart(self):
|
def xml_plcstart(self):
|
||||||
proginit.logger.debug("xmlrpc call plcstart")
|
proginit.logger.debug("xmlrpc call plcstart")
|
||||||
if self.plc.is_alive():
|
if self.plc is not None and self.plc.is_alive():
|
||||||
return -1
|
return -1
|
||||||
else:
|
else:
|
||||||
self.plc = self._plcthread()
|
self.plc = self._plcthread()
|
||||||
@@ -444,9 +489,12 @@ class RevPiPyLoad(proginit.ProgInit):
|
|||||||
|
|
||||||
def xml_plcstop(self):
|
def xml_plcstop(self):
|
||||||
proginit.logger.debug("xmlrpc call plcstop")
|
proginit.logger.debug("xmlrpc call plcstop")
|
||||||
|
if self.plc is not None:
|
||||||
self.plc.stop()
|
self.plc.stop()
|
||||||
self.plc.join()
|
self.plc.join()
|
||||||
return self.plc.exitcode
|
return self.plc.exitcode
|
||||||
|
else:
|
||||||
|
return -1
|
||||||
|
|
||||||
def xml_plcupload(self, filedata):
|
def xml_plcupload(self, filedata):
|
||||||
# TODO: Daten blockweise annehmen
|
# TODO: Daten blockweise annehmen
|
||||||
@@ -465,7 +513,7 @@ class RevPiPyLoad(proginit.ProgInit):
|
|||||||
fh_tar.extractall()
|
fh_tar.extractall()
|
||||||
fh_tar.close()
|
fh_tar.close()
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
# Kein Archiv
|
# Kein Archiv
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
|
|||||||
Reference in New Issue
Block a user