Back to index

salome-geom  6.5.0
addvars2notebook_GEOM.py
Go to the documentation of this file.
00001 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 #
00003 # This library is free software; you can redistribute it and/or
00004 # modify it under the terms of the GNU Lesser General Public
00005 # License as published by the Free Software Foundation; either
00006 # version 2.1 of the License.
00007 #
00008 # This library is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 # Lesser General Public License for more details.
00012 #
00013 # You should have received a copy of the GNU Lesser General Public
00014 # License along with this library; if not, write to the Free Software
00015 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 #
00017 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 #
00019 
00020 def addvars2notebook(filename, vars_and_values):
00021     stream = open(filename)
00022     lines = stream.readlines()
00023     stream.close()
00024     newlines = []
00025     for line in lines:
00026         if line.find("= geompy.") >= 0:
00027             name = line.split('=')[0]
00028             name = name.strip()
00029             vals = line
00030             fields = vals.split("(")
00031             if len(fields) == 2:
00032                 begin = fields[0] + "("
00033                 vals = fields[1]
00034                 fields = vals.split(")")
00035                 if len(fields) == 2:
00036                     vals = fields[0]
00037                     end = ")" + fields[1]
00038                     vals = vals.split(',')
00039                     newline  = begin
00040                     newvals = []
00041                     for i in range(len(vals)):
00042                         valname = name + "_val_%s"%(i+1)
00043                         val = vals[i]
00044                         vvv = val.strip()
00045                         try:
00046                             iii = int(vvv)
00047                             vars_and_values.append([valname, val])
00048                             val = val.replace(vvv, valname.__repr__())
00049                         except ValueError:
00050                             try:
00051                                 fff = float(vvv)
00052                                 vars_and_values.append([valname, val])
00053                                 val = val.replace(vvv, valname.__repr__())
00054                             except ValueError:
00055                                 pass
00056                             pass
00057                         newvals.append(val)
00058                         pass
00059                     newline += ','.join(newvals)
00060                     newline += end
00061                     line = newline
00062                     pass
00063                 pass
00064             pass
00065         newlines.append(line)
00066         pass
00067     content = "".join(newlines)
00068     return content