]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
*** empty log message ***
authoradam <adam>
Tue, 20 Jul 2010 13:12:13 +0000 (13:12 +0000)
committeradam <adam>
Tue, 20 Jul 2010 13:12:13 +0000 (13:12 +0000)
src/SalomeApp/Makefile.am
src/SalomeApp/addvars2notebook.py [new file with mode: 0644]

index 9c94a2680f9775591cca7d2d46ebe8d82f7caa24..e7e3b53654ef28a90cf3bec91fd386625a905a79 100755 (executable)
@@ -98,6 +98,8 @@ nodist_libSalomeApp_la_SOURCES = $(MOC_FILES)
 # python modules
 salomepython_PYTHON = salome_pluginsmanager.py
 
+dist_salomescript_DATA = addvars2notebook.py
+
 dist_salomeres_DATA =          \
        resources/SalomeApp.ini \
        resources/SalomeApp.xml
diff --git a/src/SalomeApp/addvars2notebook.py b/src/SalomeApp/addvars2notebook.py
new file mode 100644 (file)
index 0000000..6f23755
--- /dev/null
@@ -0,0 +1,67 @@
+
+import os
+import os.path
+
+def addvars2notebook(filename):
+    #
+    vars_and_values = []
+    contents = []
+    #
+    directory = os.path.dirname(filename)
+    base = os.path.basename(filename)
+    prefix = base[:-3] # remove ".py"
+    prefix = prefix + '_'
+    from os import listdir
+    l = listdir(directory)
+    for f in l:
+        if f.find(prefix) != 0: continue
+        if f[-3:] != ".py": continue
+        module = f[len(prefix):-3]
+        try:
+            mod = __import__("addvars2notebook_%s"%(module))
+        except ImportError:
+            continue
+        try:
+            func = mod.addvars2notebook
+        except AttributeError:
+            continue
+        fff = os.path.join(directory, f)
+        content = func(fff, vars_and_values)
+        contents.append([fff, content])
+        pass
+    #
+    if vars_and_values:
+        stream = open(filename)
+        content = stream.read()
+        stream.close()
+        fields = content.split("import iparameters")
+        if len(fields) == 2:
+            begin = fields[0]
+            if begin.find("## NoteBook E.A.") >= 0:
+                begin = begin.split("## NoteBook E.A.")[0]
+                pass
+            end = "import iparameters" + fields[1]
+            content = begin
+            content += "## NoteBook E.A.\n"
+            for var, value in vars_and_values:
+                content += "notebook.set(%s,%s)\n"%(var.__repr__(), value)
+                pass
+            content += end
+            stream = open(filename, "w")
+            stream.write(content)
+            stream.close()
+            #
+            for fff, content in contents:
+                stream = open(fff, "w")
+                stream.write(content)
+                stream.close()
+                pass
+            pass
+        pass
+    #
+    return
+
+if __name__ == "__main__":
+    import sys
+    addvars2notebook(sys.argv[1])
+    pass