diff --git a/lib/aslint/check_inst.py b/lib/aslint/check_inst.py index 352a98e3f0d77e806a0b11a492be106a49bc34c5..4fec3573ca10bb8973ae9b1c7738963b9e94aeb4 100644 --- a/lib/aslint/check_inst.py +++ b/lib/aslint/check_inst.py @@ -15,13 +15,14 @@ from aslint.i18n import _ def check_install(c4che, dry_run=False): """Check installation""" - asterxx = bool(c4che.get('INCLUDES_BIBCXX') or c4che.get('INCLUDES_BOOST')) + legacy = not (bool(c4che.get('INCLUDES_BIBCXX') or + c4che.get('INCLUDES_BOOST'))) try: libdir = c4che['ASTERLIBDIR'] - if asterxx: - binary = osp.join(libdir, "libaster.so") - else: + if legacy: binary = osp.join(c4che['BINDIR'], c4che['ASTERBINOPT']) + else: + binary = osp.join(libdir, "libaster.so") python = c4che['PYTHON'][0] prefix = c4che['PREFIX'] datadir = c4che['ASTERDATADIR'] @@ -46,14 +47,21 @@ def check_install(c4che, dry_run=False): cata = [osp.join(libdir, path) for path in (osp.join('code_aster', 'Cata'), 'Cata')] lcata = [len(glob(path)) for path in cata] - if sum(lcata) < 1: - # currently Cata still exists even if code_aster/Cata exists (i18n files) - msg = _('at least one of {0} is expected').format(tuple(cata)) + if legacy: + # currently Cata still exists in legacy even if code_aster/Cata exists (i18n files) + nbdir = 2 + else: + nbdir = 1 + if sum(lcata) != nbdir: + msg = _('expecting: {0}').format(tuple(cata)) if not dry_run: logger.error(msg) else: logger.info(msg) - errcode.add(check_import_cata(python, libdir, dry_run=dry_run)) + errcode.add(check_import_cata(python, libdir, + env=osp.join(datadir, 'profile.sh'), + legacy=legacy, + dry_run=dry_run)) if errcode.is_error(): if not dry_run: logger.error(_("invalid installation")) @@ -64,7 +72,7 @@ def check_install(c4che, dry_run=False): return errcode -def check_import_cata(python, libdir, dry_run=False): +def check_import_cata(python, libdir, env=None, legacy=False, dry_run=False): """Check the cata.py can be imported with only the minimal number of required packages""" errcode = ErrorCode() @@ -72,34 +80,46 @@ def check_import_cata(python, libdir, dry_run=False): def _exec(cmd): """Execute an external command""" if not dry_run: - proc = Popen(cmd, stdout=PIPE, stderr=STDOUT) - errcode.from_status(proc.wait()) + cmd_env = ". {env} ; {cmd}".format(cmd=" ".join([repr(i) for i in cmd]), env=env) + proc = Popen(cmd_env, stdout=PIPE, stderr=STDOUT, + shell=True, universal_newlines=True) + out = proc.communicate()[0] + retcode = proc.returncode + if retcode != 0: + logger.warn("command:" + cmd_env) + logger.warn(out) + errcode.from_status(retcode) else: logger.info(_("(DRY RUN) %s"), cmd) dtmp = tempfile.mkdtemp() - if osp.exists(osp.join(libdir, 'code_aster', 'Cata')): - supv = (osp.join('code_aster', 'Cata'), ) - else: - supv = ('Accas', 'Build', 'Cata', 'Execution', 'Noyau', 'Validation') prev = os.getcwd() os.chdir(dtmp) try: - if not dry_run: - for pkg in supv: - shutil.copytree(osp.join(libdir, pkg), pkg) - with open('aster.py', 'w') as fobj: + if legacy and not dry_run: + # only needed for legacy versions + with open("aster.py", "w") as fobj: fobj.write(os.linesep.join([ "class error(Exception):", " pass", "class FatalError(Exception):", " pass", "def affiche(unit, txt):", - " print txt", + " print(txt)", "def onFatalError():", " return 'ABORT'", ])) - _exec([python, '-c', "'import Cata'"]) - _exec([python, '-c', "'from Cata import cata'"]) + with open("_aster_core.py", "w") as fobj: + symbols = ("matfpe", "get_mem_stat", "set_mem_stat", + "MPI_CommRankSize", "MPI_Warn", "MPI_Barrier", + "MPI_Bcast", "MPI_GatherStr", "_USE_MPI", + "_USE_OPENMP", "_USE_64_BITS", "_POSIX", "_NO_EXPIR", + "ASTER_INT_SIZE") + lines = [symb + " = 1" for symb in symbols] + fobj.write(os.linesep.join(lines)) + + _exec([python, '-c', "import code_aster.Cata"]) + _exec([python, '-c', "from code_aster.Cata import Language"]) + _exec([python, '-c', "from code_aster.Cata import Commands"]) finally: os.chdir(prev) shutil.rmtree(dtmp)