Exemplo n.º 1
0
def import_exec_globals(config, session):
    '''
    get exec_globals directory
    cycle over its files
        if the file name not in importregistry
            send its contents to server
            put filename in importregistry
    '''
    for module in get_plugins(config):
        dirname = os.path.join(os.path.dirname(module.__file__),
                               'exec_globals')
        for fname in sorted(os.listdir(dirname)):
            if fname.endswith('.py'):
                name = 'execs:' + fname[:-3]
                try:
                    session.query(ImportRegistry).filter(ImportRegistry.name==name).one()
                except NoResultFound:
                    path = os.path.join(dirname, fname)
                    with open(path, 'r') as f:
                        eg = f.read()
                    kb = Client((config('kb_host'), int(config('kb_port'))))
                    kb.send_bytes('compiler:exec_globals:' + eg)
                    kb.send_bytes('FINISH-TERMS')
                    for fact in iter(kb.recv_bytes, 'END'):
                        print(fact)
                    kb.close()
                    ir = ImportRegistry(name)
                    session.add(ir)
Exemplo n.º 2
0
def import_ontologies(config, session):
    '''
    get directory
    cycle over trm files
        if the file name not in importregistry
            break file content on dots
            send pieces to server
            put filename in importregistry
    '''
    for module in get_plugins(config):
        fname = os.path.join(os.path.dirname(module.__file__), 'ontology', 'terms.trm')
        totell = []
        kb = Client((config('kb_host'), int(config('kb_port'))))
        with open(fname, 'r') as f:
            for line in f.readlines():
                if line:
                    kb.send_bytes(line)
        kb.send_bytes('FINISH-TERMS')
        for fact in iter(kb.recv_bytes, 'END'):
            print(fact)
        kb.close()