aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Buesch <m@bues.ch>2019-01-07 19:20:42 +0100
committerMichael Buesch <m@bues.ch>2019-01-07 19:59:02 +0100
commit23615f6338655309f1167b43e2744514489a8f33 (patch)
treed1b729ed770321e24d96fbe9d2a782d324c74e71
parent054e2e24007cfa5ed8bb179f6a74fe89181fa10f (diff)
downloadawlsim-awlsim-0.68.x.zip
awlsim-awlsim-0.68.x.tar.xz
coreserver: Improve project loading robustnessawlsim-0.68.x
Signed-off-by: Michael Buesch <m@bues.ch>
-rw-r--r--awlsim/coreserver/server.py49
1 files changed, 36 insertions, 13 deletions
diff --git a/awlsim/coreserver/server.py b/awlsim/coreserver/server.py
index 2aa0174..0a1d884 100644
--- a/awlsim/coreserver/server.py
+++ b/awlsim/coreserver/server.py
@@ -2,7 +2,7 @@
#
# AWL simulator - PLC core server
#
-# Copyright 2013-2018 Michael Buesch <m@bues.ch>
+# Copyright 2013-2019 Michael Buesch <m@bues.ch>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -519,10 +519,16 @@ class AwlSimServer(object): #+cdef
def __generateProject(self):
cpu = self.__sim.getCPU()
- awlSources = self.awlSourceContainer.getSources()
- fupSources = self.fupSourceContainer.getSources()
+ awlSources = [ source
+ for source in self.awlSourceContainer.getSources()
+ if not source.volatile ]
+ fupSources = [ source
+ for source in self.fupSourceContainer.getSources()
+ if not source.volatile ]
kopSources = [] #TODO
- symTabSources = self.symTabSourceContainer.getSources()
+ symTabSources = [ source
+ for source in self.symTabSourceContainer.getSources()
+ if not source.volatile ]
libSelections = self.loadedLibSelections[:]
cpuSpecs = cpu.getSpecs() # (Note: not a deep-copy)
cpuConf = cpu.getConf() # (Note: not a deep-copy)
@@ -1145,16 +1151,33 @@ class AwlSimServer(object): #+cdef
if not project:
return
- if isString(project):
- if fileExists(project) == False and writeBack:
- # The project file does not exist.
- # Create an empty one.
- printInfo("Creating empty project at '%s'" %\
- project)
- empty = Project(project)
- empty.toFile()
- project = Project.fromProjectOrRawAwlFile(project)
printDebug("Loading project '%s'" % str(project))
+ if isString(project):
+ projectFile = project
+
+ if writeBack:
+ # If the project file exists and it has zero size
+ # then delete the file.
+ if fileExists(projectFile):
+ with contextlib.suppress(IOError, OSError):
+ if not os.path.getsize(projectFile):
+ os.unlink(projectFile)
+ printInfo("Purged empty project "
+ "file at '%s'." % projectFile)
+ if not fileExists(projectFile):
+ # The project file does not exist.
+ # Create an empty one.
+ printInfo("Creating empty project at '%s'" % (
+ projectFile))
+ empty = Project(projectFile)
+ empty.toFile()
+ # Load the project data.
+ try:
+ project = Project.fromFile(projectFile)
+ except AwlSimError as e:
+ raise AwlSimError("AwlSimServer: "
+ "Failed to load project file '%s':\n%s" % (
+ projectFile, e.message))
self.__resetAll()
bues.ch cgit interface