Commit 4d1961b1 authored by Michael Büsch's avatar Michael Büsch

Move frozen executable handling to central place

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent a29441df
......@@ -290,14 +290,9 @@ def runWithServerBackend(inputFile):
# Connect to the server
client = TestAwlSimClient()
if opt_spawnBackend:
if isWinStandalone:
client.spawnServer(serverExecutable = "awlsim-server-module.exe",
listenHost = host,
listenPort = port)
else:
client.spawnServer(interpreter = opt_interpreter,
listenHost = host,
listenPort = port)
client.spawnServer(interpreter = opt_interpreter,
listenHost = host,
listenPort = port)
writeStdout("Connecting to core server...\n")
client.connectToServer(host = host, port = port)
......
......@@ -63,14 +63,10 @@ class AwlValidator(object):
def __init__(self):
self.__client = AwlSimClient()
extraArgs = {}
if isWinStandalone:
extraArgs["serverExecutable"] = "awlsim-server-module.exe"
try:
self.__client.setLoglevel(Logging.LOG_ERROR)
self.__client.spawnServer(listenHost = "localhost",
listenPort = self._PORT_RANGE,
**extraArgs)
listenPort = self._PORT_RANGE)
self.__client.connectToServer(host = "localhost",
port = self.__client.serverProcessPort)
self.__client.setLoglevel(Logging.LOG_NONE)
......
......@@ -40,6 +40,9 @@ else:
osIsWindows = os.name == "nt" or os.name == "ce"
osIsPosix = os.name == "posix"
# Executable name of the standalone server.
standaloneServerExe = "awlsim-server-module.exe"
# isPyPy is True, if the interpreter is PyPy.
isPyPy = "PyPy" in sys.version
......@@ -57,12 +60,12 @@ isCython = False #@nocy
isMicroPython = hasattr(sys, "implementation") and\
sys.implementation.name.lower() == "micropython"
# isWinStandalone is True, if this is a Windows standalone package (py2exe)
# isWinStandalone is True, if this is a Windows standalone package (py2exe/cx_Freeze)
isWinStandalone = osIsWindows and\
(sys.executable.endswith("awlsim-gui.exe") or\
sys.executable.endswith("awlsim-client.exe") or\
sys.executable.endswith("awlsim-server.exe") or\
sys.executable.endswith("awlsim-server-module.exe") or\
sys.executable.endswith(standaloneServerExe) or\
sys.executable.endswith("awlsim-symtab.exe") or\
sys.executable.endswith("awlsim-test.exe"))
......
......@@ -51,7 +51,8 @@ class AwlSimClient(object):
interpreter=None,
serverExecutable=None,
listenHost=AwlSimServer.DEFAULT_HOST,
listenPort=AwlSimServer.DEFAULT_PORT):
listenPort=AwlSimServer.DEFAULT_PORT,
frozenExecutableMagic=True):
"""Spawn a new AwlSim-core server process.
interpreter -> The python interpreter to use. Must be either:
- None: Use sys.executable as interpreter.
......@@ -69,6 +70,17 @@ class AwlSimClient(object):
if self.serverProcess:
raise AwlSimError("Server already running")
if frozenExecutableMagic and isWinStandalone:
# We are running the frozen executable
# and the magic is turned on.
# Enforce the server executable name.
oldExecutable = serverExecutable
serverExecutable = standaloneServerExe
if oldExecutable:
printWarning("spawnServer: Overriding server "
"executable '%s' -> '%s'" %(
oldExecutable, serverExecutable))
actualListenPort = None
for port in toList(listenPort):
if not netPortIsUnused(listenHost, port):
......
......@@ -282,7 +282,6 @@ class GuiAwlSimClient(AwlSimClient, QObject):
# We are already up and running.
return
self.__serverExecutable = None
self.__interpreterList = None
self.shutdown()
......@@ -313,12 +312,10 @@ class GuiAwlSimClient(AwlSimClient, QObject):
port = port, tunnel = tunnel)
def setMode_FORK(self, portRange,
serverExecutable=None,
interpreterList=None):
host = "localhost"
if self.__mode == self.MODE_FORK:
if self.__port in portRange and\
self.__serverExecutable == serverExecutable and\
self.__interpreterList == interpreterList:
assert(self.__host == host)
# We are already up and running.
......@@ -326,29 +323,22 @@ class GuiAwlSimClient(AwlSimClient, QObject):
try:
if self.serverProcess:
if self.serverProcessPort not in portRange or\
self.__serverExecutable != serverExecutable or\
self.__interpreterList != interpreterList:
self.killSpawnedServer()
if self.serverProcess:
port = self.serverProcessPort
else:
if serverExecutable:
self.spawnServer(serverExecutable = serverExecutable,
listenHost = host,
listenPort = portRange)
else:
self.spawnServer(interpreter = interpreterList,
listenHost = host,
listenPort = portRange)
port = self.serverProcessPort
if not self.serverProcess:
self.spawnServer(interpreter = interpreterList,
listenHost = host,
listenPort = portRange)
self.shutdownTransceiver()
self.connectToServer(host = host, port = port)
self.connectToServer(host=host,
port=self.serverProcessPort)
except AwlSimError as e:
with suppressAllExc:
self.shutdown()
raise e
self.__setMode(self.MODE_FORK, host = host, port = port)
self.__serverExecutable = serverExecutable
self.__setMode(self.MODE_FORK,
host=host,
port=self.serverProcessPort)
self.__interpreterList = interpreterList
def getBlockTreeModelRef(self):
......
......@@ -544,13 +544,8 @@ class CpuWidget(QWidget):
if linkConfig.getSpawnLocalEn():
portRange = linkConfig.getSpawnLocalPortRange()
interp = linkConfig.getSpawnLocalInterpreterList()
if isWinStandalone:
# Run the frozen standalone server process
client.setMode_FORK(portRange = portRange,
serverExecutable = "awlsim-server-module.exe")
else:
client.setMode_FORK(portRange = portRange,
interpreterList = interp)
client.setMode_FORK(portRange = portRange,
interpreterList = interp)
host = port = None
else:
client.setMode_ONLINE(self, linkConfig)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment