1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2015 EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
24 Interface de scripting pour une étude ADAO
26 __author__ = "Jean-Philippe ARGAUD"
30 from daCore import AssimilationStudy
32 # ==============================================================================
35 Creation TUI d'un cas ADAO
37 def __init__(self, name = ""):
38 self.__adaoStudy = AssimilationStudy.AssimilationStudy(name)
39 self.__dumper = _DumpLogger(name)
41 # -----------------------------------------------------------
47 DiagonalSparseMatrix = None,
52 ScalarSparseMatrix = None,
57 ThreeFunctions = None,
61 "Interface unique de définition de variables d'entrées par argument"
62 self.__dumper.register("set",dir(),locals(),None,True)
64 if Concept == "Background":
65 self.setBackground(Vector,VectorSerie,Script,Stored)
66 elif Concept == "BackgroundError":
67 self.setBackgroundError(Matrix,ScalarSparseMatrix,
68 DiagonalSparseMatrix,Script,Stored)
69 elif Concept == "CheckingPoint":
70 self.setCheckingPoint(Vector,VectorSerie,Script,Stored)
71 elif Concept == "ControlModel":
72 self.setControlModel(Matrix,OneFunction,ThreeFunctions,
73 Parameters,Script,Stored)
74 elif Concept == "ControlInput":
75 self.setControlInput(Vector,VectorSerie,Script,Stored)
76 elif Concept == "EvolutionError":
77 self.setEvolutionError(Matrix,ScalarSparseMatrix,
78 DiagonalSparseMatrix,Script,Stored)
79 elif Concept == "EvolutionModel":
80 self.setEvolutionModel(Matrix,OneFunction,ThreeFunctions,
81 Parameters,Script,Stored)
82 elif Concept == "Observation":
83 self.setObservation(Vector,VectorSerie,Script,Stored)
84 elif Concept == "ObservationError":
85 self.setObservationError(Matrix,ScalarSparseMatrix,
86 DiagonalSparseMatrix,Script,Stored)
87 elif Concept == "ObservationOperator":
88 self.setObservationOperator(Matrix,OneFunction,ThreeFunctions,
89 Parameters,Script,Stored)
90 elif Concept == "AlgorithmParameters":
91 self.setAlgorithmParameters(Algorithm,Parameters,Script)
92 elif Concept == "Debug":
94 elif Concept == "NoDebug":
96 elif Concept == "Observer":
97 self.setObserver(Variable,Template,String,Script,Info)
99 raise ValueError("the variable named '%s' is not allowed."%str(Concept))
100 except Exception as e:
101 if type(e) == type(SyntaxError()): msg = "at %s: %s"%(e.offset, e.text)
103 raise ValueError("during settings, the following error occurs:\n\n%s %s\n\nSee also the potential messages, which can show the origin of the above error, in the launching terminal."%(str(e),msg))
105 # -----------------------------------------------------------
113 "Définition d'une entrée de calcul"
114 self.__dumper.register("setBackground", dir(), locals())
115 if Script is not None:
116 __Vector, __PersistentVector = None, None
118 __PersistentVector = _ImportFromScript(Script).getvalue( "Background" )
120 __Vector = _ImportFromScript(Script).getvalue( "Background" )
122 __Vector, __PersistentVector = Vector, VectorSerie
124 self.__adaoStudy.setBackground(
126 asPersistentVector = __PersistentVector,
130 def setBackgroundError(
133 ScalarSparseMatrix = None,
134 DiagonalSparseMatrix = None,
137 "Définition d'une entrée de calcul"
138 self.__dumper.register("setBackgroundError", dir(), locals())
139 if Script is not None:
140 __Covariance, __Scalar, __Vector = None, None, None
141 if ScalarSparseMatrix:
142 __Scalar = _ImportFromScript(Script).getvalue( "BackgroundError" )
143 elif DiagonalSparseMatrix:
144 __Vector = _ImportFromScript(Script).getvalue( "BackgroundError" )
146 __Covariance = _ImportFromScript(Script).getvalue( "BackgroundError" )
148 __Covariance, __Scalar, __Vector = Matrix, ScalarSparseMatrix, DiagonalSparseMatrix
150 self.__adaoStudy.setBackgroundError(
151 asCovariance = __Covariance,
152 asEyeByScalar = __Scalar,
153 asEyeByVector = __Vector,
157 def setCheckingPoint(
163 "Définition d'une entrée de vérification"
164 self.__dumper.register("setCheckingPoint", dir(), locals())
165 if Script is not None:
166 __Vector, __PersistentVector = None, None
168 __PersistentVector = _ImportFromScript(Script).getvalue( "CheckingPoint" )
170 __Vector = _ImportFromScript(Script).getvalue( "CheckingPoint" )
172 __Vector, __PersistentVector = Vector, VectorSerie
174 self.__adaoStudy.setBackground(
176 asPersistentVector = __PersistentVector,
184 ThreeFunctions = None,
188 "Définition d'une entrée de calcul"
189 self.__dumper.register("setControlModel", dir(), locals())
191 if Parameters is not None and type(Parameters) == type({}):
192 if Parameters.has_key("DifferentialIncrement"):
193 __Parameters["withIncrement"] = Parameters["DifferentialIncrement"]
194 if Parameters.has_key("CenteredFiniteDifference"):
195 __Parameters["withCenteredDF"] = Parameters["CenteredFiniteDifference"]
196 if Script is not None:
197 __Matrix, __Function = None, None
199 __Matrix = _ImportFromScript(Script).getvalue( "ObservationOperator" )
201 __Function = { "Direct":_ImportFromScript(Script).getvalue( "DirectOperator" ) }
202 __Function.update({"useApproximatedDerivatives":True})
203 __Function.update(__Parameters)
206 "Direct" :_ImportFromScript(Script).getvalue( "DirectOperator" ),
207 "Tangent":_ImportFromScript(Script).getvalue( "TangentOperator" ),
208 "Adjoint":_ImportFromScript(Script).getvalue( "AdjointOperator" ),
210 __Function.update(__Parameters)
213 if OneFunction is not None:
214 __Function = { "Direct":OneFunction }
215 __Function.update({"useApproximatedDerivatives":True})
216 __Function.update(__Parameters)
217 elif ThreeFunctions is not None:
218 if (type(ThreeFunctions) is not type({})) or \
219 not ThreeFunctions.has_key("Direct") or \
220 not ThreeFunctions.has_key("Tangent") or \
221 not ThreeFunctions.has_key("Adjoint"):
222 raise ValueError("ThreeFunctions has to be a dictionnary and to have the 3 keys Direct, Tangent, Adjoint")
223 __Function = ThreeFunctions
224 __Function.update(__Parameters)
228 self.__adaoStudy.setControlModel(
229 asFunction = __Function,
240 "Définition d'une entrée de calcul"
241 self.__dumper.register("setControlInput", dir(), locals())
242 if Script is not None:
243 __Vector, __PersistentVector = None, None
245 __PersistentVector = _ImportFromScript(Script).getvalue( "ControlInput" )
247 __Vector = _ImportFromScript(Script).getvalue( "ControlInput" )
249 __Vector, __PersistentVector = Vector, VectorSerie
251 self.__adaoStudy.setControlInput(
253 asPersistentVector = __PersistentVector,
257 def setEvolutionError(
260 ScalarSparseMatrix = None,
261 DiagonalSparseMatrix = None,
264 "Définition d'une entrée de calcul"
265 self.__dumper.register("setEvolutionError", dir(), locals())
266 if Script is not None:
267 __Covariance, __Scalar, __Vector = None, None, None
268 if ScalarSparseMatrix:
269 __Scalar = _ImportFromScript(Script).getvalue( "EvolutionError" )
270 elif DiagonalSparseMatrix:
271 __Vector = _ImportFromScript(Script).getvalue( "EvolutionError" )
273 __Covariance = _ImportFromScript(Script).getvalue( "EvolutionError" )
275 __Covariance, __Scalar, __Vector = Matrix, ScalarSparseMatrix, DiagonalSparseMatrix
277 self.__adaoStudy.setEvolutionError(
278 asCovariance = __Covariance,
279 asEyeByScalar = __Scalar,
280 asEyeByVector = __Vector,
284 def setEvolutionModel(
288 ThreeFunctions = None,
292 "Définition d'une entrée de calcul"
293 self.__dumper.register("setEvolutionModel", dir(), locals())
295 if Parameters is not None and type(Parameters) == type({}):
296 if Parameters.has_key("DifferentialIncrement"):
297 __Parameters["withIncrement"] = Parameters["DifferentialIncrement"]
298 if Parameters.has_key("CenteredFiniteDifference"):
299 __Parameters["withCenteredDF"] = Parameters["CenteredFiniteDifference"]
300 if Parameters.has_key("EnableMultiProcessing"):
301 __Parameters["withmpEnabled"] = Parameters["EnableMultiProcessing"]
302 if Parameters.has_key("NumberOfProcesses"):
303 __Parameters["withmpWorkers"] = Parameters["NumberOfProcesses"]
304 if Script is not None:
305 __Matrix, __Function = None, None
307 __Matrix = _ImportFromScript(Script).getvalue( "ObservationOperator" )
309 __Function = { "Direct":_ImportFromScript(Script).getvalue( "DirectOperator" ) }
310 __Function.update({"useApproximatedDerivatives":True})
311 __Function.update(__Parameters)
314 "Direct" :_ImportFromScript(Script).getvalue( "DirectOperator" ),
315 "Tangent":_ImportFromScript(Script).getvalue( "TangentOperator" ),
316 "Adjoint":_ImportFromScript(Script).getvalue( "AdjointOperator" ),
318 __Function.update(__Parameters)
321 if OneFunction is not None:
322 __Function = { "Direct":OneFunction }
323 __Function.update({"useApproximatedDerivatives":True})
324 __Function.update(__Parameters)
325 elif ThreeFunctions is not None:
326 if (type(ThreeFunctions) is not type({})) or \
327 not ThreeFunctions.has_key("Direct") or \
328 not ThreeFunctions.has_key("Tangent") or \
329 not ThreeFunctions.has_key("Adjoint"):
330 raise ValueError("ThreeFunctions has to be a dictionnary and to have the 3 keys Direct, Tangent, Adjoint")
331 __Function = ThreeFunctions
332 __Function.update(__Parameters)
336 self.__adaoStudy.setEvolutionModel(
337 asFunction = __Function,
348 "Définition d'une entrée de calcul"
349 self.__dumper.register("setObservation", dir(), locals())
350 if Script is not None:
351 __Vector, __PersistentVector = None, None
353 __PersistentVector = _ImportFromScript(Script).getvalue( "Observation" )
355 __Vector = _ImportFromScript(Script).getvalue( "Observation" )
357 __Vector, __PersistentVector = Vector, VectorSerie
359 self.__adaoStudy.setObservation(
361 asPersistentVector = __PersistentVector,
365 def setObservationError(
368 ScalarSparseMatrix = None,
369 DiagonalSparseMatrix = None,
372 "Définition d'une entrée de calcul"
373 self.__dumper.register("setObservationError", dir(), locals())
374 if Script is not None:
375 __Covariance, __Scalar, __Vector = None, None, None
376 if ScalarSparseMatrix:
377 __Scalar = _ImportFromScript(Script).getvalue( "ObservationError" )
378 elif DiagonalSparseMatrix:
379 __Vector = _ImportFromScript(Script).getvalue( "ObservationError" )
381 __Covariance = _ImportFromScript(Script).getvalue( "ObservationError" )
383 __Covariance, __Scalar, __Vector = Matrix, ScalarSparseMatrix, DiagonalSparseMatrix
385 self.__adaoStudy.setObservationError(
386 asCovariance = __Covariance,
387 asEyeByScalar = __Scalar,
388 asEyeByVector = __Vector,
392 def setObservationOperator(
396 ThreeFunctions = None,
400 "Définition d'une entrée de calcul"
401 self.__dumper.register("setObservationOperator", dir(), locals())
403 if Parameters is not None and type(Parameters) == type({}):
404 if Parameters.has_key("DifferentialIncrement"):
405 __Parameters["withIncrement"] = Parameters["DifferentialIncrement"]
406 if Parameters.has_key("CenteredFiniteDifference"):
407 __Parameters["withCenteredDF"] = Parameters["CenteredFiniteDifference"]
408 if Parameters.has_key("EnableMultiProcessing"):
409 __Parameters["EnableMultiProcessing"] = Parameters["EnableMultiProcessing"]
410 __Parameters["withmpEnabled"] = Parameters["EnableMultiProcessing"]
411 if Parameters.has_key("NumberOfProcesses"):
412 __Parameters["NumberOfProcesses"] = Parameters["NumberOfProcesses"]
413 __Parameters["withmpWorkers"] = Parameters["NumberOfProcesses"]
414 if Script is not None:
415 __Matrix, __Function = None, None
417 __Matrix = _ImportFromScript(Script).getvalue( "ObservationOperator" )
419 __Function = { "Direct":_ImportFromScript(Script).getvalue( "DirectOperator" ) }
420 __Function.update({"useApproximatedDerivatives":True})
421 __Function.update(__Parameters)
424 "Direct" :_ImportFromScript(Script).getvalue( "DirectOperator" ),
425 "Tangent":_ImportFromScript(Script).getvalue( "TangentOperator" ),
426 "Adjoint":_ImportFromScript(Script).getvalue( "AdjointOperator" ),
428 __Function.update(__Parameters)
431 if OneFunction is not None:
432 __Function = { "Direct":OneFunction }
433 __Function.update({"useApproximatedDerivatives":True})
434 __Function.update(__Parameters)
435 elif ThreeFunctions is not None:
436 if (type(ThreeFunctions) is not type({})) or \
437 not ThreeFunctions.has_key("Direct") or \
438 not ThreeFunctions.has_key("Tangent") or \
439 not ThreeFunctions.has_key("Adjoint"):
440 raise ValueError("ThreeFunctions has to be a dictionnary and to have the 3 keys Direct, Tangent, Adjoint")
441 __Function = ThreeFunctions
442 __Function.update(__Parameters)
446 self.__adaoStudy.setObservationOperator(
447 asFunction = __Function,
452 # -----------------------------------------------------------
454 def setAlgorithmParameters(
459 "Définition d'un paramétrage du calcul"
460 self.__dumper.register("setAlgorithmParameters", dir(), locals())
461 if Script is not None:
462 __Algorithm = _ImportFromScript(Script).getvalue( "Algorithm" )
463 __Parameters = _ImportFromScript(Script).getvalue( "AlgorithmParameters", "Parameters" )
465 __Algorithm = Algorithm
466 __Parameters = Parameters
467 self.__adaoStudy.setAlgorithm( choice = __Algorithm )
468 self.__adaoStudy.setAlgorithmParameters( asDico = __Parameters )
471 "Définition d'un paramétrage du calcul"
472 self.__dumper.register("setDebug",dir(),locals())
473 return self.__adaoStudy.setDebug()
475 def setNoDebug(self):
476 "Définition d'un paramétrage du calcul"
477 self.__dumper.register("setNoDebug",dir(),locals())
478 return self.__adaoStudy.unsetDebug()
487 "Définition d'un paramétrage du calcul"
488 self.__dumper.register("setObserver", dir(), locals())
490 raise ValueError("setting an observer has to be done over a variable name, not over None.")
492 __Variable = str(Variable)
494 __Info = str(Variable)
498 if String is not None:
499 __FunctionText = String
500 elif Template is not None:
501 if Template == "ValuePrinter":
502 __FunctionText = """print info, var[-1]"""
503 if Template == "ValueSeriePrinter":
504 __FunctionText = """print info, var[:]"""
505 if Template == "ValueSaver":
506 __FunctionText = """import numpy, re\nv=numpy.array(var[-1], ndmin=1)\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint 'Value saved in \"%s\"'%f\nnumpy.savetxt(f,v)"""
507 if Template == "ValueSerieSaver":
508 __FunctionText = """import numpy, re\nv=numpy.array(var[:], ndmin=1)\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint 'Value saved in \"%s\"'%f\nnumpy.savetxt(f,v)"""
509 if Template == "ValuePrinterAndSaver":
510 __FunctionText = """import numpy, re\nv=numpy.array(var[-1], ndmin=1)\nprint info,v\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint 'Value saved in \"%s\"'%f\nnumpy.savetxt(f,v)"""
511 if Template == "ValueSeriePrinterAndSaver":
512 __FunctionText = """import numpy, re\nv=numpy.array(var[:], ndmin=1)\nprint info,v\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint 'Value saved in \"%s\"'%f\nnumpy.savetxt(f,v)"""
513 if Template == "ValueGnuPlotter":
514 __FunctionText = """import numpy, Gnuplot\nv=numpy.array(var[-1], ndmin=1)\nglobal ifig, gp\ntry:\n ifig += 1\n gp('set style data lines')\nexcept:\n ifig = 0\n gp = Gnuplot.Gnuplot(persist=1)\n gp('set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )"""
515 if Template == "ValueSerieGnuPlotter":
516 __FunctionText = """import numpy, Gnuplot\nv=numpy.array(var[:], ndmin=1)\nglobal ifig, gp\ntry:\n ifig += 1\n gp('set style data lines')\nexcept:\n ifig = 0\n gp = Gnuplot.Gnuplot(persist=1)\n gp('set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )"""
517 if Template == "ValuePrinterAndGnuPlotter":
518 __FunctionText = """print info, var[-1]\nimport numpy, Gnuplot\nv=numpy.array(var[-1], ndmin=1)\nglobal ifig,gp\ntry:\n ifig += 1\n gp('set style data lines')\nexcept:\n ifig = 0\n gp = Gnuplot.Gnuplot(persist=1)\n gp('set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )"""
519 if Template == "ValueSeriePrinterAndGnuPlotter":
520 __FunctionText = """print info, var[:] \nimport numpy, Gnuplot\nv=numpy.array(var[:], ndmin=1)\nglobal ifig,gp\ntry:\n ifig += 1\n gp('set style data lines')\nexcept:\n ifig = 0\n gp = Gnuplot.Gnuplot(persist=1)\n gp('set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )"""
521 if Template == "ValuePrinterSaverAndGnuPlotter":
522 __FunctionText = """print info, var[-1]\nimport numpy, re\nv=numpy.array(var[-1], ndmin=1)\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint 'Value saved in \"%s\"'%f\nnumpy.savetxt(f,v)\nimport Gnuplot\nglobal ifig,gp\ntry:\n ifig += 1\n gp('set style data lines')\nexcept:\n ifig = 0\n gp = Gnuplot.Gnuplot(persist=1)\n gp('set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )"""
523 if Template == "ValueSeriePrinterSaverAndGnuPlotter":
524 __FunctionText = """print info, var[:] \nimport numpy, re\nv=numpy.array(var[:], ndmin=1)\nglobal istep\ntry:\n istep += 1\nexcept:\n istep = 0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub('\\s','_',f)\nprint 'Value saved in \"%s\"'%f\nnumpy.savetxt(f,v)\nimport Gnuplot\nglobal ifig,gp\ntry:\n ifig += 1\n gp('set style data lines')\nexcept:\n ifig = 0\n gp = Gnuplot.Gnuplot(persist=1)\n gp('set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )"""
525 if Template == "ValueMean":
526 __FunctionText = """import numpy\nprint info, numpy.nanmean(var[-1])"""
527 if Template == "ValueStandardError":
528 __FunctionText = """import numpy\nprint info, numpy.nanstd(var[-1])"""
529 if Template == "ValueVariance":
530 __FunctionText = """import numpy\nprint info, numpy.nanvar(var[-1])"""
531 if Template == "ValueRMS":
532 __FunctionText = """import numpy\nv = numpy.matrix( numpy.ravel( var[-1] ) )\nprint info, float( numpy.sqrt((1./v.size)*(v*v.T)) )"""
533 elif Script is not None:
534 __FunctionText = _ImportFromScript(Script).getstring()
537 __Function = _ObserverF(__FunctionText)
539 self.__adaoStudy.setDataObserver(
540 VariableName = __Variable,
541 HookFunction = __Function.getfunc(),
542 HookParameters = __Info,
545 # -----------------------------------------------------------
547 def executePythonScheme(self):
548 "Lancement du calcul"
549 self.__dumper.register("executePythonScheme", dir(), locals())
551 self.__adaoStudy.analyze()
552 except Exception as e:
553 if type(e) == type(SyntaxError()): msg = "at %s: %s"%(e.offset, e.text)
555 raise ValueError("during execution, the following error occurs:\n\n%s %s\n\nSee also the potential messages, which can show the origin of the above error, in the launching terminal."%(str(e),msg))
557 execute = executePythonScheme
559 def executeYACSScheme(self, File=None):
560 "Lancement du calcul"
561 self.__dumper.register("executeYACSScheme", dir(), locals())
562 raise NotImplementedError()
564 # -----------------------------------------------------------
566 def get(self, Concept=None):
567 "Récupération d'une sortie du calcul"
568 self.__dumper.register("get",dir(),locals(),Concept)
569 return self.__adaoStudy.get(Concept)
571 def dumpNormalizedCommands(self, filename=None):
572 "Récupération de la liste des commandes du cas"
573 return self.__dumper.dump(filename)
576 return ['set', 'get', 'execute', '__doc__', '__init__', '__module__']
578 class _DumpLogger(object):
580 Conservation des commandes de création d'un cas
582 def __init__(self, __name="", __objname="case"):
583 self.__name = str(__name)
584 self.__objname = str(__objname)
586 self.__switchoff = False
587 self.__logSerie.append("#\n# Python script for ADAO TUI\n#")
588 self.__logSerie.append("from numpy import array, matrix")
589 self.__logSerie.append("import adaoBuilder")
590 self.__logSerie.append("%s = adaoBuilder.New('%s')"%(self.__objname, self.__name))
591 def register(self, __command=None, __keys=None, __local=None, __pre=None, __switchoff=False):
592 "Enregistrement d'une commande individuelle"
593 if __command is not None and __keys is not None and __local is not None and not self.__switchoff:
595 if __pre is not None:
596 __text += "%s = "%__pre
597 __text += "%s.%s( "%(self.__objname,str(__command))
598 __keys.remove("self")
601 if __v is None: continue
602 __text += "%s=%s, "%(k,repr(__v))
604 self.__logSerie.append(__text)
606 self.__switchoff = True
608 self.__switchoff = False
609 def dump(self, __filename=None):
610 "Restitution de la liste des commandes de création d'un cas"
611 __text = "\n".join(self.__logSerie)
612 if __filename is not None:
613 fid = open(__filename,"w")
618 class _ObserverF(object):
620 Création d'une fonction d'observateur à partir de son texte
622 def __init__(self, corps=""):
624 def func(self,var,info):
625 "Fonction d'observation"
628 "Restitution du pointeur de fonction dans l'objet"
631 class _ImportFromScript(object):
633 Obtention d'une variable nommée depuis un fichier script importé
635 def __init__(self, __filename=None):
636 "Verifie l'existence et importe le script"
637 __filename = __filename.rstrip(".py")
638 if __filename is None:
639 raise ValueError("The name of the file containing the variable to be imported has to be specified.")
640 if not os.path.isfile(str(__filename)+".py"):
641 raise ValueError("The file containing the variable to be imported doesn't seem to exist. The given file name is:\n \"%s\""%__filename)
642 self.__scriptfile = __import__(__filename, globals(), locals(), [])
643 self.__scriptstring = open(__filename+".py",'r').read()
644 def getvalue(self, __varname=None, __synonym=None ):
645 "Renvoie la variable demandee"
646 if __varname is None:
647 raise ValueError("The name of the variable to be imported has to be specified.")
648 if not hasattr(self.__scriptfile, __varname):
649 if __synonym is None:
650 raise ValueError("The imported script file doesn't contain the specified variable \"%s\"."%__varname)
651 elif not hasattr(self.__scriptfile, __synonym):
652 raise ValueError("The imported script file doesn't contain the specified variable \"%s\"."%__synonym)
654 return getattr(self.__scriptfile, __synonym)
656 return getattr(self.__scriptfile, __varname)
658 "Renvoie le script complet"
659 return self.__scriptstring
661 # ==============================================================================
662 if __name__ == "__main__":
663 print '\n AUTODIAGNOSTIC \n'