Back to index

salome-gui  6.5.0
Functions
addvars2notebook Namespace Reference

Functions

def addvars2notebook

Function Documentation

Definition at line 23 of file addvars2notebook.py.

00023 
00024 def addvars2notebook(filename):
00025     #
00026     vars_and_values = []
00027     contents = []
00028     #
00029     directory = os.path.dirname(filename)
00030     base = os.path.basename(filename)
00031     prefix = base[:-3] # remove ".py"
00032     prefix = prefix + '_'
00033     from os import listdir
00034     l = listdir(directory)
00035     for f in l:
00036         if f.find(prefix) != 0: continue
00037         if f[-3:] != ".py": continue
00038         module = f[len(prefix):-3]
00039         try:
00040             mod = __import__("addvars2notebook_%s"%(module))
00041         except ImportError:
00042             continue
00043         try:
00044             func = mod.addvars2notebook
00045         except AttributeError:
00046             continue
00047         fff = os.path.join(directory, f)
00048         content = func(fff, vars_and_values)
00049         contents.append([fff, content])
00050         pass
00051     #
00052     if vars_and_values:
00053         stream = open(filename)
00054         content = stream.read()
00055         stream.close()
00056         fields = content.split("import iparameters")
00057         if len(fields) == 2:
00058             begin = fields[0]
00059             if begin.find("## NoteBook E.A.") >= 0:
00060                 begin = begin.split("## NoteBook E.A.")[0]
00061                 pass
00062             end = "import iparameters" + fields[1]
00063             content = begin
00064             content += "## NoteBook E.A.\n"
00065             for var, value in vars_and_values:
00066                 content += "notebook.set(%s,%s)\n"%(var.__repr__(), value)
00067                 pass
00068             content += end
00069             stream = open(filename, "w")
00070             stream.write(content)
00071             stream.close()
00072             #
00073             for fff, content in contents:
00074                 stream = open(fff, "w")
00075                 stream.write(content)
00076                 stream.close()
00077                 pass
00078             pass
00079         pass
00080     #
00081     return