Fix bug when importing and loading not well formatted eds files
authorLaurent Bessard
Fri, 15 Jun 2012 18:24:26 +0200
changeset 740 b6646a975f23
parent 739 4faa0bb578e0
child 741 b1a73ddc514b
Fix bug when importing and loading not well formatted eds files
objdictgen/commondialogs.py
objdictgen/eds_utils.py
objdictgen/nodelist.py
--- a/objdictgen/commondialogs.py	Wed Jun 13 19:08:58 2012 +0200
+++ b/objdictgen/commondialogs.py	Fri Jun 15 18:24:26 2012 +0200
@@ -1244,14 +1244,20 @@
                                wx.OPEN)
         if dialog.ShowModal() == wx.ID_OK:
             filepath = dialog.GetPath()
-            if os.path.isfile(filepath):
-                result = self.NodeList.ImportEDSFile(filepath)
-                if result:
-                    message = wx.MessageDialog(self, _("%s\nWould you like to replace it ?")%result, _("Question"), wx.YES_NO|wx.ICON_QUESTION)
-                    if message.ShowModal() == wx.ID_YES:
-                        self.NodeList.ImportEDSFile(filepath, True)
-                    message.Destroy()
+        else:
+            filepath = ""
         dialog.Destroy()
+        if os.path.isfile(filepath):
+            result, question = self.NodeList.ImportEDSFile(filepath)
+            if result is not None and question:
+                dialog = wx.MessageDialog(self, _("%s\nWould you like to replace it ?")%result, _("Question"), wx.YES_NO|wx.ICON_QUESTION)
+                if dialog.ShowModal() == wx.ID_YES:
+                    dialog, question = self.NodeList.ImportEDSFile(filepath, True)
+                dialog.Destroy()
+            if result is not None and not question:
+                dialog = wx.MessageDialog(self, result, _("Error"), wx.OK|wx.ICON_ERROR)
+                dialog.ShowModal()
+                dialog.Destroy()
         self.RefreshEDSFile()
         event.Skip()
 
--- a/objdictgen/eds_utils.py	Wed Jun 13 19:08:58 2012 +0200
+++ b/objdictgen/eds_utils.py	Fri Jun 15 18:24:26 2012 +0200
@@ -323,7 +323,7 @@
                 # verify that there is no whitespace into keyname
                 if keyname.isalnum():
                     # value can be preceded and followed by whitespaces, so we escape them
-                    value = value.strip()
+                    value = value.strip().replace(" ", "")
                     # First case, value starts with "$NODEID", then it's a formula
                     if value.upper().startswith("$NODEID"):
                         try:
@@ -379,19 +379,19 @@
             required = set(ENTRY_TYPES[values["OBJECTTYPE"]]["require"])
             # Verify that parameters defined contains all the parameters required
             if not keys.issuperset(required):
-                missing = required.difference(keys)
+                missing = required.difference(keys)._data.keys()
                 if len(missing) > 1:
                     attributes = _("Attributes %s are")%_(", ").join(["\"%s\""%attribute for attribute in missing])
                 else:
-                    attributes = _("Attribute \"%s\" is")%missing.pop()
+                    attributes = _("Attribute \"%s\" is")%missing[0]
                 raise SyntaxError, _("Error on section \"[%s]\":\n%s required for a %s entry")%(section_name, attributes, ENTRY_TYPES[values["OBJECTTYPE"]]["name"])
             # Verify that parameters defined are all in the possible parameters
             if not keys.issubset(possible):
-                unsupported = keys.difference(possible)
+                unsupported = keys.difference(possible)._data.keys()
                 if len(unsupported) > 1:
                     attributes = _("Attributes %s are")%_(", ").join(["\"%s\""%attribute for attribute in unsupported])
                 else:
-                    attributes = _("Attribute \"%s\" is")%unsupported.pop()
+                    attributes = _("Attribute \"%s\" is")%unsupported[0]
                 raise SyntaxError, _("Error on section \"[%s]\":\n%s unsupported for a %s entry")%(section_name, attributes, ENTRY_TYPES[values["OBJECTTYPE"]]["name"])
             
             VerifyValue(values, section_name, "ParameterValue")
--- a/objdictgen/nodelist.py	Wed Jun 13 19:08:58 2012 +0200
+++ b/objdictgen/nodelist.py	Fri Jun 15 18:24:26 2012 +0200
@@ -74,6 +74,9 @@
     def GetSlaveNumber(self):
         return len(self.SlaveNodes)
     
+    def GetSlaveName(self, idx):
+        return self.SlaveNodes[idx]["Name"]
+    
     def GetSlaveNames(self):
         nodes = self.SlaveNodes.keys()
         nodes.sort()
@@ -134,10 +137,10 @@
         dir, file = os.path.split(edspath)
         eds = os.path.join(self.EDSFolder, file)
         if not force and os.path.isfile(eds):
-            return _("EDS file already imported")
+            return _("EDS file already imported"), True
         else:
             shutil.copy(edspath, self.EDSFolder)
-            return self.LoadEDS(file)
+            return self.LoadEDS(file), False
     
     def LoadEDS(self, eds):
         edspath = os.path.join(self.EDSFolder, eds)