- def __init__(self, __name="", __objname="case", __content=None):
- "Initialisation et enregistrement de l'entete"
- self._name = str(__name)
- self._objname = str(__objname)
- self._lineSerie = []
- self._switchoff = False
- self._numobservers = 2
- self._content = __content
- def _addLine(self, line=""):
- "Ajoute un enregistrement individuel"
- self._lineSerie.append(line)
- def _finalize(self):
- "Enregistrement du final"
- pass
- def _append(self):
- "Transformation de commande individuelle en enregistrement"
- raise NotImplementedError()
- def _extract(self):
- "Transformation d'enregistrement en commande individuelle"
- raise NotImplementedError()
- def _interpret(self):
- "Interprétation d'une commande"
- raise NotImplementedError()
- def dump(self, __filename=None):
- "Restitution normalisée des commandes"
- self._finalize()
- __text = "\n".join(self._lineSerie)
- __text +="\n"
- if __filename is not None:
- __file = os.path.abspath(__filename)
- fid = open(__file,"w")
- fid.write(__text)
- fid.close()
- return __text
- def load(self, __filename=None):
- "Chargement normalisé des commandes"
- if os.path.exists(__filename):
- self._content = open(__filename, 'r').read()
- __commands = self._extract(self._content)
- return __commands
- def execCase(self, __filename=None):
- "Exécution normalisée des commandes"
- if os.path.exists(__filename):
- self._content = open(__filename, 'r').read()
- __retcode = self._interpret(self._content)
- return __retcode
-
-class _TUIViewer(GenericCaseViewer):
- """
- Etablissement des commandes de creation d'un cas TUI
- """
- def __init__(self, __name="", __objname="case", __content=None):
- "Initialisation et enregistrement de l'entete"
- GenericCaseViewer.__init__(self, __name, __objname, __content)
- self._addLine("#\n# Python script for ADAO TUI\n#")
- self._addLine("from numpy import array, matrix")
- self._addLine("import adaoBuilder")
- self._addLine("%s = adaoBuilder.New('%s')"%(self._objname, self._name))
- if self._content is not None:
- for command in self._content:
- self._append(*command)
- def _append(self, __command=None, __keys=None, __local=None, __pre=None, __switchoff=False):
- "Transformation d'une commande individuelle en un enregistrement"
- if __command is not None and __keys is not None and __local is not None:
- __text = ""
- if __pre is not None:
- __text += "%s = "%__pre
- __text += "%s.%s( "%(self._objname,str(__command))
- if "self" in __keys: __keys.remove("self")
- if __command not in ("set","get") and "Concept" in __keys: __keys.remove("Concept")
- for k in __keys:
- __v = __local[k]
- if __v is None: continue
- if k == "Checked" and not __v: continue
- if k == "Stored" and not __v: continue
- if k == "AvoidRC" and __v: continue
- if k == "noDetails": continue
- numpy.set_printoptions(precision=15,threshold=1000000,linewidth=1000*15)
- __text += "%s=%s, "%(k,repr(__v))
- numpy.set_printoptions(precision=8,threshold=1000,linewidth=75)
- __text.rstrip(", ")
- __text += ")"
- self._addLine(__text)
- def _extract(self, __content=""):
- "Transformation un enregistrement en d'une commande individuelle"
- __is_case = False
- __commands = []
- __content = __content.replace("\r\n","\n")
- for line in __content.split("\n"):
- if "adaoBuilder" in line and "=" in line:
- self._objname = line.split("=")[0].strip()
- __is_case = True
- if not __is_case:
- continue
- else:
- if self._objname+".set" in line:
- __commands.append( line.replace(self._objname+".","",1) )
- return __commands
- def _interpret(self, __content=""):
- "Interprétation d'une commande"
- __content = __content.replace("\r\n","\n")
- exec(__content)
- return 0
-
-# ==============================================================================
-class ImportFromScript(object):
- """
- Obtention d'une variable nommee depuis un fichier script importe
- """
- def __init__(self, __filename=None):
- "Verifie l'existence et importe le script"
- self.__filename = __filename.rstrip(".py")
- if self.__filename is None:
- raise ValueError("The name of the file containing the variable to be imported has to be specified.")
- if not os.path.isfile(str(self.__filename)+".py"):
- raise ValueError("The file containing the variable to be imported doesn't seem to exist. The given file name is:\n \"%s\""%self.__filename)
- self.__scriptfile = __import__(self.__filename, globals(), locals(), [])
- self.__scriptstring = open(self.__filename+".py",'r').read()
- def getvalue(self, __varname=None, __synonym=None ):
- "Renvoie la variable demandee"
- if __varname is None:
- raise ValueError("The name of the variable to be imported has to be specified.")
- if not hasattr(self.__scriptfile, __varname):
- if __synonym is None:
- raise ValueError("The imported script file \"%s\" doesn't contain the specified variable \"%s\"."%(str(self.__filename)+".py",__varname))
- elif not hasattr(self.__scriptfile, __synonym):
- raise ValueError("The imported script file \"%s\" doesn't contain the specified variable \"%s\"."%(str(self.__filename)+".py",__synonym))
- else:
- return getattr(self.__scriptfile, __synonym)