From 8dc8d57607caf457902fb2123ecd640b88b8db27 Mon Sep 17 00:00:00 2001
From: Maurice Raybaud <mauriceraybaud@hotmail.fr>
Date: Sun, 24 Apr 2011 13:03:31 +0000
Subject: [PATCH] Added Linux Binary detection thanks to Bela Mihalik's patch.

---
 render_povray/render.py | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/render_povray/render.py b/render_povray/render.py
index 3ac7b48c5..cfdfddf99 100644
--- a/render_povray/render.py
+++ b/render_povray/render.py
@@ -1707,10 +1707,37 @@ class PovrayRender(bpy.types.RenderEngine):
             # DH - added -d option to prevent render window popup which leads to segfault on linux
             extra_args.append("-d")
 
-            # TODO, when POV-Ray isn't found this can probably still give a cryptic error on linux,
-            # would be nice to be able to detect if it exists
+            isExists = False
+            sysPathList = os.getenv("PATH").split(':')
+            sysPathList.append("")
 
-            print("Command line arguments passed: " + str(extra_args))
+            for dirName in sysPathList:
+                if (os.path.exists(os.path.join(dirName, pov_binary))):
+                    isExists = True
+                    break
+
+            if not isExists:
+                print("POV-Ray 3.7: could not found execute '%s' - not if PATH" % pov_binary)
+                import traceback
+                traceback.print_exc()
+                print ("***-DONE-***")
+                return False
+
+            try:
+                self._process = subprocess.Popen([pov_binary, self._temp_file_ini] + extra_args)
+
+            except OSError:
+                # TODO, report api
+                print("POV-Ray 3.7: could not execute '%s'" % pov_binary)
+                import traceback
+                traceback.print_exc()
+                print ("***-DONE-***")
+                return False
+
+            else:
+                print("POV-Ray 3.7 found")
+                print("Command line arguments passed: " + str(extra_args))
+                return True
 
     def _cleanup(self):
         for f in (self._temp_file_in, self._temp_file_ini, self._temp_file_out):
-- 
GitLab