if there is no users matiec installation, then use system path to run iec2c
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Tue, 30 May 2017 17:09:33 +0300
changeset 1685 578a46fb6b30
parent 1684 1447424a7029
child 1686 85fdcc04da25
if there is no users matiec installation, then use system path to run iec2c

search for matiec libraries in system path as well

Closes #29
ProjectController.py
--- a/ProjectController.py	Tue May 23 16:06:29 2017 +0300
+++ b/ProjectController.py	Tue May 30 17:09:33 2017 +0300
@@ -88,25 +88,50 @@
 
 class Iec2CSettings():
     def __init__(self):
-        self.iec2c = os.path.join(base_folder, "matiec", "iec2c"+(".exe" if wx.Platform == '__WXMSW__' else ""))
+        self.iec2c = None
         self.iec2c_buildopts = None
-        self.ieclib_path   = os.path.join(base_folder, "matiec", "lib")
-        self.ieclib_c_path = None
-
+        self.ieclib_path   = self.findLibPath()
+        self.ieclib_c_path = self.findLibCPath()
+
+    def findObject(self, paths, test):
+        path=None
+        for p in paths:
+            if test(p):
+                path = p
+                break           
+        return path
+        
+    def findCmd(self):
+        cmd="iec2c"+(".exe" if wx.Platform == '__WXMSW__' else "")
+        paths=[
+            os.path.join(base_folder, "matiec")
+        ]
+        path = self.findObject(paths, lambda p:os.path.isfile(os.path.join(p, cmd)))
+
+        # otherwise use iec2c from PATH
+        if path is not None:
+            cmd=os.path.join(path, cmd)
+
+        return cmd
+    
+    def findLibPath(self):
+        paths=[
+            os.path.join(base_folder, "matiec", "lib"),
+            "/usr/lib/matiec"
+        ]
+        path = self.findObject(paths, lambda p:os.path.isfile(os.path.join(p, "ieclib.txt")))
+        return path
+        
     def findLibCPath(self):
-        path=""
+        path=None
         paths=[
-            os.path.join(base_folder, "matiec", "lib", "C"),
-            os.path.join(base_folder, "matiec", "lib") ]
-        for p in paths:
-            filename=os.path.join(p, "iec_types.h")
-            if (os.path.isfile(filename)):
-                path = p
-                break
+            os.path.join(self.ieclib_path, "C"),
+            self.ieclib_path]
+        path = self.findObject(paths, lambda p:os.path.isfile(os.path.join(p, "iec_types.h")))
         return path
 
     def findSupportedOptions(self):
-        buildcmd = "\"%s\" -h"%(self.iec2c)
+        buildcmd = "\"%s\" -h"%(self.getCmd())
         options =["-f", "-l", "-p"]
 
         buildopt = ""
@@ -123,6 +148,8 @@
         return buildopt
 
     def getCmd(self):
+        if self.iec2c is None:
+            self.iec2c = self.findCmd()
         return self.iec2c
 
     def getOptions(self):