]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/PythonAPI/model/dump/DumpAssistant.py
Salome HOME
updated copyright message
[modules/shaper.git] / src / PythonAPI / model / dump / DumpAssistant.py
index 3170cc8570794ee6d7be7beeb43b2d38fb071a4e..fc7a20f22dba84a1b47a98d1298f292d79065636 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+# Copyright (C) 2014-2023  CEA, EDF
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -50,28 +50,39 @@ class DumpAssistant(ModelHighAPI.ModelHighAPI_Dumper):
     def collectFeatures(self):
         self.myFeatures = {}
         self.myWrapperNames = {}
-        for aModule in sys.modules:
-            for aName, anObj in inspect.getmembers(sys.modules[aModule], inspect.isclass):
+        # Fixing [bos #26531] [CEA] Shaper tests fail with SEGFAULT
+        # Use copy of sys.modules to avoid exception "dictionary changed size during iteration"
+        sys_modules = sys.modules.copy()
+        for aModule in sys_modules:
+            for aName, anObj in inspect.getmembers(sys_modules[aModule], inspect.isclass):
                 if issubclass(anObj, ModelHighAPI.ModelHighAPI_Interface) and hasattr(anObj, "ID") and anObj.dump != ModelHighAPI.ModelHighAPI_Interface.dump:
                     self.myFeatures[anObj.ID()] = anObj
                     self.myWrapperNames[anObj.ID()] = aName
 
     ## Create wrapper for a given feature and dump it
     def dumpFeature(self, theFeature, theForce):
+        aDumper = None
         aFeatureKind = theFeature.getKind()
         if aFeatureKind in self.myFeatures:
             # Dump only feature created by user (in history).
             # Also dump Export and RemoveResults features (hard-coded here in order not to change the data model).
             # For all other features, just keep their name.
             if theForce or theFeature.isInHistory() or aFeatureKind=="Export" or aFeatureKind=="RemoveResults":
-                self.myFeatures[aFeatureKind](theFeature).dump(self)
+                aDumper = self.myFeatures[aFeatureKind](theFeature)
+                # Dump comment for the operation before the dumping of the feature to improve the readability of a script.
+                if self.dumpCommentBeforeFeature(theFeature):
+                    self.__print__("\n### Create " + theFeature.getKind())
+                    self.newline()
             else:
                 self.name(theFeature)
                 self.clearNotDumped()
         else:
             # Probably the feature is a constraint, try to dump it with SketchAPI_Constraint.
             # In case of theFeature is not a constraint, it will not be dumped.
-            self.myFeatures[SketchAPI.SketchAPI_Constraint.ID()](theFeature).dump(self)
+            self.name(theFeature, False, True, True)
+            aDumper = self.myFeatures[SketchAPI.SketchAPI_Constraint.ID()](theFeature)
+        if aDumper is not None:
+            aDumper.dump(self)
 
     ## Create wrapper for a folder and dump it
     def dumpFolder(self, theFolder):