Beispiel #1
0
def create_instance(conf, user_items, auth):
    backend = Backend(MySQLConf(conf))
    return UcnkCorpArch2(backend=backend,
                         auth=auth,
                         user_items=user_items,
                         tag_prefix=conf.get('plugins', 'corparch')['ucnk:tag_prefix'],
                         max_num_hints=conf.get('plugins', 'corparch')['ucnk:max_num_hints'],
                         max_page_size=conf.get('plugins', 'corparch').get(
                             'ucnk:default_page_list_size', None),
                         access_req_smtp_server=conf.get('plugins',
                                                         'corparch')['ucnk:access_req_smtp_server'],
                         access_req_sender=conf.get('plugins', 'corparch')[
                             'ucnk:access_req_sender'],
                         access_req_recipients=conf.get('plugins',
                                                        'corparch')['ucnk:access_req_recipients'],
                         default_label=conf.get('plugins', 'corparch')['ucnk:default_label'],
                         registry_lang=conf.get('corpora', 'manatee_registry_locale', 'en_US'))
Beispiel #2
0
def find_db_reg_paths(conf):
    return MySQLConf(conf)
Beispiel #3
0
        '-l',
        '--auto-align',
        metavar='AUTO_ALIGN',
        action='store_const',
        const=True,
        help='Align all the corpus in a directory automatically')
    parser.add_argument(
        '-v',
        '--verbose',
        action='store_const',
        const=True,
        help='Provide more information during processing (especially errors)')
    args = parser.parse_args()
    import settings
    settings.load(args.conf_path)
    backend = WritableBackend(MySQLConf(settings))

    if os.path.isdir(args.rpath):
        process_directory(args.rpath, None, backend, args.auto_align,
                          args.verbose)
        if args.variant:
            process_directory(args.rpath, args.variant, backend,
                              args.auto_align, args.verbose)
    else:
        with open(args.rpath) as fr:
            parse_registry(fr,
                           backend=backend,
                           variant=args.variant,
                           encoding=args.encoding
                           if args.encoding else infer_encoding(args.rpath))
Beispiel #4
0
                corp, corplist_conf.get(mod_id, CorpusInfo()))
            if size > 0:
                cursor.execute('UPDATE corpora SET size = %s WHERE name = %s',
                               (corp, size))
            if web:
                cursor.execute('UPDATE corpora SET web = %s WHERE name = %s',
                               (web, size))
            for k in keywords:
                cursor.execute(
                    'INSERT INTO kontext_keyword_corpus (corpus_name, keyword_id) VALUES (%s, %s)',
                    (corp, k))

        except Exception as ex:
            print('skipping {0} due to: {1}'.format(corp, ex))
        print('---------')


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='Import N records starting from offset')
    parser.add_argument('conf_path', metavar='CONFPATH', type=str)
    parser.add_argument('corplist_path', metavar='CORPLISTPATH', type=str)
    args = parser.parse_args()
    import settings
    settings.load(args.conf_path)
    db = MySQL(MySQLConf(settings))
    corplist = get_corpora(db)
    corplist_conf = parse_corplist(args.corplist_path)
    fix_corpora(db, corplist, corplist_conf)
    db.commit()
Beispiel #5
0
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..'))
from plugins.rdbms_corparch.registry import RegModelSerializer, RegistryConf
from plugins.ucnk_remote_auth4.backend.mysql import Backend, MySQLConf


def load_registry(corpus_id, variant, backend):
    conf = RegistryConf(corpus_id=corpus_id, variant=variant, backend=backend)
    conf.load()
    return RegModelSerializer().serialize(conf)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='View database-stored Manatee registry')
    parser.add_argument('dbpath', metavar='DB_PATH', type=str)
    parser.add_argument('corpus_id', metavar='CORPUS_ID', type=str)
    parser.add_argument('-a', '--variant', metavar='VARIANT', type=str,
                        help='A subdirectory containing (restricted) variants of the corpus')
    parser.add_argument('-v', '--verbose', action='store_const', const=True,
                        help='Provide more information during processing (especially errors)')
    args = parser.parse_args()
    try:
        backend = Backend(MySQLConf(args.dbpath))
        print(load_registry(args.corpus_id, variant=args.variant, backend=backend).encode('utf-8'))
    except Exception as ex:
        print(ex, file=sys.stderr)
        if args.verbose:
            import traceback
            traceback.print_exc(ex)
Beispiel #6
0
        help='A subdirectory containing (restricted) variants of corpora')
    parser.add_argument(
        '-l',
        '--auto-align',
        metavar='AUTO_ALIGN',
        action='store_const',
        const=True,
        help='Align all the corpus in a directory automatically')
    parser.add_argument(
        '-v',
        '--verbose',
        action='store_const',
        const=True,
        help='Provide more information during processing (especially errors)')
    args = parser.parse_args()
    backend = WritableBackend(MySQLConf(args.dbpath))

    if os.path.isdir(args.rpath):
        process_directory(args.rpath, None, backend, args.auto_align,
                          args.verbose)
        if args.variant:
            process_directory(args.rpath, args.variant, backend,
                              args.auto_align, args.verbose)
    else:
        with open(args.rpath) as fr:
            parse_registry(fr,
                           backend=backend,
                           variant=args.variant,
                           encoding=args.encoding
                           if args.encoding else infer_encoding(args.rpath))
Beispiel #7
0
def create_instance(conf, sessions):
    backend = Backend(MySQLConf(conf))
    return CentralAuth(db=backend,
                       sessions=sessions,
                       conf=AuthConf(conf),
                       toolbar_conf=ToolbarConf(conf))
Beispiel #8
0
    parser.add_argument('-r',
                        '--reg-path',
                        type=str,
                        default='',
                        help='Path to registry files')
    parser.add_argument(
        '-a',
        '--variant',
        type=str,
        help=
        'Try to search for alternative registry in a directory with this name')
    parser.add_argument('-v',
                        '--verbose',
                        action='store_const',
                        const=True,
                        help='Print some additional (error) information')
    args = parser.parse_args()
    db = MySQL(MySQLConf(args.dbpath))
    if args.schema_only:
        prepare_tables(db)
    else:
        ijson = InstallJsonDir(args.json_out)
        parse_corplist(path=args.corplist,
                       db=db,
                       shared=Shared(reg_path=args.reg_path),
                       json_out=ijson,
                       variant=args.variant,
                       verbose=args.verbose)
        ijson.write()
    db.commit()