From 34e8b4635b6655a6d08f58a583c9ab2bcce05e33 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Mon, 1 Aug 2016 12:28:00 +0200 Subject: [PATCH 1/7] 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) From 92983636b044eee9cfb0a5d29a58302a4a684f0e Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Mon, 1 Aug 2016 12:29:57 +0200 Subject: [PATCH 2/7] Use self.executableName in __init__ --- plugins/CuraEngineBackend/CuraEngineBackend.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/CuraEngineBackend/CuraEngineBackend.py b/plugins/CuraEngineBackend/CuraEngineBackend.py index 0569eaf946..d9b973cab4 100644 --- a/plugins/CuraEngineBackend/CuraEngineBackend.py +++ b/plugins/CuraEngineBackend/CuraEngineBackend.py @@ -48,10 +48,10 @@ class CuraEngineBackend(Backend): # 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 = None - if os.path.exists(os.path.join(Application.getInstallPrefix(), "bin", "CuraEngine")): - default_engine_location = os.path.join(Application.getInstallPrefix(), "bin", "CuraEngine") + if os.path.exists(os.path.join(Application.getInstallPrefix(), "bin", self.executableName)): + default_engine_location = os.path.join(Application.getInstallPrefix(), "bin", self.executableName) if hasattr(sys, "frozen"): - default_engine_location = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "CuraEngine") + default_engine_location = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), self.executableName) if Platform.isWindows(): default_engine_location += ".exe" if Platform.isLinux() and not default_engine_location: From fb1b199c6a230c3d7b13a9e9bfbe9d276e02db97 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Tue, 2 Aug 2016 08:47:48 +0200 Subject: [PATCH 3/7] Moving self.executableName into __init__ as executable_name --- plugins/CuraEngineBackend/CuraEngineBackend.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugins/CuraEngineBackend/CuraEngineBackend.py b/plugins/CuraEngineBackend/CuraEngineBackend.py index d9b973cab4..50694b4514 100644 --- a/plugins/CuraEngineBackend/CuraEngineBackend.py +++ b/plugins/CuraEngineBackend/CuraEngineBackend.py @@ -40,25 +40,24 @@ 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. + executable_name = "CuraEngine" default_engine_location = None - if os.path.exists(os.path.join(Application.getInstallPrefix(), "bin", self.executableName)): - default_engine_location = os.path.join(Application.getInstallPrefix(), "bin", self.executableName) + if os.path.exists(os.path.join(Application.getInstallPrefix(), "bin", executable_name)): + default_engine_location = os.path.join(Application.getInstallPrefix(), "bin", executable_name) if hasattr(sys, "frozen"): - default_engine_location = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), self.executableName) + default_engine_location = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), executable_name) 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) + execpath = os.path.join(pathdir, executable_name) if os.path.exists(execpath): default_engine_location = execpath break From 6b61fdbe5cdeb4501b6f3f654d83a9b55252a60f Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Tue, 2 Aug 2016 08:49:09 +0200 Subject: [PATCH 4/7] Using double quotes of course --- plugins/CuraEngineBackend/CuraEngineBackend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/CuraEngineBackend/CuraEngineBackend.py b/plugins/CuraEngineBackend/CuraEngineBackend.py index 50694b4514..ba6f6bf7b7 100644 --- a/plugins/CuraEngineBackend/CuraEngineBackend.py +++ b/plugins/CuraEngineBackend/CuraEngineBackend.py @@ -54,7 +54,7 @@ class CuraEngineBackend(Backend): if Platform.isWindows(): default_engine_location += ".exe" if Platform.isLinux() and not default_engine_location: - if not os.getenv('PATH'): + 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, executable_name) From 32880a093e3acc42cf4b028c5d3985bb376a3e7b Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Tue, 2 Aug 2016 09:37:17 +0200 Subject: [PATCH 5/7] And again double quotes.. --- plugins/CuraEngineBackend/CuraEngineBackend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/CuraEngineBackend/CuraEngineBackend.py b/plugins/CuraEngineBackend/CuraEngineBackend.py index ba6f6bf7b7..82ee3b8c84 100644 --- a/plugins/CuraEngineBackend/CuraEngineBackend.py +++ b/plugins/CuraEngineBackend/CuraEngineBackend.py @@ -56,7 +56,7 @@ class CuraEngineBackend(Backend): 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): + for pathdir in os.getenv("PATH").split(os.pathsep): execpath = os.path.join(pathdir, executable_name) if os.path.exists(execpath): default_engine_location = execpath From 7c3b6814d01af30cf0fb736e06fd3b44d679b0ae Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Mon, 8 Aug 2016 10:45:41 +0200 Subject: [PATCH 6/7] Removing strays --- plugins/CuraEngineBackend/CuraEngineBackend.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/CuraEngineBackend/CuraEngineBackend.py b/plugins/CuraEngineBackend/CuraEngineBackend.py index 82ee3b8c84..82229ca8ac 100644 --- a/plugins/CuraEngineBackend/CuraEngineBackend.py +++ b/plugins/CuraEngineBackend/CuraEngineBackend.py @@ -13,7 +13,6 @@ from UM.Resources import Resources from UM.Settings.Validator import ValidatorState #To find if a setting is in an error state. We can't slice then. from UM.Platform import Platform - import cura.Settings from cura.OneAtATimeIterator import OneAtATimeIterator @@ -33,7 +32,6 @@ import Arcus from UM.i18n import i18nCatalog catalog = i18nCatalog("cura") - class CuraEngineBackend(Backend): ## Starts the back-end plug-in. # From 42db29d86ad4c0341d0e5152c0fc2d5d656d05fd Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Mon, 8 Aug 2016 10:47:19 +0200 Subject: [PATCH 7/7] Removing the stray @awhiemstra mentioned --- plugins/CuraEngineBackend/CuraEngineBackend.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/CuraEngineBackend/CuraEngineBackend.py b/plugins/CuraEngineBackend/CuraEngineBackend.py index 82229ca8ac..4abf992312 100644 --- a/plugins/CuraEngineBackend/CuraEngineBackend.py +++ b/plugins/CuraEngineBackend/CuraEngineBackend.py @@ -37,7 +37,6 @@ class CuraEngineBackend(Backend): # # This registers all the signal listeners and prepares for communication # with the back-end in general. - def __init__(self): super().__init__()