From 34e8b4635b6655a6d08f58a583c9ab2bcce05e33 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Mon, 1 Aug 2016 12:28:00 +0200 Subject: [PATCH] Scanning for CuraEngine and stop if it was not found So far I ran 2 or 3 times into the problem that my engine was not up to date. The bad thing here is that there is always an updated version from my PPA on the PC. So first this commit gives the possibility to look for CuraEngine in the $PATH directories. Before I had to copy it always manually, eg. via "cp $(which CuraEngine) bin/CuraEngine" in my workbench. Second, people can get into the situation that CuraEngine is missing at all. So before making Cura loop and try to use an executable that does not exist, better raise an Exception here. An additional info message tells about the location being used. Does not contribute to any JIRA issue (I think), but makes my life easier. --- .../CuraEngineBackend/CuraEngineBackend.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/plugins/CuraEngineBackend/CuraEngineBackend.py b/plugins/CuraEngineBackend/CuraEngineBackend.py index a822512218..0569eaf946 100644 --- a/plugins/CuraEngineBackend/CuraEngineBackend.py +++ b/plugins/CuraEngineBackend/CuraEngineBackend.py @@ -39,16 +39,35 @@ class CuraEngineBackend(Backend): # # This registers all the signal listeners and prepares for communication # with the back-end in general. + + executableName = "CuraEngine" + def __init__(self): super().__init__() # Find out where the engine is located, and how it is called. # This depends on how Cura is packaged and which OS we are running on. - default_engine_location = os.path.join(Application.getInstallPrefix(), "bin", "CuraEngine") + default_engine_location = None + if os.path.exists(os.path.join(Application.getInstallPrefix(), "bin", "CuraEngine")): + default_engine_location = os.path.join(Application.getInstallPrefix(), "bin", "CuraEngine") if hasattr(sys, "frozen"): default_engine_location = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "CuraEngine") if Platform.isWindows(): default_engine_location += ".exe" + if Platform.isLinux() and not default_engine_location: + if not os.getenv('PATH'): + raise OSError("There is something wrong with your Linux installation.") + for pathdir in os.getenv('PATH').split(os.pathsep): + execpath = os.path.join(pathdir, self.executableName) + if os.path.exists(execpath): + default_engine_location = execpath + break + + if not default_engine_location: + raise EnvironmentError("Could not find CuraEngine") + + Logger.log("i", "Found CuraEngine at: %s" %(default_engine_location)) + default_engine_location = os.path.abspath(default_engine_location) Preferences.getInstance().addPreference("backend/location", default_engine_location)