1 # Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 def addvars2notebook(filename):
28 directory = os.path.dirname(filename)
29 base = os.path.basename(filename)
30 prefix = base[:-3] # remove ".py"
32 from os import listdir
33 l = listdir(directory)
35 if f.find(prefix) != 0: continue
36 if f[-3:] != ".py": continue
37 module = f[len(prefix):-3]
39 mod = __import__("addvars2notebook_%s"%(module))
43 func = mod.addvars2notebook
44 except AttributeError:
46 fff = os.path.join(directory, f)
47 content = func(fff, vars_and_values)
48 contents.append([fff, content])
52 stream = open(filename)
53 content = stream.read()
55 fields = content.split("import iparameters")
58 if begin.find("## NoteBook E.A.") >= 0:
59 begin = begin.split("## NoteBook E.A.")[0]
61 end = "import iparameters" + fields[1]
63 content += "## NoteBook E.A.\n"
64 for var, value in vars_and_values:
65 content += "notebook.set(%s,%s)\n"%(var.__repr__(), value)
68 stream = open(filename, "w")
72 for fff, content in contents:
73 stream = open(fff, "w")
82 if __name__ == "__main__":
84 addvars2notebook(sys.argv[1])