Exemplo n.º 1
0
    def exec_(self, keywords):
        """Execute the command.

        Arguments:
            keywords (dict): User's keywords.
        """
        iwarn = False
        stop_with = "EXCEPTION"
        if ExecutionParameter().option & Options.Abort:
            stop_with = "ABORT"
        if (ExecutionParameter().option & Options.TestMode
                or self._code_enabled(keywords)):
            ExecutionParameter().enable(Options.TestMode)
            stop_with = "ABORT"
            iwarn = True
            track_coverage(self._cata, self.command_name, keywords)

        erreur = keywords.get('ERREUR')
        if erreur:
            if erreur.get('ERREUR_F'):
                stop_with = erreur['ERREUR_F']
        if ExecutionParameter().option & Options.SlaveMode:
            stop_with = "EXCEPTION"
        # must be the first call to correctly set 'vini' in onerrf
        libaster.onFatalError(stop_with)

        debug = keywords.get('DEBUG')
        if debug:
            jxveri = debug.get('JXVERI', 'NON') == 'OUI'
            ExecutionParameter().set_option("jxveri", int(jxveri))
            if jxveri:
                UTMESS("I", "SUPERVIS_23")
            sdveri = debug.get('SDVERI', 'NON') == 'OUI'
            ExecutionParameter().set_option("sdveri", int(sdveri))
            if sdveri:
                UTMESS("I", "SUPERVIS_24")
            dbgjeveux = 'OUI' in (debug.get('JEVEUX', 'NON'),
                                  debug.get('VERI_BASE', 'NON'))
            ExecutionParameter().set_option("dbgjeveux", int(dbgjeveux))
            if dbgjeveux:
                UTMESS("I", "SUPERVIS_12")
            iwarn = iwarn or jxveri or sdveri or dbgjeveux
        if iwarn:
            UTMESS('I', 'SUPERVIS_22', valk=("--test", "code_aster.init()"))

        if keywords.get('IMPR_MACRO') == 'OUI':
            ExecutionParameter().enable(Options.ShowChildCmd)

        if keywords.get('LANG'):
            translation = localization.translation(keywords['LANG'])
            tr.set_translator(translation.gettext)

        if keywords.get('IGNORE_ALARM'):
            for idmess in keywords['IGNORE_ALARM']:
                MessageLog.disable_alarm(idmess)
        super(Starter, self).exec_(keywords)
Exemplo n.º 2
0
def calc_essai_ops(self,
                   UNITE_RESU=None,
                   EXPANSION=None,
                   IDENTIFICATION=None,
                   MODIFSTRUCT=None,
                   TRAITEMENTSIG=None,
                   GROUP_NO_CAPTEURS=None,
                   GROUP_NO_EXTERIEUR=None,
                   RESU_IDENTIFICATION=None,
                   RESU_MODIFSTRU=None,
                   **args):
    if MODIFSTRUCT:
        UTMESS('F', 'CALCESSAI0_2')

    caller = inspect.currentframe()
    # 1: exec_, 2: run_, 3: run, 4: user
    for _ in range(4):
        caller = caller.f_back
        context = caller.f_globals

    prev = onFatalError()

    # gestion des concepts sortants de la macro, declares a priori
    table_fonction = []
    if RESU_IDENTIFICATION:
        for res in RESU_IDENTIFICATION:
            table_fonction.append(res['TABLE'])
    out_identification = {
        "Register": self.register_result,
        "TypeTables": 'TABLE_FONCTION',
        "ComptTable": 0,
        "TablesOut": table_fonction
    }

    out_modifstru = RESU_MODIFSTRU or {}

    mess = MessageBox(UNITE_RESU)

    objects = CalcEssaiObjects(mess)
    objects.recup_objects(context)

    # importation des concepts aster existants de la memoire jeveux
    TestCalcEssai(self, mess, out_identification, out_modifstru, objects,
                  EXPANSION, IDENTIFICATION, MODIFSTRUCT, GROUP_NO_CAPTEURS,
                  GROUP_NO_EXTERIEUR)

    mess.close_file()
    onFatalError(prev)
Exemplo n.º 3
0
def macr_recal_ops(self,
                   UNITE_ESCL,
                   RESU_EXP=None,
                   LIST_POIDS=None,
                   LIST_PARA=None,
                   RESU_CALC=None,
                   ITER_MAXI=None,
                   ITER_FONC_MAXI=None,
                   RESI_GLOB_RELA=None,
                   UNITE_RESU=None,
                   PARA_DIFF_FINI=None,
                   GRAPHIQUE=None,
                   PARA_OPTI=None,
                   COURBE=None,
                   METHODE=None,
                   INFO=None,
                   **args):
    """ Macro commande realisant le recalage de modeles Aster """
    # Gestion des Exceptions
    prev_onFatalError = onFatalError()
    onFatalError('EXCEPTION')

    # Reecriture des mots-cles
    if COURBE:
        RESU_EXP = []
        RESU_CALC = []
        LIST_POIDS = []
        LIST_POIDS_DEFAUT = []
        LIST_POIDS_TMP = []
        for m in COURBE:
            lpar, lval = m['FONC_EXP'].Valeurs()
            LIST_EXP = []
            LIST_CALC_TMP = []
            for j in range(len(lpar)):
                LIST_EXP_TMP = []
                LIST_EXP_TMP.append(lpar[j])
                LIST_EXP_TMP.append(lval[j])
                LIST_EXP.append(LIST_EXP_TMP)
            RESU_EXP.append(NP.array(LIST_EXP))
            LIST_CALC_TMP.append(m['NOM_FONC_CALC'])
            LIST_CALC_TMP.append(m['PARA_X'])
            LIST_CALC_TMP.append(m['PARA_Y'])
            RESU_CALC.append(LIST_CALC_TMP)
            if m['POIDS'] is not None:
                LIST_POIDS_TMP.append(m['POIDS'])
            LIST_POIDS_DEFAUT.append(1.)
        if len(LIST_POIDS_TMP) == 0:
            LIST_POIDS = NP.array(LIST_POIDS_DEFAUT)
        else:
            LIST_POIDS = NP.array(LIST_POIDS_TMP)

    if PARA_OPTI:
        j = 0
        LIST_PARA = []
        for m in PARA_OPTI:
            LIST_TMP = []
            LIST_TMP.append(m['NOM_PARA'])
            LIST_TMP.append(m['VALE_INI'])
            LIST_TMP.append(m['VALE_MIN'])
            LIST_TMP.append(m['VALE_MAX'])
            LIST_PARA.append(LIST_TMP)

    nomres = macr_recal(self, UNITE_ESCL, force_list(RESU_EXP,
                                                     NP.ndarray), LIST_POIDS,
                        force_list(LIST_PARA), force_list(RESU_CALC),
                        ITER_MAXI, ITER_FONC_MAXI, RESI_GLOB_RELA, UNITE_RESU,
                        PARA_DIFF_FINI, GRAPHIQUE, METHODE, INFO, **args)

    onFatalError(prev_onFatalError)
    return nomres
Exemplo n.º 4
0
    def run_(self, **kwargs):
        """Run the command (worker).

        Arguments:
            keywords (dict): User keywords
        """
        self._tuplmode = kwargs.pop("__use_namedtuple__", self._tuplmode)
        keywords = mixedcopy(kwargs)
        self.keep_caller_infos(keywords)
        timer = ExecutionParameter().timer
        if self.command_name not in ("DEBUT", "POURSUITE", "FIN"):
            check_jeveux()

        ExecuteCommand.level += 1
        self._counter = ExecutionParameter().incr_command_counter()
        timer.Start(str(self._counter),
                    name=self.command_name,
                    hide=not self.show_syntax())
        timer.Start(" . check syntax", num=1.1e6)
        self.adapt_syntax(keywords)
        self._cata.addDefaultKeywords(keywords)
        remove_none(keywords)
        try:
            self.check_syntax(keywords)
        except (CheckerError, AssertionError, KeyError, TypeError,
                ValueError) as exc:
            # in case of syntax error, show the syntax and raise the exception
            self.print_syntax(keywords)
            ExecuteCommand.level -= 1
            msg = getattr(exc, "msg", str(exc))
            if ExecutionParameter().option & Options.Debug:
                logger.error(msg)
                raise
            UTMESS("F", "SUPERVIS_4", valk=(self.command_name, msg))
        finally:
            timer.Stop(" . check syntax")
        if ExecutionParameter().option & Options.TestMode:
            track_coverage(self._cata, self.command_name, keywords)
        self.create_result(keywords)
        if hasattr(self._result, "userName"):
            self._result.userName = get_user_name(self.command_name,
                                                  self._caller["filename"],
                                                  self._caller["lineno"])

        self.print_syntax(keywords)
        stop = False
        try:
            self.exec_(keywords)
        except libaster.AsterError as exc:
            self._exc = exc
            # try to push the result in the user context
            valid = "VALID" in libaster.onFatalError()
            if valid and hasattr(self._result, "userName"):
                publish_in(self._caller["context"],
                           {self._result.userName: self._result})
            stop = (isinstance(self._exc, libaster.TimeLimitError)
                    and not ExecutionParameter().option & Options.SlaveMode)
            if not stop:
                raise
        finally:
            self.post_exec_(keywords)
            ExecuteCommand.level -= 1
        # Interrupt execution in case of TimeLimitError
        if stop:
            # "<S>" in the message for diagnostic
            if isinstance(self._exc, libaster.TimeLimitError):
                UTMESS("I", "SUPERVIS_98")
            else:
                UTMESS("I", "SUPERVIS_95")
            saveObjects(level=3)
            raise SystemExit(1)
        return self._result
Exemplo n.º 5
0
 def onFatalError(self):
     """Récupérer le comportement en cas d'erreur fatale."""
     return libaster.onFatalError()