Exemple #1
0
def modhelp(mod, context):
    try:
        result = serialize_x(_get_ext_module_fname(mod),
                             'LMExt',
                             helpinfo=context)
    except Exception as e:
        raise FunctionFailed(e)
    if result is None:
        raise ResourceNotFound('Help context')
    return result
Exemple #2
0
def list_mods():
    result = []
    mods = glob.glob(_get_ext_module_fname('*', get_system=False))
    for p in mods:
        f = os.path.basename(p)[:-3]
        if f not in ('__init__', 'generic'):
            try:
                d = serialize_x(p, 'LMExt', full=True)
                result.append(d)
            except:
                eva.core.log_traceback()
    for p in glob.glob(f'{eva.core.dir_lib}/eva/lm/extensions/*.py'):
        f = os.path.basename(p)[:-3]
        if f not in ('__init__', 'generic'):
            try:
                d = serialize_x(p, 'LMExt', full=True)
                result.append(d)
            except:
                eva.core.log_traceback()
    return sorted(result, key=lambda k: k['mod'])
Exemple #3
0
def modinfo(mod):
    try:
        result = serialize_x(_get_ext_module_fname(mod), 'LMExt', full=True)
        if result:
            try:
                del result['id']
            except:
                pass
        return result
    except Exception as e:
        raise FunctionFailed(e)
Exemple #4
0
def list_lpi_mods():
    result = []
    lpi_mods = glob.glob(_get_lpi_module_fname('*', get_system=False))
    for p in lpi_mods:
        f = os.path.basename(p)[:-3]
        if f != '__init__':
            try:
                d = serialize_x(p, 'LPI', full=True)
                if d['logic'] != 'abstract':
                    result.append(d)
            except:
                eva.core.log_traceback()
    for p in glob.glob(f'{eva.core.dir_lib}/eva/uc/drivers/lpi/*.py'):
        f = os.path.basename(p)[:-3]
        if f != '__init__':
            try:
                d = serialize_x(p, 'LPI', full=True)
                if d['logic'] != 'abstract':
                    result.append(d)
            except:
                eva.core.log_traceback()
    return sorted(result, key=lambda k: k['mod'])
Exemple #5
0
def modinfo_lpi(mod):
    try:
        result = serialize_x(_get_lpi_module_fname(mod), 'LPI', full=True)
        if result:
            try:
                del result['id']
                del result['lpi_id']
                del result['phi_id']
            except:
                pass
        return result
    except Exception as e:
        raise FunctionFailed(e)
Exemple #6
0
def put_phi_mod(mod, content, force=False):
    if mod.find('/') != -1:
        raise InvalidParameter('Invalid module file name')
    if mod == 'generic_phi':
        raise ResourceAlreadyExists('generic PHI can not be overriden')
    fname = _get_phi_module_fname(mod)
    if os.path.isfile(fname) and not force:
        raise ResourceAlreadyExists('PHI module {}'.format(fname))
    valid = False
    try:
        # verify code compilation
        compile(content, fname, 'exec')
        # save module code
        try:
            eva.core.prepare_save()
            with open(fname, 'w') as fd:
                fd.write(content)
            eva.core.finish_save()
        except Exception as e:
            raise FunctionFailed('Unable to put PHI module {}: {}'.format(
                fname, e))
        # verify saved module
        if 'mod' not in serialize_x(fname, 'PHI', full=True):
            raise FunctionFailed('Unable to verify module')
        valid = True
        return True
    except FunctionFailed:
        raise
    except:
        raise FunctionFailed(
            'Unable to check PHI module {}, invalid module code'.format(mod))
    finally:
        if not valid:
            try:
                eva.core.prepare_save()
                os.unlink(fname)
                eva.core.finish_save()
            except:
                logging.warning(
                    'Unable to delete invalid module {}'.format(fname))
                eva.core.log_traceback()