FileHandler sauber schließen

Procimg und pictory Konfiguraiton über Parameter übergebbar für Simulationen
This commit is contained in:
2017-08-15 12:35:12 +02:00
parent d247755cde
commit 9da1651ec1
2 changed files with 20 additions and 7 deletions

View File

@@ -48,6 +48,14 @@ def configure():
"-f", "--logfile", dest="logfile",
help="Save log entries to this file"
)
parser.add_argument(
"--procimg", dest="procimg",
help="Path to process image"
)
parser.add_argument(
"--pictory", dest="configrsc",
help="piCtory file to use"
)
parser.add_argument(
"-v", "--verbose", action="count", dest="verbose",
help="Switch on verbose logging"

View File

@@ -297,7 +297,7 @@ class RevPiPlc(Thread):
def _zeroprocimg(self):
"""Setzt Prozessabbild auf NULL."""
if os.path.exists("/dev/piControl0"):
f = open("/dev/piControl0", "w+b", 0)
with open("/dev/piControl0", "w+b", 0) as f:
f.write(bytes(4096))
def newlogfile(self):
@@ -449,6 +449,7 @@ class RevPiPyLoad():
# piCtory Konfiguration an bekannten Stellen prüfen
global configrsc
configrsc = proginit.pargs.configrsc
lst_rsc = ["/etc/revpi/config.rsc", "/opt/KUNBUS/config.rsc"]
for rscfile in lst_rsc:
if os.access(rscfile, os.F_OK | os.R_OK):
@@ -460,6 +461,11 @@ class RevPiPyLoad():
"".format(", ".join(lst_rsc))
)
# Alternatives Processabbild verwenden
if proginit.pargs.procimg is not None:
global procimg
procimg = proginit.pargs.procimg
# rap Katalog an bekannten Stellen prüfen und laden
global rapcatalog
lst_rap = [
@@ -851,9 +857,8 @@ class RevPiPyLoad():
file = self.packapp(mode, pictory)
if os.path.exists(file):
fh = open(file, "rb")
with open(file, "rb") as fh:
xmldata = Binary(fh.read())
fh.close()
os.remove(file)
return xmldata
return Binary()
@@ -996,7 +1001,7 @@ class RevPiPyLoad():
self.globalconfig.set("DEFAULT", key, str(dc[key]))
# conf-Datei schreiben
fh = open(proginit.globalconffile, "w")
with open(proginit.globalconffile, "w") as fh:
self.globalconfig.write(fh)
proginit.logger.info(
"got new config and wrote it to {}".format(proginit.globalconffile)