fix problem when Beremiz is running without matiec installed
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 25 Aug 2017 11:22:08 +0300
changeset 1789 492e2cd6157e
parent 1788 a3fd80859ae3
child 1790 47fc06c13b37
fix problem when Beremiz is running without matiec installed

set matiec settings only once on first use of ProjectController class and give
user-friendly message on compilation about missing matiec
installation.


Traceback (most recent call last):
File "Beremiz.py", line 197, in <module>
beremiz.Start()
File "Beremiz.py", line 192, in Start
self.CreateApplication()
File "Beremiz.py", line 130, in CreateApplication
self.BackgroundInitialization()
File "Beremiz.py", line 137, in BackgroundInitialization
self.ImportModules()
File "Beremiz.py", line 176, in ImportModules
import BeremizIDE
File
"BeremizIDE.py", line 76, in <module>
from ProjectController import ProjectController, GetAddMenuItems,
MATIEC_ERROR_MODEL, ITEM_CONFNODE
File
"ProjectController.py", line 177, in <module>
iec2c_cfg = Iec2CSettings()
File
"ProjectController.py", line 101, in __init__
self.ieclib_c_path = self.findLibCPath()
File
"ProjectController.py", line 135, in findLibCPath
os.path.join(self.ieclib_path, "C"),
File "/usr/lib/python2.7/posixpath.py", line 70, in join
elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'
ProjectController.py
--- a/ProjectController.py	Tue Aug 22 14:15:49 2017 +0000
+++ b/ProjectController.py	Fri Aug 25 11:22:08 2017 +0300
@@ -131,10 +131,13 @@
 
     def findLibCPath(self):
         path = None
-        paths = [
-            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")))
+        if self.ieclib_path is not None:
+            paths = [
+                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):
@@ -174,9 +177,6 @@
         return self.ieclib_c_path
 
 
-iec2c_cfg = Iec2CSettings()
-
-
 class ProjectController(ConfigTreeNode, PLCControler):
     """
     This class define Root object of the confnode tree.
@@ -220,10 +220,14 @@
     </xsd:schema>
     """
     EditorType = ProjectNodeEditor
+    iec2c_cfg = None
 
     def __init__(self, frame, logger):
         PLCControler.__init__(self)
 
+        if ProjectController.iec2c_cfg is None:
+            ProjectController.iec2c_cfg = Iec2CSettings()
+
         self.MandatoryParams = None
         self._builder = None
         self._connector = None
@@ -319,10 +323,10 @@
         return self
 
     def GetIECLibPath(self):
-        return iec2c_cfg.getLibCPath()
+        return self.iec2c_cfg.getLibCPath()
 
     def GetIEC2cPath(self):
-        return iec2c_cfg.getCmd()
+        return self.iec2c_cfg.getCmd()
 
     def GetCurrentLocation(self):
         return ()
@@ -742,12 +746,17 @@
         return True
 
     def _Compile_ST_to_SoftPLC(self):
+        iec2c_libpath = self.iec2c_cfg.getLibPath()
+        if iec2c_libpath is None:
+            self.logger.write_error(_("matiec installation is not found\n"))
+            return False
+
         self.logger.write(_("Compiling IEC Program into C code...\n"))
         buildpath = self._getBuildPath()
         buildcmd = "\"%s\" %s -I \"%s\" -T \"%s\" \"%s\"" % (
-                         iec2c_cfg.getCmd(),
-                         iec2c_cfg.getOptions(),
-                         iec2c_cfg.getLibPath(),
+                         self.iec2c_cfg.getCmd(),
+                         self.iec2c_cfg.getOptions(),
+                         iec2c_libpath,
                          buildpath,
                          self._getIECcodepath())
 
@@ -818,7 +827,7 @@
         # Keep track of generated C files for later use by self.CTNGenerate_C
         self.PLCGeneratedCFiles = C_files
         # compute CFLAGS for plc
-        self.plcCFLAGS = '"-I%s" -Wno-unused-function' % iec2c_cfg.getLibCPath()
+        self.plcCFLAGS = '"-I%s" -Wno-unused-function' % self.iec2c_cfg.getLibCPath()
         return True
 
     def GetBuilder(self):